@sendbird/uikit-utils 1.0.1 → 1.0.2
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/lib/commonjs/hooks/index.js +88 -0
- package/lib/commonjs/hooks/index.js.map +1 -0
- package/lib/commonjs/index.js +223 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/sendbird/attrs.js +57 -0
- package/lib/commonjs/sendbird/attrs.js.map +1 -0
- package/lib/commonjs/sendbird/channel.js +53 -0
- package/lib/commonjs/sendbird/channel.js.map +1 -0
- package/lib/commonjs/sendbird/message.js +111 -0
- package/lib/commonjs/sendbird/message.js.map +1 -0
- package/lib/commonjs/shared/arrayToMap.js +54 -0
- package/lib/commonjs/shared/arrayToMap.js.map +1 -0
- package/lib/commonjs/shared/conditionChaining.js +15 -0
- package/lib/commonjs/shared/conditionChaining.js.map +1 -0
- package/lib/commonjs/shared/logger.js +98 -0
- package/lib/commonjs/shared/logger.js.map +1 -0
- package/lib/commonjs/shared/pubsub.js +54 -0
- package/lib/commonjs/shared/pubsub.js.map +1 -0
- package/lib/commonjs/shared/regex.js +102 -0
- package/lib/commonjs/shared/regex.js.map +1 -0
- package/lib/commonjs/types.js +6 -0
- package/lib/commonjs/types.js.map +1 -0
- package/lib/commonjs/ui-format/common.js +106 -0
- package/lib/commonjs/ui-format/common.js.map +1 -0
- package/lib/commonjs/ui-format/groupChannel.js +80 -0
- package/lib/commonjs/ui-format/groupChannel.js.map +1 -0
- package/lib/module/hooks/index.js +60 -0
- package/lib/module/hooks/index.js.map +1 -0
- package/lib/module/index.js +15 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/sendbird/attrs.js +49 -0
- package/lib/module/sendbird/attrs.js.map +1 -0
- package/lib/module/sendbird/channel.js +36 -0
- package/lib/module/sendbird/channel.js.map +1 -0
- package/lib/module/sendbird/message.js +85 -0
- package/lib/module/sendbird/message.js.map +1 -0
- package/lib/module/shared/arrayToMap.js +45 -0
- package/lib/module/shared/arrayToMap.js.map +1 -0
- package/lib/module/shared/conditionChaining.js +7 -0
- package/lib/module/shared/conditionChaining.js.map +1 -0
- package/lib/module/shared/logger.js +90 -0
- package/lib/module/shared/logger.js.map +1 -0
- package/lib/module/shared/pubsub.js +45 -0
- package/lib/module/shared/pubsub.js.map +1 -0
- package/lib/module/shared/regex.js +78 -0
- package/lib/module/shared/regex.js.map +1 -0
- package/lib/module/types.js +2 -0
- package/lib/module/types.js.map +1 -0
- package/lib/module/ui-format/common.js +85 -0
- package/lib/module/ui-format/common.js.map +1 -0
- package/lib/module/ui-format/groupChannel.js +59 -0
- package/lib/module/ui-format/groupChannel.js.map +1 -0
- package/lib/typescript/src/hooks/index.d.ts +11 -0
- package/lib/typescript/src/index.d.ts +15 -0
- package/lib/typescript/src/sendbird/attrs.d.ts +43 -0
- package/lib/typescript/src/sendbird/channel.d.ts +18 -0
- package/lib/typescript/src/sendbird/message.d.ts +20 -0
- package/lib/typescript/src/shared/arrayToMap.d.ts +5 -0
- package/lib/typescript/src/shared/conditionChaining.d.ts +2 -0
- package/lib/typescript/src/shared/logger.d.ts +38 -0
- package/lib/typescript/src/shared/pubsub.d.ts +8 -0
- package/lib/typescript/src/shared/regex.d.ts +11 -0
- package/lib/typescript/src/types.d.ts +79 -0
- package/lib/typescript/src/ui-format/common.d.ts +43 -0
- package/lib/typescript/src/ui-format/groupChannel.d.ts +5 -0
- package/package.json +2 -2
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import format from 'date-fns/format';
|
|
2
|
+
import isToday from 'date-fns/isToday';
|
|
3
|
+
import isYesterday from 'date-fns/isYesterday';
|
|
4
|
+
import { truncate } from './common';
|
|
5
|
+
export const getGroupChannelTitle = function (currentUserId, channel) {
|
|
6
|
+
let EMPTY_USERNAME = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '(No name)';
|
|
7
|
+
let NO_MEMBERS = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '(No members)';
|
|
8
|
+
let DEFAULT_CHANNEL_NAME = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 'Group Channel';
|
|
9
|
+
if (channel.name !== DEFAULT_CHANNEL_NAME && channel.name !== '') return channel.name;
|
|
10
|
+
if (channel.memberCount === 1) return NO_MEMBERS;
|
|
11
|
+
return channel.members.filter(_ref => {
|
|
12
|
+
let {
|
|
13
|
+
userId
|
|
14
|
+
} = _ref;
|
|
15
|
+
return userId !== currentUserId;
|
|
16
|
+
}).map(_ref2 => {
|
|
17
|
+
let {
|
|
18
|
+
nickname
|
|
19
|
+
} = _ref2;
|
|
20
|
+
return nickname || EMPTY_USERNAME;
|
|
21
|
+
}).join(', ');
|
|
22
|
+
};
|
|
23
|
+
export const getGroupChannelPreviewTime = (channel, locale) => {
|
|
24
|
+
var _channel$lastMessage;
|
|
25
|
+
|
|
26
|
+
const timestamp = ((_channel$lastMessage = channel.lastMessage) === null || _channel$lastMessage === void 0 ? void 0 : _channel$lastMessage.createdAt) || channel.joinedAt * 1000 || channel.createdAt;
|
|
27
|
+
if (isToday(timestamp)) return format(timestamp, 'p', {
|
|
28
|
+
locale
|
|
29
|
+
});
|
|
30
|
+
if (isYesterday(timestamp)) return 'Yesterday';
|
|
31
|
+
return format(timestamp, 'MMM dd', {
|
|
32
|
+
locale
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
export const getGroupChannelLastMessage = function (channel) {
|
|
36
|
+
let EMPTY_MESSAGE = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
37
|
+
let MAX_LEN = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 15;
|
|
38
|
+
const message = channel.lastMessage;
|
|
39
|
+
if (!message) return EMPTY_MESSAGE;
|
|
40
|
+
|
|
41
|
+
if (message.isFileMessage()) {
|
|
42
|
+
const extIdx = message.name.lastIndexOf('.');
|
|
43
|
+
|
|
44
|
+
if (extIdx > -1) {
|
|
45
|
+
const file = message.name.slice(0, extIdx);
|
|
46
|
+
const ext = message.name.slice(extIdx);
|
|
47
|
+
return truncate(file, {
|
|
48
|
+
maxLen: MAX_LEN
|
|
49
|
+
}) + ext;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return truncate(message.name, {
|
|
53
|
+
maxLen: MAX_LEN
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return message.message ?? EMPTY_MESSAGE;
|
|
58
|
+
};
|
|
59
|
+
//# sourceMappingURL=groupChannel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["format","isToday","isYesterday","truncate","getGroupChannelTitle","currentUserId","channel","EMPTY_USERNAME","NO_MEMBERS","DEFAULT_CHANNEL_NAME","name","memberCount","members","filter","userId","map","nickname","join","getGroupChannelPreviewTime","locale","timestamp","lastMessage","createdAt","joinedAt","getGroupChannelLastMessage","EMPTY_MESSAGE","MAX_LEN","message","isFileMessage","extIdx","lastIndexOf","file","slice","ext","maxLen"],"sources":["groupChannel.ts"],"sourcesContent":["import type { Locale } from 'date-fns';\nimport format from 'date-fns/format';\nimport isToday from 'date-fns/isToday';\nimport isYesterday from 'date-fns/isYesterday';\n\nimport type { SendbirdGroupChannel } from '../types';\nimport { truncate } from './common';\n\nexport const getGroupChannelTitle = (\n currentUserId: string,\n channel: SendbirdGroupChannel,\n EMPTY_USERNAME = '(No name)',\n NO_MEMBERS = '(No members)',\n DEFAULT_CHANNEL_NAME = 'Group Channel',\n) => {\n if (channel.name !== DEFAULT_CHANNEL_NAME && channel.name !== '') return channel.name;\n if (channel.memberCount === 1) return NO_MEMBERS;\n return channel.members\n .filter(({ userId }) => userId !== currentUserId)\n .map(({ nickname }) => nickname || EMPTY_USERNAME)\n .join(', ');\n};\n\nexport const getGroupChannelPreviewTime = (channel: SendbirdGroupChannel, locale?: Locale) => {\n const timestamp = channel.lastMessage?.createdAt || channel.joinedAt * 1000 || channel.createdAt;\n if (isToday(timestamp)) return format(timestamp, 'p', { locale });\n if (isYesterday(timestamp)) return 'Yesterday';\n return format(timestamp, 'MMM dd', { locale });\n};\n\nexport const getGroupChannelLastMessage = (channel: SendbirdGroupChannel, EMPTY_MESSAGE = '', MAX_LEN = 15) => {\n const message = channel.lastMessage;\n if (!message) return EMPTY_MESSAGE;\n\n if (message.isFileMessage()) {\n const extIdx = message.name.lastIndexOf('.');\n if (extIdx > -1) {\n const file = message.name.slice(0, extIdx);\n const ext = message.name.slice(extIdx);\n return truncate(file, { maxLen: MAX_LEN }) + ext;\n }\n\n return truncate(message.name, { maxLen: MAX_LEN });\n }\n\n return message.message ?? EMPTY_MESSAGE;\n};\n"],"mappings":"AACA,OAAOA,MAAP,MAAmB,iBAAnB;AACA,OAAOC,OAAP,MAAoB,kBAApB;AACA,OAAOC,WAAP,MAAwB,sBAAxB;AAGA,SAASC,QAAT,QAAyB,UAAzB;AAEA,OAAO,MAAMC,oBAAoB,GAAG,UAClCC,aADkC,EAElCC,OAFkC,EAM/B;EAAA,IAHHC,cAGG,uEAHc,WAGd;EAAA,IAFHC,UAEG,uEAFU,cAEV;EAAA,IADHC,oBACG,uEADoB,eACpB;EACH,IAAIH,OAAO,CAACI,IAAR,KAAiBD,oBAAjB,IAAyCH,OAAO,CAACI,IAAR,KAAiB,EAA9D,EAAkE,OAAOJ,OAAO,CAACI,IAAf;EAClE,IAAIJ,OAAO,CAACK,WAAR,KAAwB,CAA5B,EAA+B,OAAOH,UAAP;EAC/B,OAAOF,OAAO,CAACM,OAAR,CACJC,MADI,CACG;IAAA,IAAC;MAAEC;IAAF,CAAD;IAAA,OAAgBA,MAAM,KAAKT,aAA3B;EAAA,CADH,EAEJU,GAFI,CAEA;IAAA,IAAC;MAAEC;IAAF,CAAD;IAAA,OAAkBA,QAAQ,IAAIT,cAA9B;EAAA,CAFA,EAGJU,IAHI,CAGC,IAHD,CAAP;AAID,CAbM;AAeP,OAAO,MAAMC,0BAA0B,GAAG,CAACZ,OAAD,EAAgCa,MAAhC,KAAoD;EAAA;;EAC5F,MAAMC,SAAS,GAAG,yBAAAd,OAAO,CAACe,WAAR,8EAAqBC,SAArB,KAAkChB,OAAO,CAACiB,QAAR,GAAmB,IAArD,IAA6DjB,OAAO,CAACgB,SAAvF;EACA,IAAIrB,OAAO,CAACmB,SAAD,CAAX,EAAwB,OAAOpB,MAAM,CAACoB,SAAD,EAAY,GAAZ,EAAiB;IAAED;EAAF,CAAjB,CAAb;EACxB,IAAIjB,WAAW,CAACkB,SAAD,CAAf,EAA4B,OAAO,WAAP;EAC5B,OAAOpB,MAAM,CAACoB,SAAD,EAAY,QAAZ,EAAsB;IAAED;EAAF,CAAtB,CAAb;AACD,CALM;AAOP,OAAO,MAAMK,0BAA0B,GAAG,UAAClB,OAAD,EAAqE;EAAA,IAArCmB,aAAqC,uEAArB,EAAqB;EAAA,IAAjBC,OAAiB,uEAAP,EAAO;EAC7G,MAAMC,OAAO,GAAGrB,OAAO,CAACe,WAAxB;EACA,IAAI,CAACM,OAAL,EAAc,OAAOF,aAAP;;EAEd,IAAIE,OAAO,CAACC,aAAR,EAAJ,EAA6B;IAC3B,MAAMC,MAAM,GAAGF,OAAO,CAACjB,IAAR,CAAaoB,WAAb,CAAyB,GAAzB,CAAf;;IACA,IAAID,MAAM,GAAG,CAAC,CAAd,EAAiB;MACf,MAAME,IAAI,GAAGJ,OAAO,CAACjB,IAAR,CAAasB,KAAb,CAAmB,CAAnB,EAAsBH,MAAtB,CAAb;MACA,MAAMI,GAAG,GAAGN,OAAO,CAACjB,IAAR,CAAasB,KAAb,CAAmBH,MAAnB,CAAZ;MACA,OAAO1B,QAAQ,CAAC4B,IAAD,EAAO;QAAEG,MAAM,EAAER;MAAV,CAAP,CAAR,GAAsCO,GAA7C;IACD;;IAED,OAAO9B,QAAQ,CAACwB,OAAO,CAACjB,IAAT,EAAe;MAAEwB,MAAM,EAAER;IAAV,CAAf,CAAf;EACD;;EAED,OAAOC,OAAO,CAACA,OAAR,IAAmBF,aAA1B;AACD,CAhBM"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { DependencyList } from 'react';
|
|
2
|
+
declare type Destructor = () => void;
|
|
3
|
+
declare type AsyncEffectCallback = () => void | Destructor | Promise<void> | Promise<Destructor>;
|
|
4
|
+
export declare const useUniqId: (key: string) => number;
|
|
5
|
+
export declare const useForceUpdate: () => () => void;
|
|
6
|
+
export declare const useAsyncEffect: (asyncEffect: AsyncEffectCallback, deps?: DependencyList) => void;
|
|
7
|
+
export declare const useAsyncLayoutEffect: (asyncEffect: AsyncEffectCallback, deps?: DependencyList) => void;
|
|
8
|
+
export declare const useIIFE: <T>(callback: () => T) => T;
|
|
9
|
+
export declare const useIsMountedRef: () => import("react").MutableRefObject<boolean>;
|
|
10
|
+
export declare const useFreshCallback: <T extends (...args: any[]) => any>(callback: T) => T;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export { Logger } from './shared/logger';
|
|
2
|
+
export { default as arrayToMap, arrayToMapWithGetter } from './shared/arrayToMap';
|
|
3
|
+
export { createPubSub } from './shared/pubsub';
|
|
4
|
+
export { default as conditionChaining } from './shared/conditionChaining';
|
|
5
|
+
export { urlRegexStrict, urlRegexRough, newLineRegex, audioExtRegex, videoExtRegex, imageExtRegex, getFileType, getFileExtension, replaceUrlAsComponents, } from './shared/regex';
|
|
6
|
+
export * from './hooks';
|
|
7
|
+
export * from './ui-format/groupChannel';
|
|
8
|
+
export * from './ui-format/common';
|
|
9
|
+
export * from './sendbird/channel';
|
|
10
|
+
export * from './sendbird/message';
|
|
11
|
+
export * from './sendbird/attrs';
|
|
12
|
+
export declare const NOOP: () => void;
|
|
13
|
+
export declare const ASYNC_NOOP: () => Promise<undefined>;
|
|
14
|
+
export declare const PASS: <T>(val: T) => T;
|
|
15
|
+
export type { FilterByValueType, UnionToIntersection, OmittedValues, PartialDeep, Optional, ContextValue, SendbirdMessage, SendbirdChatSDK, SendbirdChannel, SendbirdBaseChannel, SendbirdGroupChannel, SendbirdOpenChannel, SendbirdUser, SendbirdMember, SendbirdBaseMessage, SendbirdUserMessage, SendbirdFileMessage, SendbirdAdminMessage, SendbirdGroupChannelParams, SendbirdFileMessageParams, SendbirdUserMessageParams, SendbirdError, SendbirdMessageCollection, SendbirdGroupChannelCollection, NotificationFiles, NotificationMentionedUsers, NotificationTranslations, PartialNullable, SendbirdDataPayload, } from './types';
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export declare enum ApplicationAttributes {
|
|
2
|
+
reactions = "reactions",
|
|
3
|
+
message_search_v3 = "message_search_v3",
|
|
4
|
+
enable_og_tag = "enable_og_tag",
|
|
5
|
+
use_last_seen_at = "use_last_seen_at",
|
|
6
|
+
enable_message_threading = "enable_message_threading",
|
|
7
|
+
allow_message_update_from_sdk = "allow_message_update_from_sdk",
|
|
8
|
+
allow_group_channel_create_from_sdk = "allow_group_channel_create_from_sdk",
|
|
9
|
+
allow_migration_api = "allow_migration_api",
|
|
10
|
+
allow_only_operator_sdk_to_update_group_channel_image = "allow_only_operator_sdk_to_update_group_channel_image",
|
|
11
|
+
allow_user_update_from_sdk = "allow_user_update_from_sdk",
|
|
12
|
+
allow_broadcast_channel = "allow_broadcast_channel",
|
|
13
|
+
allow_sdk_file_message_urls = "allow_sdk_file_message_urls",
|
|
14
|
+
allow_group_channel_leave_from_sdk = "allow_group_channel_leave_from_sdk",
|
|
15
|
+
allow_user_list_from_sdk = "allow_user_list_from_sdk",
|
|
16
|
+
allow_group_channel_invite_from_sdk = "allow_group_channel_invite_from_sdk",
|
|
17
|
+
allow_only_operator_sdk_to_update_group_channel_name = "allow_only_operator_sdk_to_update_group_channel_name",
|
|
18
|
+
allow_group_channel_update_from_sdk = "allow_group_channel_update_from_sdk",
|
|
19
|
+
allow_super_group_channel = "allow_super_group_channel",
|
|
20
|
+
allow_non_operators_to_mention_channel = "allow_non_operators_to_mention_channel",
|
|
21
|
+
allow_file_messages_from_sdk = "allow_file_messages_from_sdk",
|
|
22
|
+
allow_open_channel_create_from_sdk = "allow_open_channel_create_from_sdk",
|
|
23
|
+
allow_anonymous_message_update = "allow_anonymous_message_update",
|
|
24
|
+
allow_group_channel_delete_from_sdk = "allow_group_channel_delete_from_sdk",
|
|
25
|
+
allow_operators_to_ban_operators = "allow_operators_to_ban_operators",
|
|
26
|
+
allow_operators_to_edit_operators = "allow_operators_to_edit_operators"
|
|
27
|
+
}
|
|
28
|
+
export declare enum PremiumFeatures {
|
|
29
|
+
reactions = "reactions",
|
|
30
|
+
moderation_group = "moderation_group",
|
|
31
|
+
message_search_v3 = "message_search_v3",
|
|
32
|
+
data_export = "data_export",
|
|
33
|
+
migration = "migration",
|
|
34
|
+
delivery_receipt = "delivery_receipt",
|
|
35
|
+
auto_thumbnail = "auto_thumbnail",
|
|
36
|
+
image_moderation = "image_moderation",
|
|
37
|
+
super_group_channel = "super_group_channel",
|
|
38
|
+
announcement = "announcement",
|
|
39
|
+
moderation_open = "moderation_open",
|
|
40
|
+
desk = "desk",
|
|
41
|
+
bot_interface = "bot_interface",
|
|
42
|
+
auto_trans = "auto_trans"
|
|
43
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { SendbirdBaseChannel, SendbirdGroupChannel } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Default sort comparator for channel
|
|
4
|
+
* @param {SendbirdBaseChannel} a
|
|
5
|
+
* @param {SendbirdBaseChannel} b
|
|
6
|
+
* @returns {number}
|
|
7
|
+
* */
|
|
8
|
+
export declare function channelComparator<T extends SendbirdBaseChannel>(a: T, b: T): number;
|
|
9
|
+
/**
|
|
10
|
+
* Diff utils for channel
|
|
11
|
+
* @param {SendbirdBaseChannel} [a]
|
|
12
|
+
* @param {SendbirdBaseChannel} [b]
|
|
13
|
+
* @returns {boolean}
|
|
14
|
+
* */
|
|
15
|
+
export declare function isDifferentChannel<T extends SendbirdBaseChannel>(a?: T, b?: T): boolean;
|
|
16
|
+
export declare const groupChannelChatUnavailable: (channel: SendbirdGroupChannel) => boolean;
|
|
17
|
+
export declare function isDefaultCoverImage(coverUrl: string): boolean;
|
|
18
|
+
export declare function getMembersExcludeMe(channel: SendbirdGroupChannel, currentUserId?: string): import("sendbird").Member[];
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { SendbirdDataPayload, SendbirdFileMessage, SendbirdMessage } from '../types';
|
|
2
|
+
export declare function isNewMessage(msg: SendbirdMessage, currentUserId?: string): boolean;
|
|
3
|
+
export declare function isMyMessage(msg: SendbirdMessage, currentUserId?: string): boolean;
|
|
4
|
+
export declare function messageKeyExtractor(message: SendbirdMessage): string;
|
|
5
|
+
export declare function messageComparator<T extends SendbirdMessage>(a: T, b: T): number;
|
|
6
|
+
export declare function hasSameSender(a?: SendbirdMessage, b?: SendbirdMessage): boolean;
|
|
7
|
+
export declare function calcMessageGrouping(groupEnabled: boolean, curr: SendbirdMessage, prev?: SendbirdMessage, next?: SendbirdMessage): {
|
|
8
|
+
groupWithPrev: boolean;
|
|
9
|
+
groupWithNext: boolean;
|
|
10
|
+
};
|
|
11
|
+
export declare function getMessageUniqId(msg: SendbirdMessage): string;
|
|
12
|
+
export declare function getAvailableUriFromFileMessage(message: SendbirdFileMessage): string;
|
|
13
|
+
declare type RawSendbirdDataPayload = {
|
|
14
|
+
sendbird: string | object;
|
|
15
|
+
};
|
|
16
|
+
export declare function isSendbirdNotification(dataPayload?: {
|
|
17
|
+
[key: string]: string | object;
|
|
18
|
+
}): dataPayload is RawSendbirdDataPayload;
|
|
19
|
+
export declare function parseSendbirdNotification(dataPayload: RawSendbirdDataPayload): SendbirdDataPayload;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { FilterByValueType } from '../types';
|
|
2
|
+
export default function arrayToMap<T extends Record<K, unknown>, K extends keyof T = keyof T>(arr: T[], selector: keyof FilterByValueType<T, string | number>): Record<string, T>;
|
|
3
|
+
export default function arrayToMap<T extends Record<K, unknown>, K extends keyof T = keyof T>(arr: T[], selector: string, fallbackSelector: K): Record<string, T>;
|
|
4
|
+
export default function arrayToMap<T extends Record<K, unknown>, K extends keyof T = keyof T>(arr: T[], selector: string, selector2: string, combineKey: true): Record<string, T>;
|
|
5
|
+
export declare function arrayToMapWithGetter<T extends Record<K, unknown>, K extends keyof T = keyof T>(arr: T[], getSelector: (item: T) => string): Record<string, T>;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
declare const LogLevelEnum: {
|
|
2
|
+
none: number;
|
|
3
|
+
log: number;
|
|
4
|
+
error: number;
|
|
5
|
+
warn: number;
|
|
6
|
+
info: number;
|
|
7
|
+
debug: number;
|
|
8
|
+
};
|
|
9
|
+
declare type LogLevel = keyof typeof LogLevelEnum;
|
|
10
|
+
export declare const Logger: {
|
|
11
|
+
LogLevelEnum: {
|
|
12
|
+
none: number;
|
|
13
|
+
log: number;
|
|
14
|
+
error: number;
|
|
15
|
+
warn: number;
|
|
16
|
+
info: number;
|
|
17
|
+
debug: number;
|
|
18
|
+
};
|
|
19
|
+
create: (level?: LogLevel) => {
|
|
20
|
+
setTitle(title: string): void;
|
|
21
|
+
setLogLevel(lv: LogLevel): void;
|
|
22
|
+
getLogLevel(): "none" | "log" | "error" | "warn" | "info" | "debug";
|
|
23
|
+
log(...args: unknown[]): number;
|
|
24
|
+
error(...args: unknown[]): number;
|
|
25
|
+
warn(...args: unknown[]): number;
|
|
26
|
+
info(...args: unknown[]): number;
|
|
27
|
+
debug(...args: unknown[]): number;
|
|
28
|
+
};
|
|
29
|
+
setTitle(title: string): void;
|
|
30
|
+
setLogLevel(lv: LogLevel): void;
|
|
31
|
+
getLogLevel(): "none" | "log" | "error" | "warn" | "info" | "debug";
|
|
32
|
+
log(...args: unknown[]): number;
|
|
33
|
+
error(...args: unknown[]): number;
|
|
34
|
+
warn(...args: unknown[]): number;
|
|
35
|
+
info(...args: unknown[]): number;
|
|
36
|
+
debug(...args: unknown[]): number;
|
|
37
|
+
};
|
|
38
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare type SubscribeListener = ((...args: unknown[]) => void) & {
|
|
2
|
+
onError?: (error: unknown) => void;
|
|
3
|
+
};
|
|
4
|
+
export declare type SubscribeListenerPool = Record<symbol, SubscribeListener>;
|
|
5
|
+
export declare const createPubSub: (label?: string) => {
|
|
6
|
+
subscribe: (event: string, listener: SubscribeListener, subscriber?: string) => () => void;
|
|
7
|
+
publish: (event: string, ...args: unknown[]) => void;
|
|
8
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const urlRegexStrict: RegExp;
|
|
2
|
+
export declare const urlRegexRough: RegExp;
|
|
3
|
+
export declare const phoneRegex: RegExp;
|
|
4
|
+
export declare const emailRegex: RegExp;
|
|
5
|
+
export declare const newLineRegex: RegExp;
|
|
6
|
+
export declare const replaceUrlAsComponents: <T>(originText: string, replacer: (url: string) => T, strict?: boolean) => (string | T)[];
|
|
7
|
+
export declare const imageExtRegex: RegExp;
|
|
8
|
+
export declare const audioExtRegex: RegExp;
|
|
9
|
+
export declare const videoExtRegex: RegExp;
|
|
10
|
+
export declare const getFileType: (extOrType: string) => "video" | "audio" | "image" | "file";
|
|
11
|
+
export declare function getFileExtension(filePath: string): string;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
import type Sendbird from 'sendbird';
|
|
3
|
+
export declare type FilterByValueType<T extends object, Type> = {
|
|
4
|
+
[K in keyof T as T[K] extends Type ? K : never]: T[K];
|
|
5
|
+
};
|
|
6
|
+
export declare type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
7
|
+
export declare type OmittedValues<T, K extends keyof T> = Omit<T, K>[keyof Omit<T, K>];
|
|
8
|
+
export declare type PartialDeep<T> = T extends object ? T extends Function ? T : {
|
|
9
|
+
[P in keyof T]?: PartialDeep<T[P]>;
|
|
10
|
+
} : T;
|
|
11
|
+
export declare type PartialNullable<T> = {
|
|
12
|
+
[P in keyof T]?: T[P] | null;
|
|
13
|
+
};
|
|
14
|
+
export declare type Optional<T> = T | undefined;
|
|
15
|
+
export declare type ContextValue<T extends React.Context<any>> = T extends React.Context<infer V> ? V : never;
|
|
16
|
+
export declare type SendbirdChatSDK = Sendbird.SendBirdInstance;
|
|
17
|
+
export declare type SendbirdMessage = Sendbird.BaseMessageInstance | Sendbird.FileMessage | Sendbird.UserMessage | Sendbird.AdminMessage;
|
|
18
|
+
export declare type SendbirdChannel = Sendbird.BaseChannel | Sendbird.GroupChannel | Sendbird.OpenChannel;
|
|
19
|
+
export declare type SendbirdUserMessage = Sendbird.UserMessage;
|
|
20
|
+
export declare type SendbirdFileMessage = Sendbird.FileMessage;
|
|
21
|
+
export declare type SendbirdAdminMessage = Sendbird.AdminMessage;
|
|
22
|
+
export declare type SendbirdBaseMessage = Sendbird.BaseMessageInstance;
|
|
23
|
+
export declare type SendbirdFileMessageParams = Sendbird.FileMessageParams;
|
|
24
|
+
export declare type SendbirdUserMessageParams = Sendbird.UserMessageParams;
|
|
25
|
+
export declare type SendbirdError = Sendbird.SendBirdError;
|
|
26
|
+
export declare type SendbirdGroupChannelParams = Sendbird.GroupChannelParams;
|
|
27
|
+
export declare type SendbirdUser = Sendbird.User;
|
|
28
|
+
export declare type SendbirdMember = Sendbird.Member;
|
|
29
|
+
export declare type SendbirdGroupChannel = Sendbird.GroupChannel;
|
|
30
|
+
export declare type SendbirdBaseChannel = Sendbird.BaseChannel;
|
|
31
|
+
export declare type SendbirdOpenChannel = Sendbird.OpenChannel;
|
|
32
|
+
export declare type SendbirdGroupChannelCollection = Sendbird.GroupChannelCollection;
|
|
33
|
+
export declare type SendbirdMessageCollection = Sendbird.MessageCollection;
|
|
34
|
+
export interface SendbirdDataPayload {
|
|
35
|
+
app_id: string;
|
|
36
|
+
audience_type: string;
|
|
37
|
+
category: string;
|
|
38
|
+
channel: {
|
|
39
|
+
channel_unread_message_count: number;
|
|
40
|
+
channel_url: string;
|
|
41
|
+
custom_type: string;
|
|
42
|
+
name: string;
|
|
43
|
+
};
|
|
44
|
+
channel_type: string;
|
|
45
|
+
created_at: number;
|
|
46
|
+
custom_type: string;
|
|
47
|
+
files: NotificationFiles[];
|
|
48
|
+
mentioned_users: NotificationMentionedUsers[];
|
|
49
|
+
message: string;
|
|
50
|
+
message_id: number;
|
|
51
|
+
push_sound: string;
|
|
52
|
+
push_title: null;
|
|
53
|
+
recipient: {
|
|
54
|
+
id: string;
|
|
55
|
+
name: string;
|
|
56
|
+
push_template: string;
|
|
57
|
+
};
|
|
58
|
+
sender?: {
|
|
59
|
+
id: string;
|
|
60
|
+
name: string;
|
|
61
|
+
profile_url: string;
|
|
62
|
+
require_auth_for_profile_image: boolean;
|
|
63
|
+
};
|
|
64
|
+
sqs_ts: number;
|
|
65
|
+
translations: NotificationTranslations;
|
|
66
|
+
type: 'ADMM' | 'MESG' | 'FILE' | string;
|
|
67
|
+
unread_message_count: number;
|
|
68
|
+
}
|
|
69
|
+
export interface NotificationFiles {
|
|
70
|
+
type: string;
|
|
71
|
+
url: string;
|
|
72
|
+
name: string;
|
|
73
|
+
size: number;
|
|
74
|
+
require_auth: boolean;
|
|
75
|
+
}
|
|
76
|
+
export interface NotificationTranslations {
|
|
77
|
+
}
|
|
78
|
+
export interface NotificationMentionedUsers {
|
|
79
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { Locale } from 'date-fns';
|
|
2
|
+
declare type TruncateMode = 'head' | 'mid' | 'tail';
|
|
3
|
+
declare type TruncateOption = {
|
|
4
|
+
mode: TruncateMode;
|
|
5
|
+
maxLen: number;
|
|
6
|
+
separator: string;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* String truncate util
|
|
10
|
+
* @param {string} str
|
|
11
|
+
* @param {Object} opts Options for truncate
|
|
12
|
+
* @param {'head' | 'mid' | 'tail'} opts.mode default "mid"
|
|
13
|
+
* @param {number} opts.maxLen default 40
|
|
14
|
+
* @param {string} opts.separator default "..."
|
|
15
|
+
* @returns {string}
|
|
16
|
+
* */
|
|
17
|
+
export declare const truncate: (str: string, opts?: Partial<TruncateOption>) => string;
|
|
18
|
+
/**
|
|
19
|
+
* Badge count truncate util
|
|
20
|
+
* If count exceed the limit, it comes in the form of "MAX+"
|
|
21
|
+
*
|
|
22
|
+
* @param {number} count
|
|
23
|
+
* @param {number} MAX default 99
|
|
24
|
+
* @returns {string}
|
|
25
|
+
* */
|
|
26
|
+
export declare const truncatedBadgeCount: (count: number, MAX?: number) => string;
|
|
27
|
+
/**
|
|
28
|
+
* Messages date separator format
|
|
29
|
+
*
|
|
30
|
+
* @param {Date} date
|
|
31
|
+
* @param {Locale} [locale]
|
|
32
|
+
* @returns {string}
|
|
33
|
+
* */
|
|
34
|
+
export declare const dateSeparator: (date: Date, locale?: Locale) => string;
|
|
35
|
+
/**
|
|
36
|
+
* Message time format
|
|
37
|
+
*
|
|
38
|
+
* @param {Date} date
|
|
39
|
+
* @param {Locale} [locale]
|
|
40
|
+
* @returns {string}
|
|
41
|
+
* */
|
|
42
|
+
export declare const messageTime: (date: Date, locale?: Locale) => string;
|
|
43
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Locale } from 'date-fns';
|
|
2
|
+
import type { SendbirdGroupChannel } from '../types';
|
|
3
|
+
export declare const getGroupChannelTitle: (currentUserId: string, channel: SendbirdGroupChannel, EMPTY_USERNAME?: string, NO_MEMBERS?: string, DEFAULT_CHANNEL_NAME?: string) => string;
|
|
4
|
+
export declare const getGroupChannelPreviewTime: (channel: SendbirdGroupChannel, locale?: Locale) => string;
|
|
5
|
+
export declare const getGroupChannelLastMessage: (channel: SendbirdGroupChannel, EMPTY_MESSAGE?: string, MAX_LEN?: number) => string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sendbird/uikit-utils",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "UIKit utilities",
|
|
5
5
|
"main": "lib/commonjs/index",
|
|
6
6
|
"module": "lib/module/index",
|
|
@@ -71,5 +71,5 @@
|
|
|
71
71
|
"readmeFile": "./README.md",
|
|
72
72
|
"displayName": "@sendbird/uikit-utils"
|
|
73
73
|
},
|
|
74
|
-
"gitHead": "
|
|
74
|
+
"gitHead": "257ece5f957e03ff5c08b79780b33d9d19adc5de"
|
|
75
75
|
}
|