From b86495db6a40c890681a518e6086a0f2434763bc Mon Sep 17 00:00:00 2001 From: Joe Warner Date: Fri, 19 Apr 2024 12:39:15 +0100 Subject: [PATCH] fix: integration branch for sdk changes --- src/lib/components/MediaLink.ts | 48 +++++++++++++++++++ src/lib/constants/Events.ts | 1 + .../ContentEditorContextObject.ts | 2 +- .../ContentEditorExtension.spec.ts | 8 ++-- .../content-editor/ContentEditorExtension.ts | 8 +++- .../ContentFieldContextObject.ts | 2 +- .../ContentFieldExtension.spec.ts | 5 +- .../content-field/ContentFieldExtension.ts | 7 ++- src/lib/models/Locales.ts | 1 + 9 files changed, 73 insertions(+), 9 deletions(-) diff --git a/src/lib/components/MediaLink.ts b/src/lib/components/MediaLink.ts index 53f3471..6ea0527 100644 --- a/src/lib/components/MediaLink.ts +++ b/src/lib/components/MediaLink.ts @@ -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 { + 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> { + 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. * diff --git a/src/lib/constants/Events.ts b/src/lib/constants/Events.ts index c3074f0..fe2a33f 100644 --- a/src/lib/constants/Events.ts +++ b/src/lib/constants/Events.ts @@ -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 { diff --git a/src/lib/extensions/content-editor/ContentEditorContextObject.ts b/src/lib/extensions/content-editor/ContentEditorContextObject.ts index ebc16ed..d6655fd 100644 --- a/src/lib/extensions/content-editor/ContentEditorContextObject.ts +++ b/src/lib/extensions/content-editor/ContentEditorContextObject.ts @@ -12,9 +12,9 @@ export interface ContentEditorContextObject locales: LocalesModel; stagingEnvironment: string; visualisation: string; - locationHref: string; readOnly: boolean; hub: Hub; + collaspseByDefault: boolean; } export function isContentEditorContextObject( diff --git a/src/lib/extensions/content-editor/ContentEditorExtension.spec.ts b/src/lib/extensions/content-editor/ContentEditorExtension.spec.ts index a64638b..9533a44 100644 --- a/src/lib/extensions/content-editor/ContentEditorExtension.spec.ts +++ b/src/lib/extensions/content-editor/ContentEditorExtension.spec.ts @@ -1,9 +1,7 @@ import { ClientConnection } from 'message-event-channel'; import { ContentItem } from '../../components/ContentItem'; import { ContentEditorExtension } from './ContentEditorExtension'; -import { Field } from '../../components/Field'; import { ContentEditorForm } from '../../components/ContentEditorForm'; -import { Frame } from '../../components/Frame'; import { ContentReference } from '../../components/ContentReference'; import { ContentLink } from '../../components/ContentLink'; import { MediaLink } from '../../components/MediaLink'; @@ -36,13 +34,15 @@ describe('ContentEditorExtension', () => { }, locales: { default: ['en'], - available: [{ locale: 'en-gb', language: 'en', country: 'gb', index: 1, selected: true }], + available: [ + { locale: 'en-gb', language: 'en', country: 'gb', index: 1, selected: true, label: '' }, + ], }, stagingEnvironment: 'https://test-staging-environment', visualisation: 'test-visualization', readOnly: true, hub: { id: 'hubId', name: 'hubName' }, - locationHref: '#!', + collaspseByDefault: false, }; const options = { diff --git a/src/lib/extensions/content-editor/ContentEditorExtension.ts b/src/lib/extensions/content-editor/ContentEditorExtension.ts index 54f1ea6..becbc5f 100644 --- a/src/lib/extensions/content-editor/ContentEditorExtension.ts +++ b/src/lib/extensions/content-editor/ContentEditorExtension.ts @@ -97,6 +97,11 @@ export class ContentEditorExtension extends E */ public applicationNavigator!: ContentEditorApplicationNavigator; + /** + * CollaspseByDefault - global setting for whether or not form fields should be open or closed by default + */ + public collaspseByDefault!: boolean; + constructor(options: ExtensionOptions, context: ContentEditorContextObject) { super(options, context); @@ -111,12 +116,12 @@ export class ContentEditorExtension extends E const { schema, params, - locationHref, locales, stagingEnvironment, readOnly, visualisation, hub, + collaspseByDefault, } = context; this.assets = new Assets(this.connection); @@ -127,6 +132,7 @@ export class ContentEditorExtension extends E this.locales = locales; this.visualisation = visualisation; this.stagingEnvironment = stagingEnvironment; + this.collaspseByDefault = collaspseByDefault; this.hub = hub; this.applicationNavigator = new ContentEditorApplicationNavigator(this.connection); diff --git a/src/lib/extensions/content-field/ContentFieldContextObject.ts b/src/lib/extensions/content-field/ContentFieldContextObject.ts index 173fe18..9f9c8ac 100644 --- a/src/lib/extensions/content-field/ContentFieldContextObject.ts +++ b/src/lib/extensions/content-field/ContentFieldContextObject.ts @@ -14,7 +14,7 @@ export interface ContentFieldContextObject visualisation: string; readOnly: boolean; hub: Hub; - locationHref: string; + collaspseByDefault: boolean; } export function isContentFieldContextObject( diff --git a/src/lib/extensions/content-field/ContentFieldExtension.spec.ts b/src/lib/extensions/content-field/ContentFieldExtension.spec.ts index 40678a1..b4dcd26 100644 --- a/src/lib/extensions/content-field/ContentFieldExtension.spec.ts +++ b/src/lib/extensions/content-field/ContentFieldExtension.spec.ts @@ -34,13 +34,16 @@ describe('ContentFieldExtension', () => { }, locales: { default: ['en'], - available: [{ locale: 'en-gb', language: 'en', country: 'gb', index: 1, selected: true }], + available: [ + { locale: 'en-gb', language: 'en', country: 'gb', index: 1, selected: true, label: '' }, + ], }, locationHref: '#!', stagingEnvironment: 'https://test-staging-environment', visualisation: 'test-visualization', readOnly: true, hub: { id: 'hubId', name: 'hubName' }, + collaspseByDefault: false, }; it('should create a new instance of ContentFieldExtension', () => { const connection = new ClientConnection(options); diff --git a/src/lib/extensions/content-field/ContentFieldExtension.ts b/src/lib/extensions/content-field/ContentFieldExtension.ts index 9172df4..06687da 100644 --- a/src/lib/extensions/content-field/ContentFieldExtension.ts +++ b/src/lib/extensions/content-field/ContentFieldExtension.ts @@ -81,6 +81,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; /** * ApplicationNavigator - used to navigate within the form @@ -106,8 +110,8 @@ export class ContentFieldExtension< stagingEnvironment, readOnly, visualisation, - locationHref, hub, + collaspseByDefault, } = context; this.assets = new Assets(this.connection); @@ -119,6 +123,7 @@ export class ContentFieldExtension< this.locales = locales; this.visualisation = visualisation; this.stagingEnvironment = stagingEnvironment; + this.collaspseByDefault = collaspseByDefault; this.hub = hub; } } diff --git a/src/lib/models/Locales.ts b/src/lib/models/Locales.ts index 7b5a876..87aca1b 100644 --- a/src/lib/models/Locales.ts +++ b/src/lib/models/Locales.ts @@ -10,6 +10,7 @@ export interface LocalModel { language: string; country: string; index: number; + label: string; selected: boolean; master?: boolean; }