@sendbird/uikit-utils 2.1.0 → 2.3.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/lib/commonjs/hooks/index.js +14 -1
- package/lib/commonjs/hooks/index.js.map +1 -1
- package/lib/commonjs/hooks/react-native.js +56 -0
- package/lib/commonjs/hooks/react-native.js.map +1 -0
- package/lib/commonjs/index.js +38 -7
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/sendbird/channel.js +7 -1
- package/lib/commonjs/sendbird/channel.js.map +1 -1
- package/lib/commonjs/sendbird/message.js +12 -2
- package/lib/commonjs/sendbird/message.js.map +1 -1
- package/lib/commonjs/sendbird/user.js +5 -0
- package/lib/commonjs/sendbird/user.js.map +1 -1
- package/lib/commonjs/shared/index.js +74 -0
- package/lib/commonjs/shared/index.js.map +1 -0
- package/lib/commonjs/shared/regex.js +52 -6
- package/lib/commonjs/shared/regex.js.map +1 -1
- package/lib/commonjs/types.js +3 -1
- package/lib/commonjs/types.js.map +1 -1
- package/lib/commonjs/ui-format/common.js +17 -14
- package/lib/commonjs/ui-format/common.js.map +1 -1
- package/lib/commonjs/ui-format/groupChannel.js +7 -10
- package/lib/commonjs/ui-format/groupChannel.js.map +1 -1
- package/lib/module/hooks/index.js +10 -0
- package/lib/module/hooks/index.js.map +1 -1
- package/lib/module/hooks/react-native.js +39 -0
- package/lib/module/hooks/react-native.js.map +1 -0
- package/lib/module/index.js +3 -2
- package/lib/module/index.js.map +1 -1
- package/lib/module/sendbird/channel.js +3 -0
- package/lib/module/sendbird/channel.js.map +1 -1
- package/lib/module/sendbird/message.js +9 -3
- package/lib/module/sendbird/message.js.map +1 -1
- package/lib/module/sendbird/user.js +3 -0
- package/lib/module/sendbird/user.js.map +1 -1
- package/lib/module/shared/index.js +57 -0
- package/lib/module/shared/index.js.map +1 -0
- package/lib/module/shared/regex.js +43 -3
- package/lib/module/shared/regex.js.map +1 -1
- package/lib/module/types.js +1 -4
- package/lib/module/types.js.map +1 -1
- package/lib/module/ui-format/common.js +12 -7
- package/lib/module/ui-format/common.js.map +1 -1
- package/lib/module/ui-format/groupChannel.js +5 -4
- package/lib/module/ui-format/groupChannel.js.map +1 -1
- package/lib/typescript/src/hooks/index.d.ts +3 -2
- package/lib/typescript/src/hooks/react-native.d.ts +12 -0
- package/lib/typescript/src/index.d.ts +4 -3
- package/lib/typescript/src/sendbird/channel.d.ts +1 -0
- package/lib/typescript/src/sendbird/message.d.ts +4 -2
- package/lib/typescript/src/sendbird/user.d.ts +2 -0
- package/lib/typescript/src/shared/bufferedRequest.d.ts +1 -1
- package/lib/typescript/src/shared/index.d.ts +26 -0
- package/lib/typescript/src/shared/logger.d.ts +1 -1
- package/lib/typescript/src/shared/pubsub.d.ts +2 -2
- package/lib/typescript/src/shared/regex.d.ts +8 -0
- package/lib/typescript/src/types.d.ts +42 -36
- package/lib/typescript/src/ui-format/common.d.ts +7 -6
- package/package.json +4 -3
- package/src/hooks/index.ts +11 -0
- package/src/hooks/react-native.ts +56 -0
- package/src/index.ts +10 -1
- package/src/sendbird/channel.ts +4 -0
- package/src/sendbird/message.ts +13 -3
- package/src/sendbird/user.ts +6 -0
- package/src/shared/index.ts +56 -0
- package/src/shared/regex.ts +35 -0
- package/src/types.ts +20 -3
- package/src/ui-format/common.ts +9 -7
- package/src/ui-format/groupChannel.ts +5 -4
- package/lib/commonjs/shared/conditionChaining.js +0 -15
- package/lib/commonjs/shared/conditionChaining.js.map +0 -1
- package/lib/module/shared/conditionChaining.js +0 -7
- package/lib/module/shared/conditionChaining.js.map +0 -1
- package/lib/typescript/src/shared/conditionChaining.d.ts +0 -2
- package/src/shared/conditionChaining.ts +0 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["require","shim","urlRegexStrict","urlRegexRough","phoneRegex","emailRegex","newLineRegex","
|
|
1
|
+
{"version":3,"names":["require","shim","urlRegexStrict","urlRegexRough","phoneRegex","emailRegex","newLineRegex","createMentionTemplateRegex","trigger","RegExp","replaceWithRegex","text","regex","replacer","keyPrefix","matches","matchAll","founds","map","value","start","index","end","length","groups","matchIndex","items","cursor","forEach","restText","pop","head","slice","mid","match","tail","push","replaceUrlAsComponents","originText","strict","imageExtRegex","audioExtRegex","videoExtRegex","getFileType","extOrType","indexOf","type","split","getFileExtension","filePath","idx","lastIndexOf","toLowerCase","normalizeFileName","fileName","extension"],"sources":["regex.ts"],"sourcesContent":["// For iOS 12 backwards compatibility\nrequire('string.prototype.matchall').shim();\n\nexport const urlRegexStrict =\n /(https?:\\/\\/|www\\.)[-a-zA-Z0-9@:%._+~#=]{1,256}\\.(xn--)?[a-z0-9-]{2,20}\\b([-a-zA-Z0-9@:%_+[\\],.~#?&/=]*[-a-zA-Z0-9@:%_+\\]~#?&/=])*/g;\nexport const urlRegexRough =\n /(https?:\\/\\/|www\\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\\.[a-zA-Z0-9()]{1,6}\\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)/g;\nexport const phoneRegex = /[+]?[(]?[0-9]{3}[)]?[-\\s.]?[0-9]{3}[-\\s.]?[0-9]{4,7}/;\nexport const emailRegex = /\\S+@\\S+\\.\\S+/;\nexport const newLineRegex = /\\r\\n|\\r|\\n/g;\n\nexport const createMentionTemplateRegex = (trigger: string) => new RegExp(`(${trigger}[{])(.*?)([}])`, 'g');\n\n// const cases = [\n// {\n// type: 'urlStrict',\n// regex: urlRegexStrict,\n// },\n// {\n// type: 'urlRough',\n// regex: urlRegexStrict,\n// },\n// {\n// type: 'email',\n// regex: emailRegex,\n// },\n// {\n// type: 'phone',\n// regex: urlRegexStrict,\n// },\n// ];\n\nexport const replaceWithRegex = <T>(\n text: string,\n regex: RegExp,\n replacer: (params: {\n match: string;\n groups: string[];\n matchIndex: number | undefined;\n index: number;\n keyPrefix: string;\n }) => T,\n keyPrefix: string,\n) => {\n const matches = [...text.matchAll(regex)];\n const founds = matches.map((value) => {\n const text = value[0];\n const start = value.index ?? 0;\n const end = start + text.length;\n return { text, start, end, groups: value, matchIndex: value.index };\n });\n\n const items: Array<T | string> = [text];\n let cursor = 0;\n founds.forEach(({ text, start, end, groups, matchIndex }, index) => {\n const restText = items.pop() as string;\n const head = restText.slice(0, start - cursor);\n const mid = replacer({ match: text, groups, matchIndex, index, keyPrefix });\n const tail = restText.slice(end - cursor);\n items.push(head, mid, tail);\n cursor = end;\n });\n return items;\n};\n\nexport const replaceUrlAsComponents = <T>(originText: string, replacer: (url: string) => T, strict?: boolean) => {\n const matches = [...originText.matchAll(strict ? urlRegexStrict : urlRegexRough)];\n const founds = matches.map((value) => {\n const text = value[0];\n const start = value.index ?? 0;\n const end = start + text.length;\n return { text, start, end };\n });\n\n const items: Array<string | T> = [originText];\n let cursor = 0;\n founds.forEach(({ text, start, end }) => {\n const restText = items.pop() as string;\n const head = restText.slice(0, start - cursor);\n const mid = replacer(text);\n const tail = restText.slice(end - cursor);\n items.push(head, mid, tail);\n cursor = end;\n });\n return items;\n};\n\nexport const imageExtRegex = /jpeg|jpg|png|webp|gif/i;\nexport const audioExtRegex = /3gp|aac|aax|act|aiff|flac|gsm|m4a|m4b|m4p|tta|wma|mp3|webm|wav/i;\nexport const videoExtRegex = /mov|vod|mp4|avi/i;\nexport const getFileType = (extOrType: string) => {\n if (extOrType.indexOf('/') > -1) {\n const type = extOrType.split('/')[0];\n if (type === 'video') return 'video';\n if (type === 'audio') return 'audio';\n if (type === 'image') return 'image';\n return 'file';\n }\n\n if (extOrType.match(imageExtRegex)) return 'image';\n if (extOrType.match(audioExtRegex)) return 'audio';\n if (extOrType.match(videoExtRegex)) return 'video';\n return 'file';\n};\nexport function getFileExtension(filePath: string) {\n const idx = filePath.lastIndexOf('.');\n if (idx === -1) return '';\n return filePath.slice(idx - filePath.length).toLowerCase();\n}\nexport function normalizeFileName(fileName: string, extension: string) {\n if (fileName.indexOf(extension) > -1) {\n return fileName;\n } else {\n if (extension.indexOf('.') === 0) {\n return `${fileName}${extension}`;\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AAT,CAAqB,GAArB,CAAZ;EACA,IAAID,GAAG,KAAK,CAAC,CAAb,EAAgB,OAAO,EAAP;EAChB,OAAOD,QAAQ,CAACjB,KAAT,CAAekB,GAAG,GAAGD,QAAQ,CAAC1B,MAA9B,EAAsC6B,WAAtC,EAAP;AACD;AACD,OAAO,SAASC,iBAAT,CAA2BC,QAA3B,EAA6CC,SAA7C,EAAgE;EACrE,IAAID,QAAQ,CAACT,OAAT,CAAiBU,SAAjB,IAA8B,CAAC,CAAnC,EAAsC;IACpC,OAAOD,QAAP;EACD,CAFD,MAEO;IACL,IAAIC,SAAS,CAACV,OAAV,CAAkB,GAAlB,MAA2B,CAA/B,EAAkC;MAChC,OAAQ,GAAES,QAAS,GAAEC,SAAU,EAA/B;IACD,CAFD,MAEO;MACL,OAAQ,GAAED,QAAS,IAAGC,SAAU,EAAhC;IACD;EACF;AACF"}
|
package/lib/module/types.js
CHANGED
package/lib/module/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n\n/* eslint-disable @typescript-eslint/no-empty-interface */\nimport type React from 'react';\n\nimport type SendbirdChat from '@sendbird/chat';\nimport type {
|
|
1
|
+
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n\n/* eslint-disable @typescript-eslint/no-empty-interface */\nimport type React from 'react';\n\nimport type SendbirdChat from '@sendbird/chat';\nimport type {\n BaseChannel,\n Emoji,\n EmojiCategory,\n EmojiContainer,\n RestrictedUser,\n SendbirdError as SBError,\n User,\n UserUpdateParams,\n} from '@sendbird/chat';\nimport type {\n GroupChannel,\n GroupChannelCollection,\n GroupChannelCreateParams,\n GroupChannelListQuery,\n GroupChannelModule,\n GroupChannelUpdateParams,\n Member,\n MessageCollection,\n} from '@sendbird/chat/groupChannel';\nimport type { ModuleNamespaces, SendableMessage } from '@sendbird/chat/lib/__definition';\nimport type {\n AdminMessage,\n BaseMessage,\n FileMessage,\n FileMessageCreateParams,\n FileMessageUpdateParams,\n PreviousMessageListQuery,\n Reaction,\n UserMessage,\n UserMessageCreateParams,\n UserMessageUpdateParams,\n} from '@sendbird/chat/message';\nimport type { OpenChannel, OpenChannelModule } from '@sendbird/chat/openChannel';\n\nexport type FilterByValueType<T extends object, Type> = {\n [K in keyof T as T[K] extends Type ? K : never]: T[K];\n};\n\nexport type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends (k: infer I) => void\n ? I\n : never;\n\nexport type OmittedValues<T, K extends keyof T> = Omit<T, K>[keyof Omit<T, K>];\n\nexport type PartialDeep<T> = T extends object\n ? T extends Function\n ? T\n : {\n [P in keyof T]?: PartialDeep<T[P]>;\n }\n : T;\n\nexport type PartialNullable<T> = {\n [P in keyof T]?: T[P] | null;\n};\n\nexport type Optional<T> = T | undefined;\n\nexport type ContextValue<T extends React.Context<any>> = T extends React.Context<infer V> ? V : never;\n\nexport interface UserStruct {\n userId: string;\n}\n\nexport type SendbirdChatSDK = SendbirdChat & ModuleNamespaces<[GroupChannelModule, OpenChannelModule]>;\nexport type SendbirdMessage = BaseMessage | FileMessage | UserMessage | AdminMessage | SendableMessage;\nexport type SendbirdChannel = BaseChannel | GroupChannel | OpenChannel;\nexport type SendbirdUserMessage = UserMessage;\nexport type SendbirdFileMessage = FileMessage;\nexport type SendbirdAdminMessage = AdminMessage;\nexport type SendbirdBaseMessage = BaseMessage;\nexport type SendbirdSendableMessage = SendableMessage;\nexport type SendbirdFileMessageCreateParams = FileMessageCreateParams;\nexport type SendbirdFileMessageUpdateParams = FileMessageUpdateParams;\nexport type SendbirdUserMessageCreateParams = UserMessageCreateParams;\nexport type SendbirdUserMessageUpdateParams = UserMessageUpdateParams;\nexport type SendbirdGroupChannelCreateParams = GroupChannelCreateParams;\nexport type SendbirdGroupChannelUpdateParams = GroupChannelUpdateParams;\nexport type SendbirdUserUpdateParams = UserUpdateParams;\nexport type SendbirdUser = User;\nexport type SendbirdRestrictedUser = RestrictedUser;\nexport type SendbirdMember = Member;\nexport type SendbirdGroupChannel = GroupChannel;\nexport type SendbirdBaseChannel = BaseChannel;\nexport type SendbirdOpenChannel = OpenChannel;\n\nexport type SendbirdReaction = Reaction;\nexport type SendbirdEmoji = Emoji;\nexport type SendbirdEmojiCategory = EmojiCategory;\nexport type SendbirdEmojiContainer = EmojiContainer;\n\nexport type SendbirdGroupChannelCollection = GroupChannelCollection;\nexport type SendbirdGroupChannelListQuery = GroupChannelListQuery;\nexport type SendbirdMessageCollection = MessageCollection;\nexport type SendbirdPreviousMessageListQuery = PreviousMessageListQuery;\n\nexport type SendbirdError = SBError;\n\nexport interface SendbirdDataPayload {\n app_id: string;\n audience_type: string;\n category: string;\n channel: {\n channel_unread_message_count: number;\n channel_url: string;\n custom_type: string;\n name: string;\n };\n channel_type: string;\n created_at: number;\n custom_type: string;\n files: NotificationFiles[];\n mentioned_users: NotificationMentionedUsers[];\n message: string;\n message_id: number;\n push_sound: string;\n push_title: null;\n recipient: {\n id: string;\n name: string;\n push_template: string;\n };\n sender?: {\n id: string;\n name: string;\n profile_url: string;\n require_auth_for_profile_image: boolean;\n };\n sqs_ts: number;\n translations: NotificationTranslations;\n type: 'ADMM' | 'MESG' | 'FILE' | string;\n unread_message_count: number;\n}\nexport interface NotificationFiles {\n type: string;\n url: string;\n name: string;\n size: number;\n require_auth: boolean;\n}\n\nexport interface NotificationTranslations {}\nexport interface NotificationMentionedUsers {}\n"],"mappings":""}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import format from 'date-fns
|
|
1
|
+
import { format, isThisYear } from 'date-fns';
|
|
2
2
|
const defaultOpts = {
|
|
3
3
|
mode: 'mid',
|
|
4
4
|
maxLen: 40,
|
|
@@ -43,17 +43,19 @@ export const truncate = function (str) {
|
|
|
43
43
|
throw new Error('Invalid truncate mode: ' + mode);
|
|
44
44
|
};
|
|
45
45
|
/**
|
|
46
|
-
*
|
|
46
|
+
* Count truncate util
|
|
47
47
|
* If count exceed the limit, it comes in the form of "MAX+"
|
|
48
48
|
*
|
|
49
49
|
* @param {number} count
|
|
50
50
|
* @param {number} MAX default 99
|
|
51
|
+
* @param {string} MAX_SUFFIX default +
|
|
51
52
|
* @returns {string}
|
|
52
53
|
* */
|
|
53
54
|
|
|
54
|
-
export const
|
|
55
|
+
export const truncatedCount = function (count) {
|
|
55
56
|
let MAX = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 99;
|
|
56
|
-
|
|
57
|
+
let MAX_SUFFIX = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '+';
|
|
58
|
+
if (count >= MAX) return `${MAX}${MAX_SUFFIX}`;
|
|
57
59
|
return `${count}`;
|
|
58
60
|
};
|
|
59
61
|
/**
|
|
@@ -64,8 +66,11 @@ export const truncatedBadgeCount = function (count) {
|
|
|
64
66
|
* @returns {string}
|
|
65
67
|
* */
|
|
66
68
|
|
|
67
|
-
export const
|
|
68
|
-
return format(date, '
|
|
69
|
+
export const getDateSeparatorFormat = (date, locale) => {
|
|
70
|
+
if (isThisYear(date)) return format(date, 'MMM dd, yyyy', {
|
|
71
|
+
locale
|
|
72
|
+
});
|
|
73
|
+
return format(date, 'E, MMM dd', {
|
|
69
74
|
locale
|
|
70
75
|
});
|
|
71
76
|
};
|
|
@@ -77,7 +82,7 @@ export const dateSeparator = (date, locale) => {
|
|
|
77
82
|
* @returns {string}
|
|
78
83
|
* */
|
|
79
84
|
|
|
80
|
-
export const
|
|
85
|
+
export const getMessageTimeFormat = (date, locale) => {
|
|
81
86
|
return format(date, 'p', {
|
|
82
87
|
locale
|
|
83
88
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["format","defaultOpts","mode","maxLen","separator","truncate","str","opts","options","length","slice","lead","Math","ceil","trail","floor","Error","
|
|
1
|
+
{"version":3,"names":["format","isThisYear","defaultOpts","mode","maxLen","separator","truncate","str","opts","options","length","slice","lead","Math","ceil","trail","floor","Error","truncatedCount","count","MAX","MAX_SUFFIX","getDateSeparatorFormat","date","locale","getMessageTimeFormat"],"sources":["common.ts"],"sourcesContent":["import type { Locale } from 'date-fns';\nimport { format, isThisYear } from 'date-fns';\n\ntype TruncateMode = 'head' | 'mid' | 'tail';\ntype TruncateOption = { mode: TruncateMode; maxLen: number; separator: string };\nconst defaultOpts: TruncateOption = { mode: 'mid', maxLen: 40, separator: '...' };\n\n/**\n * String truncate util\n * @param {string} str\n * @param {Object} opts Options for truncate\n * @param {'head' | 'mid' | 'tail'} opts.mode default \"mid\"\n * @param {number} opts.maxLen default 40\n * @param {string} opts.separator default \"...\"\n * @returns {string}\n * */\nexport const truncate = (str: string, opts: Partial<TruncateOption> = defaultOpts): string => {\n const options = { ...defaultOpts, ...opts };\n const { maxLen, mode, separator } = options;\n\n if (str.length <= maxLen) return str;\n\n if (mode === 'head') {\n return separator + str.slice(-maxLen);\n }\n\n if (mode === 'mid') {\n const lead = Math.ceil(maxLen / 2);\n const trail = Math.floor(maxLen / 2);\n return str.slice(0, lead) + separator + str.slice(-trail);\n }\n\n if (mode === 'tail') {\n return str.slice(0, maxLen) + separator;\n }\n\n throw new Error('Invalid truncate mode: ' + mode);\n};\n\n/**\n * Count truncate util\n * If count exceed the limit, it comes in the form of \"MAX+\"\n *\n * @param {number} count\n * @param {number} MAX default 99\n * @param {string} MAX_SUFFIX default +\n * @returns {string}\n * */\nexport const truncatedCount = (count: number, MAX = 99, MAX_SUFFIX = '+') => {\n if (count >= MAX) return `${MAX}${MAX_SUFFIX}`;\n return `${count}`;\n};\n\n/**\n * Messages date separator format\n *\n * @param {Date} date\n * @param {Locale} [locale]\n * @returns {string}\n * */\nexport const getDateSeparatorFormat = (date: Date, locale?: Locale): string => {\n if (isThisYear(date)) return format(date, 'MMM dd, yyyy', { locale });\n return format(date, 'E, MMM dd', { locale });\n};\n\n/**\n * Message time format\n *\n * @param {Date} date\n * @param {Locale} [locale]\n * @returns {string}\n * */\nexport const getMessageTimeFormat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OAAO,MAAMe,cAAc,GAAG,UAACC,KAAD,EAA+C;EAAA,IAA/BC,GAA+B,uEAAzB,EAAyB;EAAA,IAArBC,UAAqB,uEAAR,GAAQ;EAC3E,IAAIF,KAAK,IAAIC,GAAb,EAAkB,OAAQ,GAAEA,GAAI,GAAEC,UAAW,EAA3B;EAClB,OAAQ,GAAEF,KAAM,EAAhB;AACD,CAHM;AAKP;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMG,sBAAsB,GAAG,CAACC,IAAD,EAAaC,MAAb,KAAyC;EAC7E,IAAIvB,UAAU,CAACsB,IAAD,CAAd,EAAsB,OAAOvB,MAAM,CAACuB,IAAD,EAAO,cAAP,EAAuB;IAAEC;EAAF,CAAvB,CAAb;EACtB,OAAOxB,MAAM,CAACuB,IAAD,EAAO,WAAP,EAAoB;IAAEC;EAAF,CAApB,CAAb;AACD,CAHM;AAKP;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,oBAAoB,GAAG,CAACF,IAAD,EAAaC,MAAb,KAAyC;EAC3E,OAAOxB,MAAM,CAACuB,IAAD,EAAO,GAAP,EAAY;IAAEC;EAAF,CAAZ,CAAb;AACD,CAFM"}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import format from 'date-fns
|
|
2
|
-
import isToday from 'date-fns/isToday';
|
|
3
|
-
import isYesterday from 'date-fns/isYesterday';
|
|
1
|
+
import { format, isThisYear, isToday, isYesterday } from 'date-fns';
|
|
4
2
|
import { truncate } from './common';
|
|
5
3
|
export const getGroupChannelTitle = function (currentUserId, channel) {
|
|
6
4
|
let EMPTY_USERNAME = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '(No name)';
|
|
@@ -28,7 +26,10 @@ export const getGroupChannelPreviewTime = (channel, locale) => {
|
|
|
28
26
|
locale
|
|
29
27
|
});
|
|
30
28
|
if (isYesterday(timestamp)) return 'Yesterday';
|
|
31
|
-
return format(timestamp, 'MMM dd', {
|
|
29
|
+
if (isThisYear(timestamp)) return format(timestamp, 'MMM dd', {
|
|
30
|
+
locale
|
|
31
|
+
});
|
|
32
|
+
return format(timestamp, 'yyyy/MM/dd', {
|
|
32
33
|
locale
|
|
33
34
|
});
|
|
34
35
|
};
|
|
@@ -1 +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","isUserMessage","isAdminMessage"],"sources":["groupChannel.ts"],"sourcesContent":["import type { Locale } from 'date-fns';\nimport
|
|
1
|
+
{"version":3,"names":["format","isThisYear","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","isUserMessage","isAdminMessage"],"sources":["groupChannel.ts"],"sourcesContent":["import type { Locale } from 'date-fns';\nimport { format, isThisYear, isToday, isYesterday } from 'date-fns';\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\n if (isToday(timestamp)) return format(timestamp, 'p', { locale });\n if (isYesterday(timestamp)) return 'Yesterday';\n if (isThisYear(timestamp)) return format(timestamp, 'MMM dd', { locale });\n\n return format(timestamp, 'yyyy/MM/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 if (message.isUserMessage()) {\n return message.message ?? EMPTY_MESSAGE;\n }\n\n if (message.isAdminMessage()) {\n return message.message ?? EMPTY_MESSAGE;\n }\n\n return EMPTY_MESSAGE;\n};\n"],"mappings":"AACA,SAASA,MAAT,EAAiBC,UAAjB,EAA6BC,OAA7B,EAAsCC,WAAtC,QAAyD,UAAzD;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,C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,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,IAAIC,OAAO,CAACQ,aAAR,EAAJ,EAA6B;IAC3B,OAAOR,OAAO,CAACA,OAAR,IAAmBF,aAA1B;EACD;;EAED,IAAIE,OAAO,CAACS,cAAR,EAAJ,EAA8B;IAC5B,OAAOT,OAAO,CAACA,OAAR,IAAmBF,aAA1B;EACD;;EAED,OAAOA,aAAP;AACD,CAxBM"}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import type { DependencyList } from 'react';
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
type Destructor = () => void;
|
|
3
|
+
type AsyncEffectCallback = () => void | Destructor | Promise<void> | Promise<Destructor>;
|
|
4
4
|
export declare const useUniqId: (key: string) => number;
|
|
5
5
|
export declare const useForceUpdate: () => () => void;
|
|
6
6
|
export declare const useAsyncEffect: (asyncEffect: AsyncEffectCallback, deps?: DependencyList) => void;
|
|
7
7
|
export declare const useAsyncLayoutEffect: (asyncEffect: AsyncEffectCallback, deps?: DependencyList) => void;
|
|
8
8
|
export declare const useIIFE: <T>(callback: () => T) => T;
|
|
9
9
|
export declare const useIsMountedRef: () => import("react").MutableRefObject<boolean>;
|
|
10
|
+
export declare const useIsFirstMount: () => boolean;
|
|
10
11
|
export declare const useFreshCallback: <T extends (...args: any[]) => any>(callback: T) => T;
|
|
11
12
|
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { AppStateEvent, AppStateStatus } from 'react-native';
|
|
2
|
+
import { EdgeInsets } from 'react-native-safe-area-context';
|
|
3
|
+
type EdgePaddingMap = {
|
|
4
|
+
left: 'paddingLeft';
|
|
5
|
+
right: 'paddingRight';
|
|
6
|
+
top: 'paddingTop';
|
|
7
|
+
bottom: 'paddingBottom';
|
|
8
|
+
};
|
|
9
|
+
export declare const useSafeAreaPadding: <T extends keyof EdgeInsets, Result extends { [key in EdgePaddingMap[T]]: EdgeInsets[T]; }>(edges: T[]) => Result;
|
|
10
|
+
type AppStateListener = (status: AppStateStatus) => void;
|
|
11
|
+
export declare const useAppState: (type: AppStateEvent, listener: AppStateListener) => void;
|
|
12
|
+
export {};
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
export { Logger } from './shared/logger';
|
|
2
2
|
export { default as arrayToMap, arrayToMapWithGetter } from './shared/arrayToMap';
|
|
3
3
|
export { createPubSub } from './shared/pubsub';
|
|
4
|
-
export {
|
|
5
|
-
export { urlRegexStrict, urlRegexRough, newLineRegex, audioExtRegex, videoExtRegex, imageExtRegex, getFileType, getFileExtension, replaceUrlAsComponents, normalizeFileName, emailRegex, phoneRegex, } from './shared/regex';
|
|
4
|
+
export { urlRegexStrict, urlRegexRough, newLineRegex, audioExtRegex, videoExtRegex, imageExtRegex, getFileType, getFileExtension, replaceUrlAsComponents, normalizeFileName, emailRegex, phoneRegex, replaceWithRegex, createMentionTemplateRegex, } from './shared/regex';
|
|
6
5
|
export { BufferedRequest } from './shared/bufferedRequest';
|
|
6
|
+
export * from './shared';
|
|
7
7
|
export * from './hooks';
|
|
8
|
+
export * from './hooks/react-native';
|
|
8
9
|
export * from './ui-format/groupChannel';
|
|
9
10
|
export * from './ui-format/common';
|
|
10
11
|
export * from './sendbird/channel';
|
|
@@ -22,4 +23,4 @@ export declare const SBErrorCode: {
|
|
|
22
23
|
export declare const SBErrorMessage: {
|
|
23
24
|
ACL: string;
|
|
24
25
|
};
|
|
25
|
-
export type { FilterByValueType, UnionToIntersection, OmittedValues, PartialDeep, Optional, ContextValue, SendbirdMessage, SendbirdChatSDK, SendbirdChannel, SendbirdBaseChannel, SendbirdGroupChannel, SendbirdOpenChannel, SendbirdUser, SendbirdMember, SendbirdBaseMessage, SendbirdUserMessage, SendbirdFileMessage, SendbirdAdminMessage, SendbirdGroupChannelCreateParams, SendbirdFileMessageCreateParams, SendbirdUserMessageCreateParams, SendbirdError, SendbirdMessageCollection, SendbirdGroupChannelCollection, NotificationFiles, NotificationMentionedUsers, NotificationTranslations, PartialNullable, SendbirdDataPayload, SendbirdPreviousMessageListQuery, SendbirdSendableMessage, SendbirdGroupChannelListQuery, SendbirdGroupChannelUpdateParams, SendbirdUserMessageUpdateParams, SendbirdFileMessageUpdateParams, SendbirdUserUpdateParams, SendbirdRestrictedUser, } from './types';
|
|
26
|
+
export type { UserStruct, FilterByValueType, UnionToIntersection, OmittedValues, PartialDeep, Optional, ContextValue, SendbirdMessage, SendbirdChatSDK, SendbirdChannel, SendbirdBaseChannel, SendbirdGroupChannel, SendbirdOpenChannel, SendbirdUser, SendbirdMember, SendbirdBaseMessage, SendbirdUserMessage, SendbirdFileMessage, SendbirdAdminMessage, SendbirdGroupChannelCreateParams, SendbirdFileMessageCreateParams, SendbirdUserMessageCreateParams, SendbirdError, SendbirdMessageCollection, SendbirdGroupChannelCollection, NotificationFiles, NotificationMentionedUsers, NotificationTranslations, PartialNullable, SendbirdDataPayload, SendbirdPreviousMessageListQuery, SendbirdSendableMessage, SendbirdGroupChannelListQuery, SendbirdGroupChannelUpdateParams, SendbirdUserMessageUpdateParams, SendbirdFileMessageUpdateParams, SendbirdUserUpdateParams, SendbirdRestrictedUser, SendbirdReaction, SendbirdEmojiContainer, SendbirdEmoji, SendbirdEmojiCategory, } from './types';
|
|
@@ -17,3 +17,4 @@ export declare function isDefaultCoverImage(coverUrl: string): boolean;
|
|
|
17
17
|
export declare function getMembersExcludeMe(channel: SendbirdGroupChannel, currentUserId?: string): import("@sendbird/chat/groupChannel").Member[];
|
|
18
18
|
export declare function getGroupChannels(channels: SendbirdChannel[]): SendbirdGroupChannel[];
|
|
19
19
|
export declare function getOpenChannels(channels: SendbirdChannel[]): SendbirdOpenChannel[];
|
|
20
|
+
export declare function getChannelUniqId(channel: SendbirdChannel): string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { SendbirdBaseMessage, SendbirdDataPayload, SendbirdFileMessage, SendbirdMessage, SendbirdSendableMessage } from '../types';
|
|
1
|
+
import type { SendbirdBaseChannel, SendbirdBaseMessage, SendbirdDataPayload, SendbirdFileMessage, SendbirdMessage, SendbirdReaction, SendbirdSendableMessage } from '../types';
|
|
2
2
|
export declare function isNewMessage(msg: SendbirdMessage, currentUserId?: string): boolean;
|
|
3
3
|
export declare function isSendableMessage(msg?: SendbirdMessage | null): msg is SendbirdSendableMessage;
|
|
4
4
|
export declare function isMyMessage(msg?: SendbirdMessage | null, currentUserId?: string): boolean;
|
|
@@ -11,11 +11,13 @@ export declare function calcMessageGrouping(groupEnabled: boolean, curr: Sendbir
|
|
|
11
11
|
};
|
|
12
12
|
export declare function getMessageUniqId(msg: SendbirdBaseMessage): string;
|
|
13
13
|
export declare function getAvailableUriFromFileMessage(message: SendbirdFileMessage): string;
|
|
14
|
-
|
|
14
|
+
type RawSendbirdDataPayload = {
|
|
15
15
|
sendbird: string | object;
|
|
16
16
|
};
|
|
17
17
|
export declare function isSendbirdNotification(dataPayload?: {
|
|
18
18
|
[key: string]: string | object;
|
|
19
19
|
}): dataPayload is RawSendbirdDataPayload;
|
|
20
20
|
export declare function parseSendbirdNotification(dataPayload: RawSendbirdDataPayload): SendbirdDataPayload;
|
|
21
|
+
export declare function shouldRenderReaction(channel: SendbirdBaseChannel, reactionEnabled: boolean): boolean;
|
|
22
|
+
export declare function getReactionCount(reaction: SendbirdReaction): number;
|
|
21
23
|
export {};
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { Role } from '@sendbird/chat';
|
|
2
|
+
import type { UserStruct } from '../types';
|
|
2
3
|
export declare function ifOperator<T>(role: Role, then: T): T | undefined;
|
|
3
4
|
export declare function ifOperator<T, V>(role: Role, then: T, or: V): T | V;
|
|
4
5
|
export declare function ifMuted<T>(muted: boolean, then: T): T | undefined;
|
|
5
6
|
export declare function ifMuted<T, V>(muted: boolean, then: T, or: V): T | V;
|
|
7
|
+
export declare function getUserUniqId<T extends UserStruct>(user: T): string;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a given string to a hashed string.
|
|
3
|
+
* */
|
|
4
|
+
export declare function hash(str: string): string;
|
|
5
|
+
/**
|
|
6
|
+
* Replace a specific range of text in the string with another text.
|
|
7
|
+
* */
|
|
8
|
+
export declare function replace(str: string, start: number, end: number, text: string): string;
|
|
9
|
+
/**
|
|
10
|
+
* Returns the value corresponding to the first true index of a given condition array.
|
|
11
|
+
* */
|
|
12
|
+
export declare function conditionChaining<T, V>(conditions: T[], values: V[]): V;
|
|
13
|
+
/**
|
|
14
|
+
* Calculates the downscale size.
|
|
15
|
+
* */
|
|
16
|
+
type Size = {
|
|
17
|
+
width: number;
|
|
18
|
+
height: number;
|
|
19
|
+
};
|
|
20
|
+
export declare function getDownscaleSize(origin: Size, resizing: Partial<Size>): {
|
|
21
|
+
width: number;
|
|
22
|
+
height: number;
|
|
23
|
+
};
|
|
24
|
+
export declare function isImage(filePath: string, mimeType?: string): boolean;
|
|
25
|
+
export declare function shouldCompressImage(filePath: string, compressionEnabled?: boolean): boolean;
|
|
26
|
+
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export
|
|
1
|
+
export type SubscribeListener = ((...args: unknown[]) => void) & {
|
|
2
2
|
onError?: (error: unknown) => void;
|
|
3
3
|
};
|
|
4
|
-
export
|
|
4
|
+
export type SubscribeListenerPool = Record<symbol, SubscribeListener>;
|
|
5
5
|
export declare const createPubSub: (label?: string) => {
|
|
6
6
|
subscribe: (event: string, listener: SubscribeListener, subscriber?: string) => () => void;
|
|
7
7
|
publish: (event: string, ...args: unknown[]) => void;
|
|
@@ -3,6 +3,14 @@ export declare const urlRegexRough: RegExp;
|
|
|
3
3
|
export declare const phoneRegex: RegExp;
|
|
4
4
|
export declare const emailRegex: RegExp;
|
|
5
5
|
export declare const newLineRegex: RegExp;
|
|
6
|
+
export declare const createMentionTemplateRegex: (trigger: string) => RegExp;
|
|
7
|
+
export declare const replaceWithRegex: <T>(text: string, regex: RegExp, replacer: (params: {
|
|
8
|
+
match: string;
|
|
9
|
+
groups: string[];
|
|
10
|
+
matchIndex: number | undefined;
|
|
11
|
+
index: number;
|
|
12
|
+
keyPrefix: string;
|
|
13
|
+
}) => T, keyPrefix: string) => (string | T)[];
|
|
6
14
|
export declare const replaceUrlAsComponents: <T>(originText: string, replacer: (url: string) => T, strict?: boolean) => (string | T)[];
|
|
7
15
|
export declare const imageExtRegex: RegExp;
|
|
8
16
|
export declare const audioExtRegex: RegExp;
|
|
@@ -1,50 +1,56 @@
|
|
|
1
1
|
import type React from 'react';
|
|
2
2
|
import type SendbirdChat from '@sendbird/chat';
|
|
3
|
-
import type { BaseChannel, RestrictedUser, SendbirdError as SBError, User, UserUpdateParams } from '@sendbird/chat';
|
|
3
|
+
import type { BaseChannel, Emoji, EmojiCategory, EmojiContainer, RestrictedUser, SendbirdError as SBError, User, UserUpdateParams } from '@sendbird/chat';
|
|
4
4
|
import type { GroupChannel, GroupChannelCollection, GroupChannelCreateParams, GroupChannelListQuery, GroupChannelModule, GroupChannelUpdateParams, Member, MessageCollection } from '@sendbird/chat/groupChannel';
|
|
5
5
|
import type { ModuleNamespaces, SendableMessage } from '@sendbird/chat/lib/__definition';
|
|
6
|
-
import type { AdminMessage, BaseMessage, FileMessage, FileMessageCreateParams, FileMessageUpdateParams, PreviousMessageListQuery, UserMessage, UserMessageCreateParams, UserMessageUpdateParams } from '@sendbird/chat/message';
|
|
6
|
+
import type { AdminMessage, BaseMessage, FileMessage, FileMessageCreateParams, FileMessageUpdateParams, PreviousMessageListQuery, Reaction, UserMessage, UserMessageCreateParams, UserMessageUpdateParams } from '@sendbird/chat/message';
|
|
7
7
|
import type { OpenChannel, OpenChannelModule } from '@sendbird/chat/openChannel';
|
|
8
|
-
|
|
9
|
-
export declare type FilterByValueType<T extends object, Type> = {
|
|
8
|
+
export type FilterByValueType<T extends object, Type> = {
|
|
10
9
|
[K in keyof T as T[K] extends Type ? K : never]: T[K];
|
|
11
10
|
};
|
|
12
|
-
export
|
|
13
|
-
export
|
|
14
|
-
export
|
|
11
|
+
export type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
12
|
+
export type OmittedValues<T, K extends keyof T> = Omit<T, K>[keyof Omit<T, K>];
|
|
13
|
+
export type PartialDeep<T> = T extends object ? T extends Function ? T : {
|
|
15
14
|
[P in keyof T]?: PartialDeep<T[P]>;
|
|
16
15
|
} : T;
|
|
17
|
-
export
|
|
16
|
+
export type PartialNullable<T> = {
|
|
18
17
|
[P in keyof T]?: T[P] | null;
|
|
19
18
|
};
|
|
20
|
-
export
|
|
21
|
-
export
|
|
22
|
-
export
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
export
|
|
26
|
-
export
|
|
27
|
-
export
|
|
28
|
-
export
|
|
29
|
-
export
|
|
30
|
-
export
|
|
31
|
-
export
|
|
32
|
-
export
|
|
33
|
-
export
|
|
34
|
-
export
|
|
35
|
-
export
|
|
36
|
-
export
|
|
37
|
-
export
|
|
38
|
-
export
|
|
39
|
-
export
|
|
40
|
-
export
|
|
41
|
-
export
|
|
42
|
-
export
|
|
43
|
-
export
|
|
44
|
-
export
|
|
45
|
-
export
|
|
46
|
-
export
|
|
47
|
-
export
|
|
19
|
+
export type Optional<T> = T | undefined;
|
|
20
|
+
export type ContextValue<T extends React.Context<any>> = T extends React.Context<infer V> ? V : never;
|
|
21
|
+
export interface UserStruct {
|
|
22
|
+
userId: string;
|
|
23
|
+
}
|
|
24
|
+
export type SendbirdChatSDK = SendbirdChat & ModuleNamespaces<[GroupChannelModule, OpenChannelModule]>;
|
|
25
|
+
export type SendbirdMessage = BaseMessage | FileMessage | UserMessage | AdminMessage | SendableMessage;
|
|
26
|
+
export type SendbirdChannel = BaseChannel | GroupChannel | OpenChannel;
|
|
27
|
+
export type SendbirdUserMessage = UserMessage;
|
|
28
|
+
export type SendbirdFileMessage = FileMessage;
|
|
29
|
+
export type SendbirdAdminMessage = AdminMessage;
|
|
30
|
+
export type SendbirdBaseMessage = BaseMessage;
|
|
31
|
+
export type SendbirdSendableMessage = SendableMessage;
|
|
32
|
+
export type SendbirdFileMessageCreateParams = FileMessageCreateParams;
|
|
33
|
+
export type SendbirdFileMessageUpdateParams = FileMessageUpdateParams;
|
|
34
|
+
export type SendbirdUserMessageCreateParams = UserMessageCreateParams;
|
|
35
|
+
export type SendbirdUserMessageUpdateParams = UserMessageUpdateParams;
|
|
36
|
+
export type SendbirdGroupChannelCreateParams = GroupChannelCreateParams;
|
|
37
|
+
export type SendbirdGroupChannelUpdateParams = GroupChannelUpdateParams;
|
|
38
|
+
export type SendbirdUserUpdateParams = UserUpdateParams;
|
|
39
|
+
export type SendbirdUser = User;
|
|
40
|
+
export type SendbirdRestrictedUser = RestrictedUser;
|
|
41
|
+
export type SendbirdMember = Member;
|
|
42
|
+
export type SendbirdGroupChannel = GroupChannel;
|
|
43
|
+
export type SendbirdBaseChannel = BaseChannel;
|
|
44
|
+
export type SendbirdOpenChannel = OpenChannel;
|
|
45
|
+
export type SendbirdReaction = Reaction;
|
|
46
|
+
export type SendbirdEmoji = Emoji;
|
|
47
|
+
export type SendbirdEmojiCategory = EmojiCategory;
|
|
48
|
+
export type SendbirdEmojiContainer = EmojiContainer;
|
|
49
|
+
export type SendbirdGroupChannelCollection = GroupChannelCollection;
|
|
50
|
+
export type SendbirdGroupChannelListQuery = GroupChannelListQuery;
|
|
51
|
+
export type SendbirdMessageCollection = MessageCollection;
|
|
52
|
+
export type SendbirdPreviousMessageListQuery = PreviousMessageListQuery;
|
|
53
|
+
export type SendbirdError = SBError;
|
|
48
54
|
export interface SendbirdDataPayload {
|
|
49
55
|
app_id: string;
|
|
50
56
|
audience_type: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Locale } from 'date-fns';
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
type TruncateMode = 'head' | 'mid' | 'tail';
|
|
3
|
+
type TruncateOption = {
|
|
4
4
|
mode: TruncateMode;
|
|
5
5
|
maxLen: number;
|
|
6
6
|
separator: string;
|
|
@@ -16,14 +16,15 @@ declare type TruncateOption = {
|
|
|
16
16
|
* */
|
|
17
17
|
export declare const truncate: (str: string, opts?: Partial<TruncateOption>) => string;
|
|
18
18
|
/**
|
|
19
|
-
*
|
|
19
|
+
* Count truncate util
|
|
20
20
|
* If count exceed the limit, it comes in the form of "MAX+"
|
|
21
21
|
*
|
|
22
22
|
* @param {number} count
|
|
23
23
|
* @param {number} MAX default 99
|
|
24
|
+
* @param {string} MAX_SUFFIX default +
|
|
24
25
|
* @returns {string}
|
|
25
26
|
* */
|
|
26
|
-
export declare const
|
|
27
|
+
export declare const truncatedCount: (count: number, MAX?: number, MAX_SUFFIX?: string) => string;
|
|
27
28
|
/**
|
|
28
29
|
* Messages date separator format
|
|
29
30
|
*
|
|
@@ -31,7 +32,7 @@ export declare const truncatedBadgeCount: (count: number, MAX?: number) => strin
|
|
|
31
32
|
* @param {Locale} [locale]
|
|
32
33
|
* @returns {string}
|
|
33
34
|
* */
|
|
34
|
-
export declare const
|
|
35
|
+
export declare const getDateSeparatorFormat: (date: Date, locale?: Locale) => string;
|
|
35
36
|
/**
|
|
36
37
|
* Message time format
|
|
37
38
|
*
|
|
@@ -39,5 +40,5 @@ export declare const dateSeparator: (date: Date, locale?: Locale) => string;
|
|
|
39
40
|
* @param {Locale} [locale]
|
|
40
41
|
* @returns {string}
|
|
41
42
|
* */
|
|
42
|
-
export declare const
|
|
43
|
+
export declare const getMessageTimeFormat: (date: Date, locale?: Locale) => string;
|
|
43
44
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sendbird/uikit-utils",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"description": "UIKit utilities",
|
|
5
5
|
"main": "lib/commonjs/index",
|
|
6
6
|
"module": "lib/module/index",
|
|
@@ -43,10 +43,11 @@
|
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@types/react": "*",
|
|
46
|
+
"@types/react-native": "*",
|
|
46
47
|
"react": "17.0.2",
|
|
47
48
|
"react-native": "0.67.4",
|
|
48
49
|
"react-native-builder-bob": "^0.18.0",
|
|
49
|
-
"typescript": "
|
|
50
|
+
"typescript": "4.9.4"
|
|
50
51
|
},
|
|
51
52
|
"peerDependencies": {
|
|
52
53
|
"@sendbird/chat": "^4.0.13",
|
|
@@ -76,5 +77,5 @@
|
|
|
76
77
|
"readmeFile": "./README.md",
|
|
77
78
|
"displayName": "@sendbird/uikit-utils"
|
|
78
79
|
},
|
|
79
|
-
"gitHead": "
|
|
80
|
+
"gitHead": "a9bf41fd7919436db99f6cc3bacd0f8d791b7729"
|
|
80
81
|
}
|
package/src/hooks/index.ts
CHANGED
|
@@ -56,6 +56,17 @@ export const useIsMountedRef = () => {
|
|
|
56
56
|
return isMounted;
|
|
57
57
|
};
|
|
58
58
|
|
|
59
|
+
export const useIsFirstMount = () => {
|
|
60
|
+
const isFirstMount = useRef(true);
|
|
61
|
+
|
|
62
|
+
if (isFirstMount.current) {
|
|
63
|
+
isFirstMount.current = false;
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return isFirstMount.current;
|
|
68
|
+
};
|
|
69
|
+
|
|
59
70
|
export const useFreshCallback = <T extends (...args: any[]) => any>(callback: T): T => {
|
|
60
71
|
const ref = useRef<T>(callback);
|
|
61
72
|
ref.current = callback;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { useEffect, useMemo, useRef } from 'react';
|
|
2
|
+
import { AppState, AppStateEvent, AppStateStatus } from 'react-native';
|
|
3
|
+
import { EdgeInsets, useSafeAreaInsets } from 'react-native-safe-area-context';
|
|
4
|
+
|
|
5
|
+
type EdgePaddingMap = {
|
|
6
|
+
left: 'paddingLeft';
|
|
7
|
+
right: 'paddingRight';
|
|
8
|
+
top: 'paddingTop';
|
|
9
|
+
bottom: 'paddingBottom';
|
|
10
|
+
};
|
|
11
|
+
const edgePaddingMap: EdgePaddingMap = {
|
|
12
|
+
left: 'paddingLeft',
|
|
13
|
+
right: 'paddingRight',
|
|
14
|
+
top: 'paddingTop',
|
|
15
|
+
bottom: 'paddingBottom',
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const useSafeAreaPadding = <
|
|
19
|
+
T extends keyof EdgeInsets,
|
|
20
|
+
Result extends { [key in EdgePaddingMap[T]]: EdgeInsets[T] },
|
|
21
|
+
>(
|
|
22
|
+
edges: T[],
|
|
23
|
+
): Result => {
|
|
24
|
+
const safeAreaInsets = useSafeAreaInsets();
|
|
25
|
+
return useMemo(() => {
|
|
26
|
+
return edges.reduce((map, edge) => {
|
|
27
|
+
const paddingKey = edgePaddingMap[edge];
|
|
28
|
+
map[paddingKey] = safeAreaInsets[edge];
|
|
29
|
+
return map;
|
|
30
|
+
}, {} as { [key in EdgePaddingMap[T]]: EdgeInsets[T] });
|
|
31
|
+
}, edges) as Result;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
type AppStateListener = (status: AppStateStatus) => void;
|
|
35
|
+
|
|
36
|
+
export const useAppState = (type: AppStateEvent, listener: AppStateListener) => {
|
|
37
|
+
const callbackRef = useRef<AppStateListener>(listener);
|
|
38
|
+
callbackRef.current = listener;
|
|
39
|
+
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
const eventListener = (state: AppStateStatus) => callbackRef.current(state);
|
|
42
|
+
const subscriber = AppState.addEventListener(type, eventListener);
|
|
43
|
+
|
|
44
|
+
return () => {
|
|
45
|
+
// @ts-ignore
|
|
46
|
+
if (subscriber?.remove) {
|
|
47
|
+
subscriber.remove();
|
|
48
|
+
}
|
|
49
|
+
// @ts-ignore
|
|
50
|
+
else if (AppState.removeEventListener) {
|
|
51
|
+
// @ts-ignore
|
|
52
|
+
AppState.removeEventListener(type, eventListener);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
}, []);
|
|
56
|
+
};
|