@concord-consortium/lara-interactive-api 1.6.1 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/api.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { IInitInteractive, INavigationOptions, IAuthInfo, ISupportedFeatures, IShowModal, ICloseModal, IGetInteractiveListOptions, IGetInteractiveListResponse, ISetLinkedInteractives, IGetLibraryInteractiveListRequest, IJwtResponse, ICustomMessageHandler, ICustomMessagesHandledMap, IGetInteractiveSnapshotOptions, IGetInteractiveSnapshotResponse, IAddLinkedInteractiveStateListenerOptions, IDecoratedContentEvent, ITextDecorationHandler, WriteAttachmentParams, ReadAttachmentParams, GetAttachmentUrlParams, IGetReportItemAnswerHandler, IReportItemAnswer, OnUnloadFunction } from "./types";
1
+ import { IInitInteractive, INavigationOptions, IAuthInfo, ISupportedFeatures, IShowModal, ICloseModal, IGetInteractiveListOptions, IGetInteractiveListResponse, ISetLinkedInteractives, IGetLibraryInteractiveListRequest, IJwtResponse, ICustomMessageHandler, ICustomMessagesHandledMap, IGetInteractiveSnapshotOptions, IGetInteractiveSnapshotResponse, IAddLinkedInteractiveStateListenerOptions, IDecoratedContentEvent, ITextDecorationHandler, WriteAttachmentParams, ReadAttachmentParams, GetAttachmentUrlParams, IGetReportItemAnswerHandler, IReportItemAnswer, OnUnloadFunction, IReportItemHandlerMetadata } from "./types";
2
2
  export declare const getInitInteractiveMessage: <InteractiveState = {}, AuthoredState = {}, GlobalInteractiveState = {}>() => Promise<IInitInteractive<InteractiveState, AuthoredState, GlobalInteractiveState> | null>;
3
3
  export declare const getMode: () => Promise<"runtime" | "authoring" | "report" | "reportItem" | undefined>;
4
4
  export declare const getInteractiveState: <InteractiveState>() => InteractiveState | null;
@@ -66,11 +66,12 @@ export declare const getGlobalInteractiveState: <GlobalInteractiveState>() => Gl
66
66
  */
67
67
  export declare const setGlobalInteractiveState: <GlobalInteractiveState>(newGlobalState: GlobalInteractiveState | null) => void;
68
68
  export declare const addCustomMessageListener: (callback: ICustomMessageHandler, handles?: ICustomMessagesHandledMap | undefined) => void;
69
- export declare const removeCustomMessageListener: () => void;
69
+ export declare const removeCustomMessageListener: () => boolean;
70
70
  export declare const addDecorateContentListener: (callback: ITextDecorationHandler) => void;
71
71
  export declare const removeDecorateContentListener: () => void;
72
72
  export declare const addGetReportItemAnswerListener: <InteractiveState, AuthoredState>(callback: IGetReportItemAnswerHandler<InteractiveState, AuthoredState>) => void;
73
73
  export declare const removeGetReportItemAnswerListener: () => void;
74
+ export declare const notifyReportItemClientReady: (metadata?: IReportItemHandlerMetadata | undefined) => void;
74
75
  export declare const setSupportedFeatures: (features: ISupportedFeatures) => void;
75
76
  export declare const setHeight: (height: number | string) => void;
76
77
  export declare const postDecoratedContentEvent: (msg: IDecoratedContentEvent) => void;
package/client.d.ts CHANGED
@@ -1,11 +1,16 @@
1
1
  import * as iframePhone from "iframe-phone";
2
- import { ClientMessage, ICustomMessageHandler, ICustomMessagesHandledMap, ISupportedFeaturesRequest, ServerMessage, ITextDecorationHandler, IGetReportItemAnswerHandler, OnUnloadFunction } from "./types";
2
+ import { ClientMessage, ICustomMessagesHandledMap, ISupportedFeaturesRequest, ServerMessage, OnUnloadFunction } from "./types";
3
3
  import { ManagedState } from "./managed-state";
4
4
  export declare const getClient: () => Client;
5
+ /**
6
+ * This class is intended to provide basic helpers (like `post()` or `add/removeListener`), maintain client-specific
7
+ * state, and generally be as minimal as possible. Most of the client-specific helpers and logic can be implemented
8
+ * in api.ts or hooks.ts (or both so the client app has choice).
9
+ */
5
10
  export declare class Client {
6
11
  phone: iframePhone.IFrameEndpoint;
7
12
  managedState: ManagedState;
8
- private customMessagesHandled;
13
+ customMessagesHandled: ICustomMessagesHandledMap;
9
14
  private listeners;
10
15
  private requestId;
11
16
  private onUnload;
@@ -14,12 +19,6 @@ export declare class Client {
14
19
  post(message: ClientMessage, content?: any): void;
15
20
  addListener(message: ServerMessage, callback: iframePhone.ListenerCallback, requestId?: number): boolean;
16
21
  removeListener(message: ServerMessage, requestId?: number, callback?: iframePhone.ListenerCallback): boolean;
17
- addCustomMessageListener(callback: ICustomMessageHandler, handles?: ICustomMessagesHandledMap): void;
18
- removeCustomMessageListener(): boolean;
19
- addDecorateContentListener(callback: ITextDecorationHandler): void;
20
- removeDecorateContentListener(): boolean;
21
- addGetReportItemAnswerListener(callback: IGetReportItemAnswerHandler): void;
22
- removeGetReportItemAnswerListener(): boolean;
23
22
  setSupportedFeatures: (request: ISupportedFeaturesRequest) => void;
24
23
  setOnUnload: (onUnload?: OnUnloadFunction<{}> | undefined) => void;
25
24
  private connect;
package/hooks.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ICustomMessageHandler, ICustomMessagesHandledMap, IInitInteractive, ITextDecorationHandler } from "./types";
1
+ import { ICustomMessageHandler, ICustomMessagesHandledMap, IInitInteractive, ITextDecorationHandler, IReportItemHandlerMetadata, IGetReportItemAnswerHandler } from "./types";
2
2
  declare type UpdateFunc<S> = (prevState: S | null) => S;
3
3
  export declare const useInteractiveState: <InteractiveState>() => {
4
4
  interactiveState: InteractiveState | null;
@@ -16,4 +16,9 @@ export declare const useInitMessage: <InteractiveState = {}, AuthoredState = {},
16
16
  export declare const useCustomMessages: (callback: ICustomMessageHandler, handles?: ICustomMessagesHandledMap | undefined) => void;
17
17
  export declare const useDecorateContent: (callback: ITextDecorationHandler) => void;
18
18
  export declare const useAutoSetHeight: () => void;
19
+ export interface IUseReportItemOptions<InteractiveState, AuthoredState> {
20
+ metadata: IReportItemHandlerMetadata;
21
+ handler: IGetReportItemAnswerHandler<InteractiveState, AuthoredState>;
22
+ }
23
+ export declare const useReportItem: <InteractiveState, AuthoredState>({ metadata, handler }: IUseReportItemOptions<InteractiveState, AuthoredState>) => void;
19
24
  export {};
package/index-bundle.d.ts CHANGED
@@ -130,7 +130,7 @@ interface IReportItemInitInteractive<InteractiveState = {}, AuthoredState = {}>
130
130
  mode: "reportItem";
131
131
  hostFeatures: IHostFeatures;
132
132
  interactiveItemId: string;
133
- view: "singleAnswer" | "multipleAnswer";
133
+ view: "singleAnswer" | "multipleAnswer" | "hidden";
134
134
  users: Record<string, {
135
135
  hasAnswer: boolean;
136
136
  }>;
@@ -361,11 +361,13 @@ interface ILinkedInteractiveStateResponse<LinkedInteractiveState> {
361
361
  listenerId: string;
362
362
  interactiveState: LinkedInteractiveState | undefined;
363
363
  }
364
+ declare type ReportItemsType = "fullAnswer" | "compactAnswer";
364
365
  interface IGetReportItemAnswer<InteractiveState = {}, AuthoredState = {}> extends IBaseRequestResponse {
365
- version: "2.0.0";
366
+ version: "2.1.0";
366
367
  platformUserId: string;
367
368
  interactiveState: InteractiveState;
368
369
  authoredState: AuthoredState;
370
+ itemsType: ReportItemsType;
369
371
  }
370
372
  interface IReportItemAnswerItemAttachment {
371
373
  type: "attachment";
@@ -384,13 +386,31 @@ interface IReportItemAnswerItemLinks {
384
386
  hideViewInline?: boolean;
385
387
  hideViewInNewTab?: boolean;
386
388
  }
387
- declare type IReportItemAnswerItem = IReportItemAnswerItemAttachment | IReportItemAnswerItemAnswerText | IReportItemAnswerItemHtml | IReportItemAnswerItemLinks;
389
+ interface IReportItemAnswerItemScore {
390
+ type: "score";
391
+ score: number;
392
+ maxScore: number;
393
+ }
394
+ declare type IReportItemAnswerItem = IReportItemAnswerItemAttachment | IReportItemAnswerItemAnswerText | IReportItemAnswerItemHtml | IReportItemAnswerItemLinks | IReportItemAnswerItemScore;
388
395
  interface IReportItemAnswer extends IBaseRequestResponse {
389
- version: "2.0.0";
396
+ version: "2.1.0";
390
397
  platformUserId: string;
391
398
  items: IReportItemAnswerItem[];
399
+ /**
400
+ * When not provided, host should assume that itemsType is equal to "fullAnswer" (to maintain backward compatibility
401
+ * with version 2.0.0).
402
+ */
403
+ itemsType?: ReportItemsType;
392
404
  }
393
405
  declare type IGetReportItemAnswerHandler<InteractiveState = {}, AuthoredState = {}> = (message: IGetReportItemAnswer<InteractiveState, AuthoredState>) => void;
406
+ interface IReportItemHandlerMetadata {
407
+ /**
408
+ * When compactAnswerReportItems is present and equal to true, report will try to get report items related to compact
409
+ * answer (small icons visible in the dashboard grid view). An example of compact answer report item is "score"
410
+ * used by ScoreBOT question.
411
+ */
412
+ compactAnswerReportItemsAvailable?: boolean;
413
+ }
394
414
  /**
395
415
  * Interface that can be used by interactives to export and consume datasets. For example:
396
416
  * - Vortex interactive is exporting its dataset in the interactive state
@@ -549,11 +569,12 @@ declare const getGlobalInteractiveState: <GlobalInteractiveState>() => GlobalInt
549
569
  */
550
570
  declare const setGlobalInteractiveState: <GlobalInteractiveState>(newGlobalState: GlobalInteractiveState | null) => void;
551
571
  declare const addCustomMessageListener: (callback: ICustomMessageHandler, handles?: ICustomMessagesHandledMap | undefined) => void;
552
- declare const removeCustomMessageListener: () => void;
572
+ declare const removeCustomMessageListener: () => boolean;
553
573
  declare const addDecorateContentListener: (callback: ITextDecorationHandler) => void;
554
574
  declare const removeDecorateContentListener: () => void;
555
575
  declare const addGetReportItemAnswerListener: <InteractiveState, AuthoredState>(callback: IGetReportItemAnswerHandler<InteractiveState, AuthoredState>) => void;
556
576
  declare const removeGetReportItemAnswerListener: () => void;
577
+ declare const notifyReportItemClientReady: (metadata?: IReportItemHandlerMetadata | undefined) => void;
557
578
  declare const setSupportedFeatures: (features: ISupportedFeatures) => void;
558
579
  declare const setHeight: (height: number | string) => void;
559
580
  declare const postDecoratedContentEvent: (msg: IDecoratedContentEvent) => void;
@@ -616,6 +637,11 @@ declare const useInitMessage: <InteractiveState = {}, AuthoredState = {}, Global
616
637
  declare const useCustomMessages: (callback: ICustomMessageHandler, handles?: ICustomMessagesHandledMap | undefined) => void;
617
638
  declare const useDecorateContent: (callback: ITextDecorationHandler) => void;
618
639
  declare const useAutoSetHeight: () => void;
640
+ interface IUseReportItemOptions<InteractiveState, AuthoredState> {
641
+ metadata: IReportItemHandlerMetadata;
642
+ handler: IGetReportItemAnswerHandler<InteractiveState, AuthoredState>;
643
+ }
644
+ declare const useReportItem: <InteractiveState, AuthoredState>({ metadata, handler }: IUseReportItemOptions<InteractiveState, AuthoredState>) => void;
619
645
 
620
646
  declare type ManagedStateEvent = "interactiveStateUpdated" | "globalInteractiveStateUpdated" | "authoredStateUpdated" | "initInteractive";
621
647
  declare class ManagedState {
@@ -640,10 +666,15 @@ declare class ManagedState {
640
666
  }
641
667
 
642
668
  declare const getClient: () => Client;
669
+ /**
670
+ * This class is intended to provide basic helpers (like `post()` or `add/removeListener`), maintain client-specific
671
+ * state, and generally be as minimal as possible. Most of the client-specific helpers and logic can be implemented
672
+ * in api.ts or hooks.ts (or both so the client app has choice).
673
+ */
643
674
  declare class Client {
644
675
  phone: iframePhone.IFrameEndpoint;
645
676
  managedState: ManagedState;
646
- private customMessagesHandled;
677
+ customMessagesHandled: ICustomMessagesHandledMap;
647
678
  private listeners;
648
679
  private requestId;
649
680
  private onUnload;
@@ -652,15 +683,9 @@ declare class Client {
652
683
  post(message: ClientMessage, content?: any): void;
653
684
  addListener(message: ServerMessage, callback: iframePhone.ListenerCallback, requestId?: number): boolean;
654
685
  removeListener(message: ServerMessage, requestId?: number, callback?: iframePhone.ListenerCallback): boolean;
655
- addCustomMessageListener(callback: ICustomMessageHandler, handles?: ICustomMessagesHandledMap): void;
656
- removeCustomMessageListener(): boolean;
657
- addDecorateContentListener(callback: ITextDecorationHandler): void;
658
- removeDecorateContentListener(): boolean;
659
- addGetReportItemAnswerListener(callback: IGetReportItemAnswerHandler): void;
660
- removeGetReportItemAnswerListener(): boolean;
661
686
  setSupportedFeatures: (request: ISupportedFeaturesRequest) => void;
662
687
  setOnUnload: (onUnload?: OnUnloadFunction<{}> | undefined) => void;
663
688
  private connect;
664
689
  }
665
690
 
666
- export { AttachmentInfoMap, ChoiceId, Client, ClientMessage, DeprecatedRuntimeClientMessage, DeprecatedRuntimeServerMessage, GetAttachmentUrlParams, GlobalIFrameSaverClientMessage, GlobalIFrameSaverServerMessage, IAddLinkedInteractiveStateListenerOptions, IAddLinkedInteractiveStateListenerRequest, IAttachmentInfo, IAttachmentUrlRequest, IAttachmentUrlResponse, IAuthInfo, IAuthoringClientMessage, IAuthoringCustomReportField, IAuthoringCustomReportFields, IAuthoringImageQuestionMetadata, IAuthoringInitInteractive, IAuthoringInteractiveMetadata, IAuthoringMetadata, IAuthoringMetadataBase, IAuthoringMultipleChoiceChoiceMetadata, IAuthoringMultipleChoiceMetadata, IAuthoringOpenResponseMetadata, IAuthoringServerMessage, IBaseShowModal, ICloseModal, IContextMember, IContextMembership, ICustomMessage, ICustomMessageHandler, ICustomMessageOptions, ICustomMessagesHandledMap, ICustomReportFieldsAuthoredState, ICustomReportFieldsAuthoredStateField, ICustomReportFieldsInteractiveState, IDataset, IDecoratedContentEvent, IGetAuthInfoRequest, IGetAuthInfoResponse, IGetFirebaseJwtRequest, IGetFirebaseJwtResponse, IGetInteractiveListOptions, IGetInteractiveListRequest, IGetInteractiveListResponse, IGetInteractiveSnapshotOptions, IGetInteractiveSnapshotRequest, IGetInteractiveSnapshotResponse, IGetInteractiveState, IGetLibraryInteractiveListOptions, IGetLibraryInteractiveListRequest, IGetLibraryInteractiveListResponse, IGetReportItemAnswer, IGetReportItemAnswerHandler, IHintRequest, IHostFeatureSupport, IHostFeatures, IHostModalSupport, IInitInteractive, IInteractiveListResponseItem, IInteractiveStateProps, IInteractiveStateWithDataset, IJwtClaims, IJwtResponse, ILibraryInteractiveListResponseItem, ILinkedInteractive, ILinkedInteractiveStateResponse, INavigationOptions, IPortalClaims, IRemoveLinkedInteractiveStateListenerRequest, IReportInitInteractive, IReportItemAnswer, IReportItemAnswerItem, IReportItemAnswerItemAnswerText, IReportItemAnswerItemAttachment, IReportItemAnswerItemHtml, IReportItemAnswerItemLinks, IReportItemClientMessage, IReportItemInitInteractive, IReportItemServerMessage, IRuntimeClientMessage, IRuntimeCustomReportValues, IRuntimeImageQuestionMetadata, IRuntimeInitInteractive, IRuntimeInteractiveMetadata, IRuntimeMetadata, IRuntimeMetadataBase, IRuntimeMultipleChoiceMetadata, IRuntimeOpenResponseMetadata, IRuntimeServerMessage, ISetLinkedInteractives, IShowAlert, IShowDialog, IShowLightbox, IShowModal, ISupportedFeatures, ISupportedFeaturesRequest, ITextDecorationHandler, ITextDecorationHandlerInfo, ITextDecorationInfo, IThemeInfo, IWriteAttachmentRequest, IframePhoneServerMessage, InitInteractiveMode, InteractiveItemId, LoggerClientMessage, ModalType, OnUnloadFunction, ReadAttachmentParams, ServerMessage, WriteAttachmentParams, addAuthoredStateListener, addCustomMessageListener, addDecorateContentListener, addGetReportItemAnswerListener, addGlobalInteractiveStateListener, addInteractiveStateListener, addLinkedInteractiveStateListener, closeModal, flushStateUpdates, getAttachmentUrl, getAuthInfo, getAuthoredState, getClient, getFirebaseJwt, getGlobalInteractiveState, getInitInteractiveMessage, getInteractiveList, getInteractiveSnapshot, getInteractiveState, getLibraryInteractiveList, getMode, inIframe, log, postDecoratedContentEvent, readAttachment, removeAuthoredStateListener, removeCustomMessageListener, removeDecorateContentListener, removeGetReportItemAnswerListener, removeGlobalInteractiveStateListener, removeInteractiveStateListener, removeLinkedInteractiveStateListener, sendReportItemAnswer, setAuthoredState, setGlobalInteractiveState, setHeight, setHint, setInteractiveState, setInteractiveStateTimeout, setLinkedInteractives, setNavigation, setOnUnload, setSupportedFeatures, showModal, useAuthoredState, useAutoSetHeight, useCustomMessages, useDecorateContent, useGlobalInteractiveState, useInitMessage, useInteractiveState, writeAttachment };
691
+ export { AttachmentInfoMap, ChoiceId, Client, ClientMessage, DeprecatedRuntimeClientMessage, DeprecatedRuntimeServerMessage, GetAttachmentUrlParams, GlobalIFrameSaverClientMessage, GlobalIFrameSaverServerMessage, IAddLinkedInteractiveStateListenerOptions, IAddLinkedInteractiveStateListenerRequest, IAttachmentInfo, IAttachmentUrlRequest, IAttachmentUrlResponse, IAuthInfo, IAuthoringClientMessage, IAuthoringCustomReportField, IAuthoringCustomReportFields, IAuthoringImageQuestionMetadata, IAuthoringInitInteractive, IAuthoringInteractiveMetadata, IAuthoringMetadata, IAuthoringMetadataBase, IAuthoringMultipleChoiceChoiceMetadata, IAuthoringMultipleChoiceMetadata, IAuthoringOpenResponseMetadata, IAuthoringServerMessage, IBaseShowModal, ICloseModal, IContextMember, IContextMembership, ICustomMessage, ICustomMessageHandler, ICustomMessageOptions, ICustomMessagesHandledMap, ICustomReportFieldsAuthoredState, ICustomReportFieldsAuthoredStateField, ICustomReportFieldsInteractiveState, IDataset, IDecoratedContentEvent, IGetAuthInfoRequest, IGetAuthInfoResponse, IGetFirebaseJwtRequest, IGetFirebaseJwtResponse, IGetInteractiveListOptions, IGetInteractiveListRequest, IGetInteractiveListResponse, IGetInteractiveSnapshotOptions, IGetInteractiveSnapshotRequest, IGetInteractiveSnapshotResponse, IGetInteractiveState, IGetLibraryInteractiveListOptions, IGetLibraryInteractiveListRequest, IGetLibraryInteractiveListResponse, IGetReportItemAnswer, IGetReportItemAnswerHandler, IHintRequest, IHostFeatureSupport, IHostFeatures, IHostModalSupport, IInitInteractive, IInteractiveListResponseItem, IInteractiveStateProps, IInteractiveStateWithDataset, IJwtClaims, IJwtResponse, ILibraryInteractiveListResponseItem, ILinkedInteractive, ILinkedInteractiveStateResponse, INavigationOptions, IPortalClaims, IRemoveLinkedInteractiveStateListenerRequest, IReportInitInteractive, IReportItemAnswer, IReportItemAnswerItem, IReportItemAnswerItemAnswerText, IReportItemAnswerItemAttachment, IReportItemAnswerItemHtml, IReportItemAnswerItemLinks, IReportItemAnswerItemScore, IReportItemClientMessage, IReportItemHandlerMetadata, IReportItemInitInteractive, IReportItemServerMessage, IRuntimeClientMessage, IRuntimeCustomReportValues, IRuntimeImageQuestionMetadata, IRuntimeInitInteractive, IRuntimeInteractiveMetadata, IRuntimeMetadata, IRuntimeMetadataBase, IRuntimeMultipleChoiceMetadata, IRuntimeOpenResponseMetadata, IRuntimeServerMessage, ISetLinkedInteractives, IShowAlert, IShowDialog, IShowLightbox, IShowModal, ISupportedFeatures, ISupportedFeaturesRequest, ITextDecorationHandler, ITextDecorationHandlerInfo, ITextDecorationInfo, IThemeInfo, IUseReportItemOptions, IWriteAttachmentRequest, IframePhoneServerMessage, InitInteractiveMode, InteractiveItemId, LoggerClientMessage, ModalType, OnUnloadFunction, ReadAttachmentParams, ReportItemsType, ServerMessage, WriteAttachmentParams, addAuthoredStateListener, addCustomMessageListener, addDecorateContentListener, addGetReportItemAnswerListener, addGlobalInteractiveStateListener, addInteractiveStateListener, addLinkedInteractiveStateListener, closeModal, flushStateUpdates, getAttachmentUrl, getAuthInfo, getAuthoredState, getClient, getFirebaseJwt, getGlobalInteractiveState, getInitInteractiveMessage, getInteractiveList, getInteractiveSnapshot, getInteractiveState, getLibraryInteractiveList, getMode, inIframe, log, notifyReportItemClientReady, postDecoratedContentEvent, readAttachment, removeAuthoredStateListener, removeCustomMessageListener, removeDecorateContentListener, removeGetReportItemAnswerListener, removeGlobalInteractiveStateListener, removeInteractiveStateListener, removeLinkedInteractiveStateListener, sendReportItemAnswer, setAuthoredState, setGlobalInteractiveState, setHeight, setHint, setInteractiveState, setInteractiveStateTimeout, setLinkedInteractives, setNavigation, setOnUnload, setSupportedFeatures, showModal, useAuthoredState, useAutoSetHeight, useCustomMessages, useDecorateContent, useGlobalInteractiveState, useInitMessage, useInteractiveState, useReportItem, writeAttachment };