Skip to content

Commit

Permalink
fix: added label to locales, set up methods for multimedia selections…
Browse files Browse the repository at this point in the history
… and added setting for collapsed
  • Loading branch information
dev-warner committed Apr 11, 2024
1 parent 1eb8f36 commit 4cfc7b8
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 1 deletion.
48 changes: 48 additions & 0 deletions src/lib/components/MediaLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,54 @@ export class MediaLink {
* @param connection message-event-channel connection
*/
constructor(private connection: ClientConnection) {}

/**
* This method will trigger opening the media browser. It returns a promise that will resolve to the chosen Image or Video Link.
*
* Example of fetching media from DC
* ```typescript
* try {
* // open browser and waits for media browser
* // returns object that should be saved to the model
* const video = await sdk.mediaLink.get()
*
* } catch (e) {
* // no media returned
* }
* ```
*/
async get(): Promise<MediaImageLink | MediaVideoLink> {
return this.connection.request(MEDIA_LINK.GET, null, {
timeout: false,
});
}

/**
* This method will trigger opening the media overlay. It returns a promise that will resolve to the chosen Image and Video Links.
*
* Example of fetching an media from DC
* ```typescript
* try {
* // open browser and waits for media selection
* // returns object that should be saved to the model
* const media = await sdk.mediaLink.getMultiple({ max: 10 })
*
* } catch (e) {
* // no media returned
* }
* ```
*/
async getMultiple(
{ max }: MediaOptions = { max: null }
): Promise<Array<MediaImageLink | MediaImageLink>> {
return this.connection.request(
MEDIA_LINK.GET,
{ max },
{
timeout: false,
}
);
}
/**
* This method will trigger an image browser. It returns a promise that will resolve to the chosen Image Link.
*
Expand Down
1 change: 1 addition & 0 deletions src/lib/constants/Events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export enum CONTENT_ITEM {
export enum MEDIA_LINK {
IMAGE_GET = 'media-image-get',
VIDEO_GET = 'media-video-get',
GET = 'media-get',
}

export enum CONTENT_LINK {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface ContentEditorContextObject<ParamType extends Params = Params>
visualisation: string;
readOnly: boolean;
hub: Hub;
collaspseByDefault: boolean;
}

export function isContentEditorContextObject(
Expand Down
17 changes: 16 additions & 1 deletion src/lib/extensions/content-editor/ContentEditorExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ export class ContentEditorExtension<ParamType extends Params = Params> extends E
*/
public hub!: Hub;

/**
* CollaspseByDefault - global setting for whether or not form fields should be open or closed by default
*/
public collaspseByDefault!: boolean;

constructor(options: ExtensionOptions, context: ContentEditorContextObject<ParamType>) {
super(options, context);

Expand All @@ -86,7 +91,16 @@ export class ContentEditorExtension<ParamType extends Params = Params> extends E
}

setupContext(context: ContentEditorContextObject<ParamType>): void {
const { schema, params, locales, stagingEnvironment, readOnly, visualisation, hub } = context;
const {
schema,
params,
locales,
stagingEnvironment,
readOnly,
visualisation,
hub,
collaspseByDefault,
} = context;

this.assets = new Assets(this.connection);
this.contentItem = new ContentItem(this.connection);
Expand All @@ -96,6 +110,7 @@ export class ContentEditorExtension<ParamType extends Params = Params> extends E
this.locales = locales;
this.visualisation = visualisation;
this.stagingEnvironment = stagingEnvironment;
this.collaspseByDefault = collaspseByDefault;
this.hub = hub;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface ContentFieldContextObject<ParamType extends Params = Params>
visualisation: string;
readOnly: boolean;
hub: Hub;
collaspseByDefault: boolean;
}

export function isContentFieldContextObject(
Expand Down
6 changes: 6 additions & 0 deletions src/lib/extensions/content-field/ContentFieldExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ export class ContentFieldExtension<
* Hub - Hub id and Hub name
*/
public hub!: Hub;
/**
* CollaspseByDefault - global setting for whether or not form fields should be open or closed by default
*/
public collaspseByDefault!: boolean;

constructor(options: ExtensionOptions, context: ContentFieldContextObject<ParamType>) {
super(options, context);
Expand All @@ -87,6 +91,7 @@ export class ContentFieldExtension<
readOnly,
visualisation,
hub,
collaspseByDefault,
} = context;

this.assets = new Assets(this.connection);
Expand All @@ -97,6 +102,7 @@ export class ContentFieldExtension<
this.locales = locales;
this.visualisation = visualisation;
this.stagingEnvironment = stagingEnvironment;
this.collaspseByDefault = collaspseByDefault;
this.hub = hub;
}
}
1 change: 1 addition & 0 deletions src/lib/models/Locales.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ export interface LocalModel {
language: string;
country: string;
index: number;
label: string;
selected: boolean;
}

0 comments on commit 4cfc7b8

Please sign in to comment.