@aws/mynah-ui 4.6.2 → 4.6.3

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.
@@ -1,3 +1,7 @@
1
+ /*!
2
+ * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
1
5
  import { DomBuilderObject, ExtendedHTMLElement } from '../../helper/dom';
2
6
  import { EngagementType } from '../../static';
3
7
  export interface CardProps extends Partial<DomBuilderObject> {
@@ -0,0 +1,17 @@
1
+ import { ExtendedHTMLElement } from '../../helper/dom';
2
+ import { FileNodeAction, TreeNodeDetails } from '../../static';
3
+ import { MynahIcons } from '../icon';
4
+ export interface ChatItemTreeFileProps {
5
+ tabId: string;
6
+ messageId: string;
7
+ filePath: string;
8
+ fileName: string;
9
+ icon?: MynahIcons;
10
+ deleted?: boolean;
11
+ details?: TreeNodeDetails;
12
+ actions?: FileNodeAction[];
13
+ }
14
+ export declare class ChatItemTreeFile {
15
+ render: ExtendedHTMLElement;
16
+ constructor(props: ChatItemTreeFileProps);
17
+ }
@@ -9,6 +9,7 @@ export declare enum MynahIcons {
9
9
  MINUS = "minus",
10
10
  SEARCH = "search",
11
11
  PLUS = "plus",
12
+ PAPER_CLIP = "paper-clip",
12
13
  LIST_ADD = "list-add",
13
14
  TABS = "tabs",
14
15
  CHAT = "chat",
@@ -20,6 +20,10 @@ export declare class Notification {
20
20
  private readonly props;
21
21
  constructor(props: NotificationProps);
22
22
  notify(): void;
23
+ /**
24
+ * Calculates the top according to the previously shown and still visible notifications
25
+ * @returns number
26
+ */
23
27
  private readonly getNextCalculatedTop;
24
28
  private readonly getChildren;
25
29
  }
@@ -4,18 +4,54 @@
4
4
  */
5
5
  import { DomBuilderObject, ExtendedHTMLElement } from '../helper/dom';
6
6
  export declare const OVERLAY_MARGIN = 8;
7
+ /**
8
+ * The horizontal creation direction of the overlay
9
+ */
7
10
  export declare enum OverlayHorizontalDirection {
11
+ /**
12
+ * starts from the left edge of the reference element and opens to left
13
+ */
8
14
  TO_LEFT = "horizontal-direction-to-left",
15
+ /**
16
+ * starts from the right edge of the reference element and opens to left
17
+ */
9
18
  END_TO_LEFT = "horizontal-direction-from-end-to-left",
19
+ /**
20
+ * starts from the right edge of the reference element and opens to right
21
+ */
10
22
  TO_RIGHT = "horizontal-direction-to-right",
23
+ /**
24
+ * starts from the left edge of the reference element and opens to right
25
+ */
11
26
  START_TO_RIGHT = "horizontal-direction-from-start-to-right",
27
+ /**
28
+ * starts and opens at the center of the reference element
29
+ */
12
30
  CENTER = "horizontal-direction-at-center"
13
31
  }
32
+ /**
33
+ * The vertical creation direction of the overlay
34
+ */
14
35
  export declare enum OverlayVerticalDirection {
36
+ /**
37
+ * starts from the bottom edge of the reference element and opens to bottom
38
+ */
15
39
  TO_BOTTOM = "vertical-direction-to-bottom",
40
+ /**
41
+ * starts from the top edge of the reference element and opens to bottom
42
+ */
16
43
  START_TO_BOTTOM = "vertical-direction-from-start-to-bottom",
44
+ /**
45
+ * starts from the top edge of the reference element and opens to top
46
+ */
17
47
  TO_TOP = "vertical-direction-to-top",
48
+ /**
49
+ * starts from the bottom edge of the reference element and opens to top
50
+ */
18
51
  END_TO_TOP = "vertical-direction-from-end-to-top",
52
+ /**
53
+ * starts and opens at the center of the reference element
54
+ */
19
55
  CENTER = "vertical-direction-at-center"
20
56
  }
21
57
  export interface OverlayProps {
@@ -9,7 +9,22 @@ export declare class MynahUIGlobalEvents {
9
9
  private readonly listeners;
10
10
  private constructor();
11
11
  static getInstance: () => MynahUIGlobalEvents;
12
+ /**
13
+ * Subscribe to value changes of a specific item in data store
14
+ * @param eventKey One of the keys in MynahUIDataModel
15
+ * @param handler function will be called with optional data field
16
+ * @returns listenerId which will be necessary to removeListener
17
+ */
12
18
  addListener: (eventKey: MynahEventNames, handler: (data?: any) => void) => string;
19
+ /**
20
+ * Unsubscribe from changes of a specific item in data store
21
+ * @param eventKey One of the keys in MynahUIDataModel
22
+ * @param listenerId listenerId which is returned from addListener function
23
+ */
13
24
  removeListener: (eventKey: MynahEventNames, listenerId: string) => void;
25
+ /**
26
+ * Updates the store and informs the subscribers.
27
+ * @param data A full or partial set of store data model with values.
28
+ */
14
29
  dispatch: (eventKey: MynahEventNames, data?: any) => void;
15
30
  }
@@ -13,13 +13,51 @@ export declare class MynahUIDataStore {
13
13
  private store;
14
14
  private defaults;
15
15
  constructor(tabId: string, initialData?: MynahUIDataModel);
16
+ /**
17
+ * Sets the defaults to use while clearing the store
18
+ * @param defaults partial set of MynahUIDataModel for defaults
19
+ */
16
20
  setDefaults: (defaults: MynahUIDataModel | null) => void;
21
+ /**
22
+ * Get the defaults to use while generating an empty store data
23
+ */
17
24
  getDefaults: () => MynahUIDataModel | null;
25
+ /**
26
+ * Get the current store data
27
+ */
18
28
  getStore: () => MynahUIDataModel | null;
29
+ /**
30
+ * Subscribe to value changes of a specific item in data store
31
+ * @param storeKey One of the keys in MynahUIDataModel
32
+ * @param handler function will be called when value of the given key is updated in store with new and old values
33
+ * @returns subscriptionId which needed to unsubscribe
34
+ */
19
35
  subscribe: (storeKey: keyof MynahUIDataModel, handler: (newValue: any, oldValue?: any) => void) => string;
36
+ /**
37
+ * Unsubscribe from changes of a specific item in data store
38
+ * @param storeKey One of the keys in MynahUIDataModel
39
+ * @param subscriptionId subscriptionId which is returned from subscribe function
40
+ */
20
41
  unsubscribe: (storeKey: keyof MynahUIDataModel, subscriptionId: string) => void;
42
+ /**
43
+ * Returns current value of an item in data store
44
+ * @param storeKey One of the keys in MynahUIDataModel
45
+ * @returns value of the given key in data store
46
+ */
21
47
  getValue: (storeKey: keyof MynahUIDataModel) => any;
48
+ /**
49
+ * Returns current value of an item in data store
50
+ * @param storeKey One of the keys in MynahUIDataModel
51
+ * @returns value of the given key in data store
52
+ */
22
53
  getDefaultValue: (storeKey: keyof MynahUIDataModel) => any;
54
+ /**
55
+ * Updates the store and informs the subscribers.
56
+ * @param data A full or partial set of store data model with values.
57
+ */
23
58
  updateStore: (data: MynahUIDataModel, skipSubscribers?: boolean) => void;
59
+ /**
60
+ * Clears store data and informs all the subscribers
61
+ */
24
62
  resetStore: () => void;
25
63
  }
@@ -1,7 +1,3 @@
1
- /*!
2
- * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
- * SPDX-License-Identifier: Apache-2.0
4
- */
5
1
  import { MynahUIDataModel, MynahUITabStoreModel, MynahUITabStoreTab } from '../static';
6
2
  import { MynahUIDataStore } from './store';
7
3
  interface TabStoreSubscription {
@@ -25,18 +21,68 @@ export declare class MynahUITabsStore {
25
21
  readonly addTab: (tabData?: MynahUITabStoreTab) => string | undefined;
26
22
  readonly removeTab: (tabId: string) => string;
27
23
  readonly selectTab: (tabId: string) => void;
24
+ /**
25
+ * Updates the store and informs the subscribers.
26
+ * @param data A full or partial set of store data model with values.
27
+ */
28
28
  updateTab: (tabId: string, tabData?: Partial<MynahUITabStoreTab>, skipSubscribers?: boolean) => void;
29
29
  static getInstance: (initialData?: MynahUITabStoreModel, defaults?: MynahUITabStoreTab) => MynahUITabsStore;
30
+ /**
31
+ * Subscribe to changes of the tabsStore
32
+ * @param handler function will be called when tabs changed
33
+ * @returns subscriptionId which needed to unsubscribe
34
+ */
30
35
  addListener: (eventName: keyof TabStoreSubscription, handler: (tabId: string, tabData?: MynahUITabStoreTab) => void) => string;
36
+ /**
37
+ * Subscribe to changes of the tabs' data store
38
+ * @param handler function will be called when tabs changed
39
+ * @returns subscriptionId which needed to unsubscribe
40
+ */
31
41
  addListenerToDataStore: (tabId: string, storeKey: keyof MynahUIDataModel, handler: (newValue: any, oldValue?: any) => void) => string | null;
42
+ /**
43
+ * Unsubscribe from changes of the tabs' data store
44
+ * @param handler function will be called when tabs changed
45
+ * @returns subscriptionId which needed to unsubscribe
46
+ */
32
47
  removeListenerFromDataStore: (tabId: string, subscriptionId: string, storeKey: keyof MynahUIDataModel) => void;
48
+ /**
49
+ * Unsubscribe from changes of the tabs store
50
+ * @param subscriptionId subscriptionId which is returned from subscribe function
51
+ */
33
52
  removeListener: (eventName: keyof TabStoreSubscription, subscriptionId: string) => void;
34
53
  private readonly informSubscribers;
54
+ /**
55
+ * Returns the tab
56
+ * @param tabId Tab Id
57
+ * @returns info of the tab
58
+ */
35
59
  getTab: (tabId: string) => MynahUITabStoreTab | null;
60
+ /**
61
+ * Returns the tab
62
+ * @param tabId Tab Id
63
+ * @returns info of the tab
64
+ */
36
65
  getAllTabs: () => MynahUITabStoreModel;
66
+ /**
67
+ * Returns the data store of the tab
68
+ * @param tabId Tab Id
69
+ * @returns data of the tab
70
+ */
37
71
  getTabDataStore: (tabId: string) => MynahUIDataStore;
72
+ /**
73
+ * Returns the data of the tab
74
+ * @param tabId Tab Id
75
+ * @returns data of the tab
76
+ */
38
77
  getSelectedTabId: () => string;
78
+ /**
79
+ * Clears store data and informs all the subscribers
80
+ */
39
81
  removeAllTabs: () => void;
82
+ /**
83
+ * Get all tabs length
84
+ * @returns tabs length
85
+ */
40
86
  tabsLength: () => number;
41
87
  }
42
88
  export {};
package/dist/main.d.ts CHANGED
@@ -30,6 +30,10 @@ export interface MynahUIProps {
30
30
  onTabChange?: (tabId: string, eventId?: string) => void;
31
31
  onTabAdd?: (tabId: string, eventId?: string) => void;
32
32
  onTabRemove?: (tabId: string, eventId?: string) => void;
33
+ /**
34
+ * @param tabId tabId which the close button triggered
35
+ * @returns boolean -> If you want to close the tab immediately send true
36
+ */
33
37
  onBeforeTabRemove?: (tabId: string, eventId?: string) => boolean;
34
38
  onChatItemEngagement?: (tabId: string, messageId: string, engagement: Engagement) => void;
35
39
  onCopyCodeToClipboard?: (tabId: string, messageId: string, code?: string, type?: CodeSelectionType, referenceTrackerInformation?: ReferenceTrackerInformation[], eventId?: string, codeBlockIndex?: number, totalCodeBlocks?: number) => void;
@@ -43,7 +47,11 @@ export interface MynahUIProps {
43
47
  text?: string;
44
48
  formItemValues?: Record<string, string>;
45
49
  }, eventId?: string) => void;
50
+ /**
51
+ * @deprecated since version 4.6.3. Will be dropped after version 5.x.x. Use {@link onFileClick} instead
52
+ */
46
53
  onOpenDiff?: (tabId: string, filePath: string, deleted: boolean, messageId?: string, eventId?: string) => void;
54
+ onFileClick?: (tabId: string, filePath: string, deleted: boolean, messageId?: string, eventId?: string) => void;
47
55
  onFileActionClick?: (tabId: string, messageId: string, filePath: string, actionName: string, eventId?: string) => void;
48
56
  onTabBarButtonClick?: (tabId: string, buttonId: string, eventId?: string) => void;
49
57
  }
@@ -59,16 +67,72 @@ export declare class MynahUI {
59
67
  private readonly getUserEventId;
60
68
  private readonly addGlobalListeners;
61
69
  addToUserPrompt: (tabId: string, codeStringToAdd: string) => void;
70
+ /**
71
+ * Adds a new item to the chat window
72
+ * @param tabId Corresponding tab ID.
73
+ * @param answer An ChatItem object.
74
+ */
62
75
  addChatItem: (tabId: string, chatItem: ChatItem) => void;
76
+ /**
77
+ * Updates the last ChatItemType.ANSWER_STREAM chat item
78
+ * @param tabId Corresponding tab ID.
79
+ * @param updateWith ChatItem object to update with.
80
+ */
63
81
  updateLastChatAnswer: (tabId: string, updateWith: Partial<ChatItem>) => void;
82
+ /**
83
+ * Updates the chat item with the given messageId
84
+ * @param tabId Corresponding tab ID.
85
+ * @param messageId Corresponding tab ID.
86
+ * @param updateWith ChatItem object to update with.
87
+ */
64
88
  updateChatAnswerWithMessageId: (tabId: string, messageId: string, updateWith: Partial<ChatItem>) => void;
89
+ /**
90
+ * Converts a card to an ANSWER if it is an ANSWER_STREAM
91
+ * @param tabId Corresponding tab ID.
92
+ * @param messageId Corresponding tab ID.
93
+ * @param updateWith Optional, if you like update the card while converting it to
94
+ * a normal ANSWER instead of a stream one, you can send a ChatItem object to update with.
95
+ */
65
96
  endMessageStream: (tabId: string, messageId: string, updateWith?: Partial<ChatItem>) => CardRenderDetails;
97
+ /**
98
+ * If exists, switch to a different tab
99
+ * @param tabId Tab ID to switch to
100
+ * @param eventId last action's user event ID passed from an event binded to mynahUI.
101
+ * Without user intent you cannot switch to a different tab
102
+ */
66
103
  selectTab: (tabId: string, eventId: string) => void;
104
+ /**
105
+ * If exists, close the given tab
106
+ * @param tabId Tab ID to switch to
107
+ * @param eventId last action's user event ID passed from an event binded to mynahUI.
108
+ * Without user intent you cannot switch to a different tab
109
+ */
67
110
  removeTab: (tabId: string, eventId: string) => void;
111
+ /**
112
+ * Updates only the UI with the given data for the given tab
113
+ * Send tab id as an empty string to open a new tab!
114
+ * If max tabs reached, will not return tabId
115
+ * @param data A full or partial set of data with values.
116
+ */
68
117
  updateStore: (tabId: string | '', data: MynahUIDataModel) => string | undefined;
118
+ /**
119
+ * This function returns the selected tab id if there is any, otherwise returns undefined
120
+ * @returns string selectedTabId or undefined
121
+ */
69
122
  getSelectedTabId: () => string | undefined;
123
+ /**
124
+ * Returns all tabs with their store information
125
+ * @returns string selectedTabId or undefined
126
+ */
70
127
  getAllTabs: () => MynahUITabStoreModel;
128
+ /**
129
+ * Simply creates and shows a notification
130
+ * @param props NotificationProps
131
+ */
71
132
  notify: (props: {
133
+ /**
134
+ * -1 for infinite
135
+ */
72
136
  duration?: number | undefined;
73
137
  type?: NotificationType | undefined;
74
138
  title?: string | undefined;
@@ -76,5 +140,9 @@ export declare class MynahUI {
76
140
  onNotificationClick?: ((eventId: string) => void) | undefined;
77
141
  onNotificationHide?: ((eventId: string) => void) | undefined;
78
142
  }) => void;
143
+ /**
144
+ * Simply creates and shows a notification
145
+ * @param props NotificationProps
146
+ */
79
147
  showCustomForm: (tabId: string, formItems?: ChatItemFormItem[], buttons?: ChatItemButton[], title?: string, description?: string) => void;
80
148
  }