Skip to content

Commit d0cd7b8

Browse files
Merge pull request #33 from contentstack/develop
v1.2.0
2 parents 60e7c8f + b1a9a22 commit d0cd7b8

File tree

8 files changed

+148
-110
lines changed

8 files changed

+148
-110
lines changed

README.md

Lines changed: 56 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,118 +1,95 @@
1-
# App Framework SDK
1+
# Contentstack App SDK Readme
22

3-
## JSON Rich text editor plugin
3+
The Contentstack App SDK allows you to customize your applications. This document will help you integrate the App SDK with your application.
44

5-
The **JSON Rich Text Editor Plugins** lets you add/create custom plugins to extend the functionality of your [JSON Rich Text Editor](https://www.contentstack.com/docs/developers/json-rich-text-editor/about-json-rich-text-editor/) as per your needs. You can use the prebuilt JSON RTE plugins by modifying the code to suit your requirement.
5+
## Getting started
66

7-
Some of the examples of the prebuilt JSON Rich Text Editor plugins are:
7+
To include the App SDK in your project, you need to run the following command:
88

9-
- Highlight: Allows you to highlight certain parts of your content, such as a whole line of text or a paragraph.
10-
11-
- Info Panel: Allows you to place important content inside a colored panel to make it stand out.
12-
13-
- Word Count: Allows you to track the word count for your JSON Rich Text Editor content.
14-
15-
You can create JSON Rich Text Editor Plugins using the Contentstack App SDK. For more information, read our [documentation](https://www.contentstack.com/docs/developers/json-rich-text-editor-plugins/about-json-rte-plugins/).
16-
17-
## Asset Sidebar Extension
18-
19-
**Asset Sidebar Extensions** enable you to customize and enhance your **asset editing experience**. Using customized extensions, you can tailor your images on Contentstack according to your branding requirements..
20-
21-
You can create Asset Sidebar Extensions using the Contentstack App SDK. For more information, read our documentation.
22-
23-
### AssetSidebarWidget Reference
24-
25-
It is an object representing the current Asset Sidebar Widget reference in the Contentstack UI.
9+
```sh
10+
npm install @contentstack/app-sdk
11+
```
2612

27-
**getData()**
13+
Alternatively, you can use the following command within the script tag to install the App SDK:
2814

29-
This method returns the object representing the current asset.
15+
```html
16+
<script src="https://unpkg.com/@contentstack/app-sdk@^1.2/dist/index.js"></script>
17+
```
3018

31-
**setData(asset: Partial<AssetData>)**
19+
### Initializing the App SDK
3220

33-
This method modifies the properties of the current asset.
21+
To Initialize the App SDK you need to run the following command:
3422

35-
**syncAsset()**
23+
```js
24+
ContentstackAppSdk.init().then(function (appSdk) {
25+
// add code here
26+
});
27+
```
3628

37-
If your asset has been modified externally, you can use this method to load the new asset and sync its settings with the current asset.
29+
For more information, please refer to our [App SDK API Reference](https://github.com/contentstack/app-sdk-docs#contentstack-app-sdk-api-reference) document.
3830

39-
**updateWidth(width: number)**
31+
## Download the Boilerplate
4032

41-
This method is used to modify the width of the asset sidebar panel. Using this method, you can resize the panel depending on the resolution of your content.
33+
You can extend or customize the functionality of Contentstack CMS with Marketplace apps. To simplify and speed up the building process, boilerplates describe repetitive elements in a project. This boilerplate will help you build custom applications for your organization or stack.
4234

43-
**replaceAsset(file: File)**
35+
Download the [boilerplate](https://assets.contentstack.io/v3/assets/blt23180bf2502c7444/blt2bccdd28a2d44d1b/62fcb522da3c526fe6314886/app-boilerplate.zip?disposition=download).
4436

45-
This method is used to replace the current asset with a new file. Unlike setData(), where you can only modify the properties, you can use this method to replace the actual file.
37+
## UI Locations and Examples
4638

47-
**onSave(callback: anyFunction)**
39+
UI Locations allow you to extend Contentstack's functionality. Through these UI locations, you can customize Contentstack's default behavior and UI. Integration of third-party applications is possible using different UI locations.
4840

49-
This is a callback function that runs after you save the asset settings.
41+
The Contentstack App SDK currently supports the following UI Locations:
5042

51-
**onChange(callback: anyFunction)**
43+
- [Custom Field Location](https://www.contentstack.com/docs/developers/developer-hub/custom-field-location)
44+
- [Dashboard Location](https://www.contentstack.com/docs/developers/developer-hub/dashboard-location)
45+
- [Asset Sidebar Location](https://www.contentstack.com/docs/developers/developer-hub/asset-sidebar-location)
46+
- [App Config Location](https://www.contentstack.com/docs/developers/developer-hub/app-config-location)
47+
- [RTE Location](https://www.contentstack.com/docs/developers/developer-hub/rte-location)
48+
- [Sidebar Location](https://www.contentstack.com/docs/developers/developer-hub/sidebar-location)
5249

53-
This is a callback function that runs every time the user modifies the asset data.
50+
### Custom Field Location
5451

55-
**onPublish(callback: anyFunction)**
52+
Custom Field Location allows you to create custom fields that can be used in your content types. You can integrate with various business applications, such as [Bynder](https://www.contentstack.com/docs/developers/marketplace-apps/bynder), [Cloudinary](https://www.contentstack.com/docs/developers/marketplace-apps/cloudinary), [Shopify](https://www.contentstack.com/docs/developers/marketplace-apps/shopify), by adding them as a custom field to your stack's content type.
5653

57-
This is a callback function that is executed after a user publishes an asset.
54+
### Dashboard Location
5855

59-
**onUnPublish(callback: anyFunction)**
56+
With the Dashboard Location, you can create widgets for your stack dashboard. Integration with [Google Analytics](https://www.contentstack.com/docs/developers/marketplace-apps/google-analytics/) provides meaningful insights about your website.
6057

61-
This is a callback function that is executed after you unpublish an asset.
58+
### Asset Sidebar Location
6259

63-
**AssetData**
60+
Using the Asset Sidebar Location, you can create customized sidebar widgets to extend the functionality of your assets.
6461

65-
It is the property that you can modify using the setData() method.
62+
Manage, transform, and optimize your stack's assets efficiently using the [Image Preset Builder](https://www.contentstack.com/docs/developers/marketplace-apps/image-preset-builder).
6663

67-
## Metadata
64+
### App Config Location
6865

69-
Metadata is a piece of information that lets you describe or classify an asset/entry. You can manage your digital entities effectively and enable improved accessibility with additional metadata. This object manages all the CRUD operations you can perform with metadata, e.g., adding, updating, or deleting additional metadata.
66+
App Config UI Location allows you to manage all the app settings centrally. Once configured, all other locations (where the app is installed) can access these settings.
7067

68+
### RTE Location
7169

72-
> Note: The Metadata feature allows users to update their asset metadata or entry metadata without incrementing the asset or entry version.
70+
The RTE Location allows you to create custom plugins to expand the functionality of your JSON Rich Text Editor. Using the Audience and Variables plugin, you can tailor your content as per your requirements.
7371

74-
### createMetadata(metadataConfig: IMetadataCreate)
72+
### Sidebar Location
7573

76-
```ts
77-
IMetadataCreate {
78-
entity_uid: string;
79-
type?: "asset" | "entry"; // default: "asset";
80-
extension_uid: string;
81-
_content_type_uid?: string;
82-
locale?: string;
83-
[key: string]: any; // other fields you want to add
84-
}
85-
```
74+
The Sidebar Location provides powerful tools for analyzing and recommending ideas for your entry. Use the [Smartling](https://help.smartling.com/hc/en-us/articles/4865477629083) sidebar location to help translate your content.
8675

87-
This method adds new metadata for an asset or entry. It accepts metadata configuration as required arguments. This config contains basic details that you need to identify the metadata object and other data you need for your app.
76+
## Using Contentstack styles
8877

89-
### retrieveMetadata(metadataConfig: IMetadataRetrieve)
78+
Install the Venus UI library package to style your app according to the Contentstack UI:
9079

91-
```ts
92-
IMetadateRetrieve {
93-
uid: string;
94-
}
80+
```sh
81+
npm i @contentstack/venus-components --save
9582
```
9683

97-
This method retrieves metadata for an asset or entry. It accepts metadata configuration as required arguments. This config contains basic details that you need to identify the metadata object you want to retrieve.
84+
For more information on styling your application, refer to our [style guide](https://www.contentstack.com/docs/developers/venus-component-library/).
9885

99-
### updateMetadata(metadataConfig: IMetadataUpdate)
86+
## More information
10087

101-
```ts
102-
IMetadataUpdate {
103-
uid: string;
104-
[key: string]: any; // other fields you want to update
105-
}
106-
```
107-
108-
This method updates existing metadata for an asset or entry. It accepts metadata configuration as required arguments. This config contains basic details that you need to identify the metadata object and other data you want to update.
88+
- [App SDK API Reference](https://github.com/contentstack/app-sdk-docs#readme)
89+
- [Marketplace Platform Guides](https://www.contentstack.com/docs/developers/marketplace-platform-guides/)
90+
- [Marketplace Apps](https://www.contentstack.com/docs/developers/marketplace-apps/)
91+
- [Contentstack App Development](https://www.contentstack.com/docs/developers/developer-hub/)
10992

110-
### deleteMetadata(metadataConfig: IMetadataDelete)
111-
112-
```ts
113-
IMetadateDelete {
114-
uid: string;
115-
}
116-
```
93+
## License
11794

118-
This method deletes existing metadata for an asset or entry. It accepts metadata configuration as required arguments. This config contains basic details that you need to identify the metadata object you want to delete.
95+
Licensed under [MIT](https://opensource.org/licenses/MIT).

__test__/frame.test.ts

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
import EventEmitter from "wolfy87-eventemitter";
22
import Window from "../src/window";
3+
import postRobot from "post-robot";
4+
5+
jest.mock("post-robot", () => ({
6+
__esModule: true,
7+
default: {
8+
on: jest.fn(),
9+
sendToParent: jest.fn().mockReturnValue(Promise.resolve()),
10+
},
11+
}));
312

413
describe("Window", () => {
514
let windowObj: Window;
@@ -81,7 +90,6 @@ describe("Window", () => {
8190
});
8291
});
8392

84-
8593
it("onDashboardResize Callback must be a function", function () {
8694
windowObj.type = "DASHBOARD";
8795
//@ts-ignore
@@ -113,22 +121,26 @@ describe("Window", () => {
113121
it("should send dashboardEnableTopPadding on enablePaddingTop", (done) => {
114122
windowObj.type = "DASHBOARD";
115123
windowObj.enablePaddingTop().then(() => {
116-
expect(connection.sendToParent).toHaveBeenCalledWith("window", {
117-
action: "dashboardEnableTopPadding",
118-
});
124+
expect((postRobot as any).sendToParent).toHaveBeenCalledWith(
125+
"window",
126+
{
127+
action: "dashboardEnableTopPadding",
128+
}
129+
);
119130
done();
120131
});
121132
});
122133

123134
it("should send dashboardDisableTopPadding on disablePaddingTop", (done) => {
124135
windowObj.type = "DASHBOARD";
125136
windowObj.disablePaddingTop().then(() => {
126-
expect(connection.sendToParent).toHaveBeenCalledWith("window", {
127-
action: "dashboardDisableTopPadding",
128-
});
137+
expect((postRobot as any).sendToParent).toHaveBeenCalledWith(
138+
"window",
139+
{
140+
action: "dashboardDisableTopPadding",
141+
}
142+
);
129143
done();
130144
});
131145
});
132-
133-
134146
});

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/src/window.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ declare class Window {
4242
* @return {Window}.
4343
*/
4444
disableAutoResizing(): this;
45-
enablePaddingTop(): any;
46-
disablePaddingTop(): any;
45+
enablePaddingTop(): Promise<any>;
46+
disablePaddingTop(): Promise<any>;
4747
}
4848
export default Window;
4949
//# sourceMappingURL=window.d.ts.map

dist/src/window.d.ts.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 54 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/window.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import EventEmitter from "wolfy87-eventemitter";
2+
import postRobot from "post-robot";
23

34
const config = { attributes: true, childList: true, subtree: true };
45
let observer: MutationObserver;
@@ -20,7 +21,7 @@ class Window {
2021
_height?: number
2122

2223
constructor(connection: any, type: 'DASHBOARD' | 'FIELD', emitter: EventEmitter, state: 'half_width' | 'full_width' = 'half_width') {
23-
this._connection = connection;
24+
this._connection = connection || postRobot;
2425
this._autoResizingEnabled = false;
2526
this._resizingEnabled = false;
2627
this.type = type;
@@ -108,12 +109,18 @@ class Window {
108109
return this;
109110
}
110111

111-
enablePaddingTop() {
112-
return this._connection.sendToParent('window', { action: 'dashboardEnableTopPadding' });
112+
enablePaddingTop(): Promise<any> {
113+
// @ts-ignore
114+
return postRobot.sendToParent("window", {
115+
action: "dashboardEnableTopPadding",
116+
});
113117
}
114118

115-
disablePaddingTop() {
116-
return this._connection.sendToParent('window', { action: 'dashboardDisableTopPadding' });
119+
disablePaddingTop(): Promise<any> {
120+
// @ts-ignore
121+
return postRobot.sendToParent('window', {
122+
action: 'dashboardDisableTopPadding'
123+
});
117124
}
118125

119126
}

0 commit comments

Comments
 (0)