@sendbird/uikit-utils 1.0.0-rc.1
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/LICENSE +21 -0
- package/README.md +9 -0
- 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 +75 -0
- package/src/hooks/index.ts +65 -0
- package/src/index.ts +57 -0
- package/src/sendbird/attrs.ts +44 -0
- package/src/sendbird/channel.ts +37 -0
- package/src/sendbird/message.ts +101 -0
- package/src/shared/arrayToMap.ts +70 -0
- package/src/shared/conditionChaining.ts +6 -0
- package/src/shared/logger.ts +59 -0
- package/src/shared/pubsub.ts +42 -0
- package/src/shared/regex.ts +74 -0
- package/src/types.ts +101 -0
- package/src/ui-format/common.ts +73 -0
- package/src/ui-format/groupChannel.ts +47 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.arrayToMapWithGetter = arrayToMapWithGetter;
|
|
7
|
+
exports.default = arrayToMap;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Convert Array of the object to Object
|
|
11
|
+
* @param {object[]} arr
|
|
12
|
+
* @param {keyof object} selector
|
|
13
|
+
* @param {keyof object} [fallbackSelector]
|
|
14
|
+
* @param {boolean} [combine]
|
|
15
|
+
* @returns {Record<keyof object, object>}
|
|
16
|
+
* @example
|
|
17
|
+
* ```
|
|
18
|
+
* const arr = [{name: 'john'}, {name: 'chris'}, {name: 'sravan'}, {name: 'hoon'}];
|
|
19
|
+
* const obj = arrayToMap(arr, 'name');
|
|
20
|
+
*
|
|
21
|
+
* console.log(obj);
|
|
22
|
+
* // {
|
|
23
|
+
* // 'john': {name: 'john'},
|
|
24
|
+
* // 'chris': {name: 'chris'},
|
|
25
|
+
* // 'sravan': {name: 'sravan'},
|
|
26
|
+
* // 'hoon': {name: 'hoon'}
|
|
27
|
+
* // }
|
|
28
|
+
* ```
|
|
29
|
+
* */
|
|
30
|
+
function arrayToMap(arr, selector, fallbackSelector, combine) {
|
|
31
|
+
return arr.reduce((accum, curr) => {
|
|
32
|
+
if (combine && fallbackSelector) {
|
|
33
|
+
const _key = curr[selector] + curr[fallbackSelector];
|
|
34
|
+
|
|
35
|
+
accum[_key] = curr;
|
|
36
|
+
} else {
|
|
37
|
+
const _key = curr[selector] || curr[fallbackSelector];
|
|
38
|
+
|
|
39
|
+
accum[_key] = curr;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return accum;
|
|
43
|
+
}, {});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function arrayToMapWithGetter(arr, getSelector) {
|
|
47
|
+
return arr.reduce((accum, curr) => {
|
|
48
|
+
const _key = getSelector(curr);
|
|
49
|
+
|
|
50
|
+
accum[_key] = curr;
|
|
51
|
+
return accum;
|
|
52
|
+
}, {});
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=arrayToMap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["arrayToMap","arr","selector","fallbackSelector","combine","reduce","accum","curr","_key","arrayToMapWithGetter","getSelector"],"sources":["arrayToMap.ts"],"sourcesContent":["import type { FilterByValueType } from '../types';\n\nexport default function arrayToMap<T extends Record<K, unknown>, K extends keyof T = keyof T>(\n arr: T[],\n selector: keyof FilterByValueType<T, string | number>,\n): Record<string, T>;\n\nexport default function arrayToMap<T extends Record<K, unknown>, K extends keyof T = keyof T>(\n arr: T[],\n selector: string,\n fallbackSelector: K,\n): Record<string, T>;\n\nexport default function arrayToMap<T extends Record<K, unknown>, K extends keyof T = keyof T>(\n arr: T[],\n selector: string,\n selector2: string,\n combineKey: true,\n): Record<string, T>;\n\n/**\n * Convert Array of the object to Object\n * @param {object[]} arr\n * @param {keyof object} selector\n * @param {keyof object} [fallbackSelector]\n * @param {boolean} [combine]\n * @returns {Record<keyof object, object>}\n * @example\n * ```\n * const arr = [{name: 'john'}, {name: 'chris'}, {name: 'sravan'}, {name: 'hoon'}];\n * const obj = arrayToMap(arr, 'name');\n *\n * console.log(obj);\n * // {\n * // 'john': {name: 'john'},\n * // 'chris': {name: 'chris'},\n * // 'sravan': {name: 'sravan'},\n * // 'hoon': {name: 'hoon'}\n * // }\n * ```\n * */\nexport default function arrayToMap<T extends Record<K, unknown>, K extends keyof T = keyof T>(\n arr: T[],\n selector: K,\n fallbackSelector?: K,\n combine?: boolean,\n) {\n return arr.reduce((accum, curr) => {\n if (combine && fallbackSelector) {\n const _key = curr[selector] + (curr[fallbackSelector] as string);\n accum[_key] = curr;\n } else {\n const _key = (curr[selector] || curr[fallbackSelector as K]) as string;\n accum[_key] = curr;\n }\n\n return accum;\n }, {} as Record<string, T>);\n}\n\nexport function arrayToMapWithGetter<T extends Record<K, unknown>, K extends keyof T = keyof T>(\n arr: T[],\n getSelector: (item: T) => string,\n) {\n return arr.reduce((accum, curr) => {\n const _key = getSelector(curr);\n accum[_key] = curr;\n return accum;\n }, {} as Record<string, T>);\n}\n"],"mappings":";;;;;;;;AAoBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,UAAT,CACbC,GADa,EAEbC,QAFa,EAGbC,gBAHa,EAIbC,OAJa,EAKb;EACA,OAAOH,GAAG,CAACI,MAAJ,CAAW,CAACC,KAAD,EAAQC,IAAR,KAAiB;IACjC,IAAIH,OAAO,IAAID,gBAAf,EAAiC;MAC/B,MAAMK,IAAI,GAAGD,IAAI,CAACL,QAAD,CAAJ,GAAkBK,IAAI,CAACJ,gBAAD,CAAnC;;MACAG,KAAK,CAACE,IAAD,CAAL,GAAcD,IAAd;IACD,CAHD,MAGO;MACL,MAAMC,IAAI,GAAID,IAAI,CAACL,QAAD,CAAJ,IAAkBK,IAAI,CAACJ,gBAAD,CAApC;;MACAG,KAAK,CAACE,IAAD,CAAL,GAAcD,IAAd;IACD;;IAED,OAAOD,KAAP;EACD,CAVM,EAUJ,EAVI,CAAP;AAWD;;AAEM,SAASG,oBAAT,CACLR,GADK,EAELS,WAFK,EAGL;EACA,OAAOT,GAAG,CAACI,MAAJ,CAAW,CAACC,KAAD,EAAQC,IAAR,KAAiB;IACjC,MAAMC,IAAI,GAAGE,WAAW,CAACH,IAAD,CAAxB;;IACAD,KAAK,CAACE,IAAD,CAAL,GAAcD,IAAd;IACA,OAAOD,KAAP;EACD,CAJM,EAIJ,EAJI,CAAP;AAKD"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
const conditionChaining = (conditions, values) => {
|
|
9
|
+
const idx = conditions.findIndex(state => Boolean(state));
|
|
10
|
+
return idx > -1 ? values[idx] : values[values.length - 1];
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
var _default = conditionChaining;
|
|
14
|
+
exports.default = _default;
|
|
15
|
+
//# sourceMappingURL=conditionChaining.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["conditionChaining","conditions","values","idx","findIndex","state","Boolean","length"],"sources":["conditionChaining.ts"],"sourcesContent":["const conditionChaining = <T, V>(conditions: T[], values: V[]) => {\n const idx = conditions.findIndex((state) => Boolean(state));\n return idx > -1 ? values[idx] : values[values.length - 1];\n};\n\nexport default conditionChaining;\n"],"mappings":";;;;;;;AAAA,MAAMA,iBAAiB,GAAG,CAAOC,UAAP,EAAwBC,MAAxB,KAAwC;EAChE,MAAMC,GAAG,GAAGF,UAAU,CAACG,SAAX,CAAsBC,KAAD,IAAWC,OAAO,CAACD,KAAD,CAAvC,CAAZ;EACA,OAAOF,GAAG,GAAG,CAAC,CAAP,GAAWD,MAAM,CAACC,GAAD,CAAjB,GAAyBD,MAAM,CAACA,MAAM,CAACK,MAAP,GAAgB,CAAjB,CAAtC;AACD,CAHD;;eAKeP,iB"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Logger = void 0;
|
|
7
|
+
|
|
8
|
+
/* eslint-disable no-console */
|
|
9
|
+
const LogLevelEnum = {
|
|
10
|
+
'none': 0,
|
|
11
|
+
'log': 1,
|
|
12
|
+
'error': 2,
|
|
13
|
+
'warn': 3,
|
|
14
|
+
'info': 4,
|
|
15
|
+
'debug': 5
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const createLogger = function () {
|
|
19
|
+
let level = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'warn';
|
|
20
|
+
let _logLevel = level;
|
|
21
|
+
let _title = '[UIKit]';
|
|
22
|
+
return {
|
|
23
|
+
setTitle(title) {
|
|
24
|
+
_title = title;
|
|
25
|
+
},
|
|
26
|
+
|
|
27
|
+
setLogLevel(lv) {
|
|
28
|
+
_logLevel = lv;
|
|
29
|
+
},
|
|
30
|
+
|
|
31
|
+
getLogLevel() {
|
|
32
|
+
return _logLevel;
|
|
33
|
+
},
|
|
34
|
+
|
|
35
|
+
log() {
|
|
36
|
+
if (LogLevelEnum[_logLevel] < LogLevelEnum.log) return LogLevelEnum.none;
|
|
37
|
+
|
|
38
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
39
|
+
args[_key] = arguments[_key];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
console.log(_title, ...args);
|
|
43
|
+
return LogLevelEnum[_logLevel];
|
|
44
|
+
},
|
|
45
|
+
|
|
46
|
+
error() {
|
|
47
|
+
if (LogLevelEnum[_logLevel] < LogLevelEnum.error) return LogLevelEnum.none;
|
|
48
|
+
|
|
49
|
+
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
50
|
+
args[_key2] = arguments[_key2];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
console.error(_title, ...args);
|
|
54
|
+
return LogLevelEnum[_logLevel];
|
|
55
|
+
},
|
|
56
|
+
|
|
57
|
+
warn() {
|
|
58
|
+
if (LogLevelEnum[_logLevel] < LogLevelEnum.warn) return LogLevelEnum.none;
|
|
59
|
+
|
|
60
|
+
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
61
|
+
args[_key3] = arguments[_key3];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
console.warn(_title, ...args);
|
|
65
|
+
return LogLevelEnum[_logLevel];
|
|
66
|
+
},
|
|
67
|
+
|
|
68
|
+
info() {
|
|
69
|
+
if (LogLevelEnum[_logLevel] < LogLevelEnum.info) return LogLevelEnum.none;
|
|
70
|
+
|
|
71
|
+
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
|
72
|
+
args[_key4] = arguments[_key4];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
console.info(_title, ...args);
|
|
76
|
+
return LogLevelEnum[_logLevel];
|
|
77
|
+
},
|
|
78
|
+
|
|
79
|
+
debug() {
|
|
80
|
+
if (LogLevelEnum[_logLevel] < LogLevelEnum.debug) return LogLevelEnum.none;
|
|
81
|
+
|
|
82
|
+
for (var _len5 = arguments.length, args = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
|
|
83
|
+
args[_key5] = arguments[_key5];
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
console.log(_title, ...args);
|
|
87
|
+
return LogLevelEnum[_logLevel];
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const Logger = { ...createLogger(),
|
|
94
|
+
LogLevelEnum,
|
|
95
|
+
create: createLogger
|
|
96
|
+
};
|
|
97
|
+
exports.Logger = Logger;
|
|
98
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["LogLevelEnum","createLogger","level","_logLevel","_title","setTitle","title","setLogLevel","lv","getLogLevel","log","none","args","console","error","warn","info","debug","Logger","create"],"sources":["logger.ts"],"sourcesContent":["/* eslint-disable no-console */\n\nconst LogLevelEnum = {\n 'none': 0,\n 'log': 1,\n 'error': 2,\n 'warn': 3,\n 'info': 4,\n 'debug': 5,\n};\ntype LogLevel = keyof typeof LogLevelEnum;\n\nconst createLogger = (level: LogLevel = 'warn') => {\n let _logLevel = level;\n let _title = '[UIKit]';\n\n return {\n setTitle(title: string) {\n _title = title;\n },\n setLogLevel(lv: LogLevel) {\n _logLevel = lv;\n },\n getLogLevel() {\n return _logLevel;\n },\n log(...args: unknown[]) {\n if (LogLevelEnum[_logLevel] < LogLevelEnum.log) return LogLevelEnum.none;\n console.log(_title, ...args);\n return LogLevelEnum[_logLevel];\n },\n error(...args: unknown[]) {\n if (LogLevelEnum[_logLevel] < LogLevelEnum.error) return LogLevelEnum.none;\n console.error(_title, ...args);\n return LogLevelEnum[_logLevel];\n },\n warn(...args: unknown[]) {\n if (LogLevelEnum[_logLevel] < LogLevelEnum.warn) return LogLevelEnum.none;\n console.warn(_title, ...args);\n return LogLevelEnum[_logLevel];\n },\n info(...args: unknown[]) {\n if (LogLevelEnum[_logLevel] < LogLevelEnum.info) return LogLevelEnum.none;\n console.info(_title, ...args);\n return LogLevelEnum[_logLevel];\n },\n debug(...args: unknown[]) {\n if (LogLevelEnum[_logLevel] < LogLevelEnum.debug) return LogLevelEnum.none;\n console.log(_title, ...args);\n return LogLevelEnum[_logLevel];\n },\n };\n};\n\nexport const Logger = {\n ...createLogger(),\n LogLevelEnum,\n create: createLogger,\n};\n"],"mappings":";;;;;;;AAAA;AAEA,MAAMA,YAAY,GAAG;EACnB,QAAQ,CADW;EAEnB,OAAO,CAFY;EAGnB,SAAS,CAHU;EAInB,QAAQ,CAJW;EAKnB,QAAQ,CALW;EAMnB,SAAS;AANU,CAArB;;AAUA,MAAMC,YAAY,GAAG,YAA8B;EAAA,IAA7BC,KAA6B,uEAAX,MAAW;EACjD,IAAIC,SAAS,GAAGD,KAAhB;EACA,IAAIE,MAAM,GAAG,SAAb;EAEA,OAAO;IACLC,QAAQ,CAACC,KAAD,EAAgB;MACtBF,MAAM,GAAGE,KAAT;IACD,CAHI;;IAILC,WAAW,CAACC,EAAD,EAAe;MACxBL,SAAS,GAAGK,EAAZ;IACD,CANI;;IAOLC,WAAW,GAAG;MACZ,OAAON,SAAP;IACD,CATI;;IAULO,GAAG,GAAqB;MACtB,IAAIV,YAAY,CAACG,SAAD,CAAZ,GAA0BH,YAAY,CAACU,GAA3C,EAAgD,OAAOV,YAAY,CAAC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EAAoB,GAAGQ,IAAvB;MACA,OAAOZ,YAAY,CAACG,SAAD,CAAnB;IACD;;EAlCI,CAAP;AAoCD,CAxCD;;AA0CO,MAAMe,MAAM,GAAG,EACpB,GAAGjB,YAAY,EADK;EAEpBD,YAFoB;EAGpBmB,MAAM,EAAElB;AAHY,CAAf"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createPubSub = void 0;
|
|
7
|
+
|
|
8
|
+
const createPubSub = function () {
|
|
9
|
+
let label = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'pubsub';
|
|
10
|
+
const eventPool = {};
|
|
11
|
+
|
|
12
|
+
const getSubscribeListenerPool = event => {
|
|
13
|
+
if (!eventPool[event]) eventPool[event] = {};
|
|
14
|
+
return eventPool[event];
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
return {
|
|
18
|
+
subscribe: function (event, listener) {
|
|
19
|
+
let subscriber = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
|
|
20
|
+
const name = `${label}_${event}_${subscriber}`;
|
|
21
|
+
const id = Symbol(name);
|
|
22
|
+
const subscribeListenerPool = getSubscribeListenerPool(event);
|
|
23
|
+
subscribeListenerPool[id] = listener;
|
|
24
|
+
return () => {
|
|
25
|
+
delete getSubscribeListenerPool(event)[id];
|
|
26
|
+
};
|
|
27
|
+
},
|
|
28
|
+
publish: function (event) {
|
|
29
|
+
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
30
|
+
args[_key - 1] = arguments[_key];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const subscribeListenerPool = getSubscribeListenerPool(event);
|
|
34
|
+
const ids = Object.getOwnPropertySymbols(subscribeListenerPool);
|
|
35
|
+
setTimeout(() => {
|
|
36
|
+
ids.forEach(id => {
|
|
37
|
+
const listener = subscribeListenerPool[id];
|
|
38
|
+
|
|
39
|
+
try {
|
|
40
|
+
listener(...args);
|
|
41
|
+
} catch (err) {
|
|
42
|
+
if (listener.onError) {
|
|
43
|
+
err.stack += `\npubsub error: ${id.description}`;
|
|
44
|
+
listener.onError(err);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}, 0);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
exports.createPubSub = createPubSub;
|
|
54
|
+
//# sourceMappingURL=pubsub.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createPubSub","label","eventPool","getSubscribeListenerPool","event","subscribe","listener","subscriber","name","id","Symbol","subscribeListenerPool","publish","args","ids","Object","getOwnPropertySymbols","setTimeout","forEach","err","onError","stack","description"],"sources":["pubsub.ts"],"sourcesContent":["export type SubscribeListener = ((...args: unknown[]) => void) & { onError?: (error: unknown) => void };\nexport type SubscribeListenerPool = Record<symbol, SubscribeListener>;\n\nexport const createPubSub = (label = 'pubsub') => {\n const eventPool: Record<string, SubscribeListenerPool> = {};\n\n const getSubscribeListenerPool = (event: string) => {\n if (!eventPool[event]) eventPool[event] = {};\n return eventPool[event];\n };\n\n return {\n subscribe: (event: string, listener: SubscribeListener, subscriber = '') => {\n const name = `${label}_${event}_${subscriber}`;\n const id = Symbol(name);\n\n const subscribeListenerPool = getSubscribeListenerPool(event);\n subscribeListenerPool[id] = listener;\n\n return () => {\n delete getSubscribeListenerPool(event)[id];\n };\n },\n publish: (event: string, ...args: unknown[]) => {\n const subscribeListenerPool = getSubscribeListenerPool(event);\n const ids = Object.getOwnPropertySymbols(subscribeListenerPool);\n setTimeout(() => {\n ids.forEach((id) => {\n const listener = subscribeListenerPool[id];\n try {\n listener(...args);\n } catch (err: unknown) {\n if (listener.onError) {\n (err as Error).stack += `\\npubsub error: ${id.description}`;\n listener.onError(err);\n }\n }\n });\n },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,IAAyB,mBAAkBZ,EAAE,CAACa,WAAY,EAA1D;cACAhB,QAAQ,CAACc,OAAT,CAAiBD,GAAjB;YACD;UACF;QACF,CAVD;MAWD,CAZS,EAYP,CAZO,CAAV;IAaD;EA5BI,CAAP;AA8BD,CAtCM"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.emailRegex = exports.audioExtRegex = void 0;
|
|
7
|
+
exports.getFileExtension = getFileExtension;
|
|
8
|
+
exports.videoExtRegex = exports.urlRegexStrict = exports.urlRegexRough = exports.replaceUrlAsComponents = exports.phoneRegex = exports.newLineRegex = exports.imageExtRegex = exports.getFileType = void 0;
|
|
9
|
+
|
|
10
|
+
// For iOS 12 backwards compatibility
|
|
11
|
+
require('string.prototype.matchall').shim();
|
|
12
|
+
|
|
13
|
+
const urlRegexStrict = /(https?:\/\/|www\.)[-a-zA-Z0-9@:%._+~#=]{1,256}\.(xn--)?[a-z0-9-]{2,20}\b([-a-zA-Z0-9@:%_+[\],.~#?&/=]*[-a-zA-Z0-9@:%_+\]~#?&/=])*/g;
|
|
14
|
+
exports.urlRegexStrict = urlRegexStrict;
|
|
15
|
+
const urlRegexRough = /(https?:\/\/|www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)/g;
|
|
16
|
+
exports.urlRegexRough = urlRegexRough;
|
|
17
|
+
const phoneRegex = /[+]?[(]?[0-9]{3}[)]?[-\s.]?[0-9]{3}[-\s.]?[0-9]{4,7}/;
|
|
18
|
+
exports.phoneRegex = phoneRegex;
|
|
19
|
+
const emailRegex = /\S+@\S+\.\S+/;
|
|
20
|
+
exports.emailRegex = emailRegex;
|
|
21
|
+
const newLineRegex = /\r\n|\r|\n/g; // const cases = [
|
|
22
|
+
// {
|
|
23
|
+
// type: 'urlStrict',
|
|
24
|
+
// regex: urlRegexStrict,
|
|
25
|
+
// },
|
|
26
|
+
// {
|
|
27
|
+
// type: 'urlRough',
|
|
28
|
+
// regex: urlRegexStrict,
|
|
29
|
+
// },
|
|
30
|
+
// {
|
|
31
|
+
// type: 'email',
|
|
32
|
+
// regex: emailRegex,
|
|
33
|
+
// },
|
|
34
|
+
// {
|
|
35
|
+
// type: 'phone',
|
|
36
|
+
// regex: urlRegexStrict,
|
|
37
|
+
// },
|
|
38
|
+
// ];
|
|
39
|
+
|
|
40
|
+
exports.newLineRegex = newLineRegex;
|
|
41
|
+
|
|
42
|
+
const replaceUrlAsComponents = (originText, replacer, strict) => {
|
|
43
|
+
const matches = [...originText.matchAll(strict ? urlRegexStrict : urlRegexRough)];
|
|
44
|
+
const founds = matches.map(value => {
|
|
45
|
+
const text = value[0];
|
|
46
|
+
const start = value.index ?? 0;
|
|
47
|
+
const end = start + text.length;
|
|
48
|
+
return {
|
|
49
|
+
text,
|
|
50
|
+
start,
|
|
51
|
+
end
|
|
52
|
+
};
|
|
53
|
+
});
|
|
54
|
+
const items = [originText];
|
|
55
|
+
let cursor = 0;
|
|
56
|
+
founds.forEach(_ref => {
|
|
57
|
+
let {
|
|
58
|
+
text,
|
|
59
|
+
start,
|
|
60
|
+
end
|
|
61
|
+
} = _ref;
|
|
62
|
+
const restText = items.pop();
|
|
63
|
+
const head = restText.slice(0, start - cursor);
|
|
64
|
+
const mid = replacer(text);
|
|
65
|
+
const tail = restText.slice(end - cursor);
|
|
66
|
+
items.push(head, mid, tail);
|
|
67
|
+
cursor = end;
|
|
68
|
+
});
|
|
69
|
+
return items;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
exports.replaceUrlAsComponents = replaceUrlAsComponents;
|
|
73
|
+
const imageExtRegex = /jpeg|jpg|png|webp|gif/i;
|
|
74
|
+
exports.imageExtRegex = imageExtRegex;
|
|
75
|
+
const audioExtRegex = /3gp|aac|aax|act|aiff|flac|gsm|m4a|m4b|m4p|tta|wma|mp3|webm|wav/i;
|
|
76
|
+
exports.audioExtRegex = audioExtRegex;
|
|
77
|
+
const videoExtRegex = /mov|vod|mp4|avi/i;
|
|
78
|
+
exports.videoExtRegex = videoExtRegex;
|
|
79
|
+
|
|
80
|
+
const getFileType = extOrType => {
|
|
81
|
+
if (extOrType.indexOf('/') > -1) {
|
|
82
|
+
const type = extOrType.split('/')[0];
|
|
83
|
+
if (type === 'video') return 'video';
|
|
84
|
+
if (type === 'audio') return 'audio';
|
|
85
|
+
if (type === 'image') return 'image';
|
|
86
|
+
return 'file';
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (extOrType.match(imageExtRegex)) return 'image';
|
|
90
|
+
if (extOrType.match(audioExtRegex)) return 'audio';
|
|
91
|
+
if (extOrType.match(videoExtRegex)) return 'video';
|
|
92
|
+
return 'file';
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
exports.getFileType = getFileType;
|
|
96
|
+
|
|
97
|
+
function getFileExtension(filePath) {
|
|
98
|
+
const idx = filePath.lastIndexOf('.');
|
|
99
|
+
if (idx === -1) return '';
|
|
100
|
+
return filePath.slice(idx - filePath.length).toLowerCase();
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=regex.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["require","shim","urlRegexStrict","urlRegexRough","phoneRegex","emailRegex","newLineRegex","replaceUrlAsComponents","originText","replacer","strict","matches","matchAll","founds","map","value","text","start","index","end","length","items","cursor","forEach","restText","pop","head","slice","mid","tail","push","imageExtRegex","audioExtRegex","videoExtRegex","getFileType","extOrType","indexOf","type","split","match","getFileExtension","filePath","idx","lastIndexOf","toLowerCase"],"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\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 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}\n"],"mappings":";;;;;;;;;AAAA;AACAA,OAAO,CAAC,2BAAD,CAAP,CAAqCC,IAArC;;AAEO,MAAMC,cAAc,GACzB,qIADK;;AAEA,MAAMC,aAAa,GACxB,uGADK;;AAEA,MAAMC,UAAU,GAAG,sDAAnB;;AACA,MAAMC,UAAU,GAAG,cAAnB;;AACA,MAAMC,YAAY,GAAG,aAArB,C,CAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;AAEO,MAAMC,sBAAsB,GAAG,CAAIC,UAAJ,EAAwBC,QAAxB,EAAsDC,MAAtD,KAA2E;EAC/G,MAAMC,OAAO,GAAG,CAAC,GAAGH,UAAU,CAACI,QAAX,CAAoBF,MAAM,GAAGR,cAAH,GAAoBC,aAA9C,CAAJ,CAAhB;EACA,MAAMU,MAAM,GAAGF,OAAO,CAACG,GAAR,CAAaC,KAAD,IAAW;IACpC,MAAMC,IAAI,GAAGD,KAAK,CAAC,CAAD,CAAlB;IACA,MAAME,KAAK,GAAGF,KAAK,CAACG,KAAN,IAAe,CAA7B;IACA,MAAMC,GAAG,GAAGF,KAAK,GAAGD,IAAI,CAACI,MAAzB;IACA,OAAO;MAAEJ,IAAF;MAAQC,KAAR;MAAeE;IAAf,CAAP;EACD,CALc,CAAf;EAOA,MAAME,KAAwB,GAAG,CAACb,UAAD,CAAjC;EACA,IAAIc,MAAM,GAAG,CAAb;EACAT,MAAM,CAACU,OAAP,CAAe,QAA0B;IAAA,IAAzB;MAAEP,IAAF;MAAQC,KAAR;MAAeE;IAAf,CAAyB;IACvC,MAAMK,QAAQ,GAAGH,KAAK,CAACI,GAAN,EAAjB;IACA,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AP;EAChB,OAAOD,QAAQ,CAACd,KAAT,CAAee,GAAG,GAAGD,QAAQ,CAACrB,MAA9B,EAAsCwB,WAAtC,EAAP;AACD"}
|
|
@@ -0,0 +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';\nimport type Sendbird from 'sendbird';\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\n// for v4 migration\nexport type SendbirdChatSDK = Sendbird.SendBirdInstance;\nexport type SendbirdMessage =\n | Sendbird.BaseMessageInstance\n | Sendbird.FileMessage\n | Sendbird.UserMessage\n | Sendbird.AdminMessage;\nexport type SendbirdChannel = Sendbird.BaseChannel | Sendbird.GroupChannel | Sendbird.OpenChannel;\nexport type SendbirdUserMessage = Sendbird.UserMessage;\nexport type SendbirdFileMessage = Sendbird.FileMessage;\nexport type SendbirdAdminMessage = Sendbird.AdminMessage;\nexport type SendbirdBaseMessage = Sendbird.BaseMessageInstance;\nexport type SendbirdFileMessageParams = Sendbird.FileMessageParams;\nexport type SendbirdUserMessageParams = Sendbird.UserMessageParams;\nexport type SendbirdError = Sendbird.SendBirdError;\nexport type SendbirdGroupChannelParams = Sendbird.GroupChannelParams;\nexport type SendbirdUser = Sendbird.User;\nexport type SendbirdMember = Sendbird.Member;\nexport type SendbirdGroupChannel = Sendbird.GroupChannel;\nexport type SendbirdBaseChannel = Sendbird.BaseChannel;\nexport type SendbirdOpenChannel = Sendbird.OpenChannel;\nexport type SendbirdGroupChannelCollection = Sendbird.GroupChannelCollection;\nexport type SendbirdMessageCollection = Sendbird.MessageCollection;\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":""}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.truncatedBadgeCount = exports.truncate = exports.messageTime = exports.dateSeparator = void 0;
|
|
7
|
+
|
|
8
|
+
var _format = _interopRequireDefault(require("date-fns/format"));
|
|
9
|
+
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
|
|
12
|
+
const defaultOpts = {
|
|
13
|
+
mode: 'mid',
|
|
14
|
+
maxLen: 40,
|
|
15
|
+
separator: '...'
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* String truncate util
|
|
19
|
+
* @param {string} str
|
|
20
|
+
* @param {Object} opts Options for truncate
|
|
21
|
+
* @param {'head' | 'mid' | 'tail'} opts.mode default "mid"
|
|
22
|
+
* @param {number} opts.maxLen default 40
|
|
23
|
+
* @param {string} opts.separator default "..."
|
|
24
|
+
* @returns {string}
|
|
25
|
+
* */
|
|
26
|
+
|
|
27
|
+
const truncate = function (str) {
|
|
28
|
+
let opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultOpts;
|
|
29
|
+
const options = { ...defaultOpts,
|
|
30
|
+
...opts
|
|
31
|
+
};
|
|
32
|
+
const {
|
|
33
|
+
maxLen,
|
|
34
|
+
mode,
|
|
35
|
+
separator
|
|
36
|
+
} = options;
|
|
37
|
+
if (str.length <= maxLen) return str;
|
|
38
|
+
|
|
39
|
+
if (mode === 'head') {
|
|
40
|
+
return separator + str.slice(-maxLen);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (mode === 'mid') {
|
|
44
|
+
const lead = Math.ceil(maxLen / 2);
|
|
45
|
+
const trail = Math.floor(maxLen / 2);
|
|
46
|
+
return str.slice(0, lead) + separator + str.slice(-trail);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (mode === 'tail') {
|
|
50
|
+
return str.slice(0, maxLen) + separator;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
throw new Error('Invalid truncate mode: ' + mode);
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Badge count truncate util
|
|
57
|
+
* If count exceed the limit, it comes in the form of "MAX+"
|
|
58
|
+
*
|
|
59
|
+
* @param {number} count
|
|
60
|
+
* @param {number} MAX default 99
|
|
61
|
+
* @returns {string}
|
|
62
|
+
* */
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
exports.truncate = truncate;
|
|
66
|
+
|
|
67
|
+
const truncatedBadgeCount = function (count) {
|
|
68
|
+
let MAX = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 99;
|
|
69
|
+
if (count >= MAX) return `${MAX}+`;
|
|
70
|
+
return `${count}`;
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Messages date separator format
|
|
74
|
+
*
|
|
75
|
+
* @param {Date} date
|
|
76
|
+
* @param {Locale} [locale]
|
|
77
|
+
* @returns {string}
|
|
78
|
+
* */
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
exports.truncatedBadgeCount = truncatedBadgeCount;
|
|
82
|
+
|
|
83
|
+
const dateSeparator = (date, locale) => {
|
|
84
|
+
return (0, _format.default)(date, 'E, LLL dd', {
|
|
85
|
+
locale
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* Message time format
|
|
90
|
+
*
|
|
91
|
+
* @param {Date} date
|
|
92
|
+
* @param {Locale} [locale]
|
|
93
|
+
* @returns {string}
|
|
94
|
+
* */
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
exports.dateSeparator = dateSeparator;
|
|
98
|
+
|
|
99
|
+
const messageTime = (date, locale) => {
|
|
100
|
+
return (0, _format.default)(date, 'p', {
|
|
101
|
+
locale
|
|
102
|
+
});
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
exports.messageTime = messageTime;
|
|
106
|
+
//# sourceMappingURL=common.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["defaultOpts","mode","maxLen","separator","truncate","str","opts","options","length","slice","lead","Math","ceil","trail","floor","Error","truncatedBadgeCount","count","MAX","dateSeparator","date","locale","format","messageTime"],"sources":["common.ts"],"sourcesContent":["import type { Locale } from 'date-fns';\nimport format from 'date-fns/format';\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 * Badge 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 * @returns {string}\n * */\nexport const truncatedBadgeCount = (count: number, MAX = 99) => {\n if (count >= MAX) return `${MAX}+`;\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 dateSeparator = (date: Date, locale?: Locale): string => {\n return format(date, 'E, LLL dd', { locale });\n};\n\n/**\n * Message time format\n *\n * @param {Date} date\n * @param {Locale} [locale]\n * @returns {string}\n * */\nexport const messageTime = (date: Date, locale?: Locale): string => {\n return format(date, 'p', { locale });\n};\n"],"mappings":";;;;;;;AACA;;;;AAIA,MAAMA,WAA2B,GAAG;EAAEC,IAAI,EAAE,KAAR;EAAeC,MAAM,EAAE,EAAvB;EAA2BC,SAAS,EAAE;AAAtC,CAApC;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACO,MAAMC,QAAQ,GAAG,UAACC,GAAD,EAAsE;EAAA,IAAxDC,IAAwD,uEAAxBN,WAAwB;EAC5F,MAAMO,OAAO,GAAG,EAAE,GAAGP,WAAL;IAAkB,GAAGM;EAArB,CAAhB;EACA,MAAM;IAAEJ,MAAF;IAAUD,IAAV;IAAgBE;EAAhB,IAA8BI,OAApC;EAEA,IAAIF,GAAG,CAACG,MAAJ,IAAcN,MAAlB,EAA0B,OAAOG,GAAP;;EA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}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getGroupChannelTitle = exports.getGroupChannelPreviewTime = exports.getGroupChannelLastMessage = void 0;
|
|
7
|
+
|
|
8
|
+
var _format = _interopRequireDefault(require("date-fns/format"));
|
|
9
|
+
|
|
10
|
+
var _isToday = _interopRequireDefault(require("date-fns/isToday"));
|
|
11
|
+
|
|
12
|
+
var _isYesterday = _interopRequireDefault(require("date-fns/isYesterday"));
|
|
13
|
+
|
|
14
|
+
var _common = require("./common");
|
|
15
|
+
|
|
16
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
+
|
|
18
|
+
const getGroupChannelTitle = function (currentUserId, channel) {
|
|
19
|
+
let EMPTY_USERNAME = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '(No name)';
|
|
20
|
+
let NO_MEMBERS = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '(No members)';
|
|
21
|
+
let DEFAULT_CHANNEL_NAME = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 'Group Channel';
|
|
22
|
+
if (channel.name !== DEFAULT_CHANNEL_NAME && channel.name !== '') return channel.name;
|
|
23
|
+
if (channel.memberCount === 1) return NO_MEMBERS;
|
|
24
|
+
return channel.members.filter(_ref => {
|
|
25
|
+
let {
|
|
26
|
+
userId
|
|
27
|
+
} = _ref;
|
|
28
|
+
return userId !== currentUserId;
|
|
29
|
+
}).map(_ref2 => {
|
|
30
|
+
let {
|
|
31
|
+
nickname
|
|
32
|
+
} = _ref2;
|
|
33
|
+
return nickname || EMPTY_USERNAME;
|
|
34
|
+
}).join(', ');
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
exports.getGroupChannelTitle = getGroupChannelTitle;
|
|
38
|
+
|
|
39
|
+
const getGroupChannelPreviewTime = (channel, locale) => {
|
|
40
|
+
var _channel$lastMessage;
|
|
41
|
+
|
|
42
|
+
const timestamp = ((_channel$lastMessage = channel.lastMessage) === null || _channel$lastMessage === void 0 ? void 0 : _channel$lastMessage.createdAt) || channel.joinedAt * 1000 || channel.createdAt;
|
|
43
|
+
if ((0, _isToday.default)(timestamp)) return (0, _format.default)(timestamp, 'p', {
|
|
44
|
+
locale
|
|
45
|
+
});
|
|
46
|
+
if ((0, _isYesterday.default)(timestamp)) return 'Yesterday';
|
|
47
|
+
return (0, _format.default)(timestamp, 'MMM dd', {
|
|
48
|
+
locale
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
exports.getGroupChannelPreviewTime = getGroupChannelPreviewTime;
|
|
53
|
+
|
|
54
|
+
const getGroupChannelLastMessage = function (channel) {
|
|
55
|
+
let EMPTY_MESSAGE = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
56
|
+
let MAX_LEN = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 15;
|
|
57
|
+
const message = channel.lastMessage;
|
|
58
|
+
if (!message) return EMPTY_MESSAGE;
|
|
59
|
+
|
|
60
|
+
if (message.isFileMessage()) {
|
|
61
|
+
const extIdx = message.name.lastIndexOf('.');
|
|
62
|
+
|
|
63
|
+
if (extIdx > -1) {
|
|
64
|
+
const file = message.name.slice(0, extIdx);
|
|
65
|
+
const ext = message.name.slice(extIdx);
|
|
66
|
+
return (0, _common.truncate)(file, {
|
|
67
|
+
maxLen: MAX_LEN
|
|
68
|
+
}) + ext;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return (0, _common.truncate)(message.name, {
|
|
72
|
+
maxLen: MAX_LEN
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return message.message ?? EMPTY_MESSAGE;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
exports.getGroupChannelLastMessage = getGroupChannelLastMessage;
|
|
80
|
+
//# sourceMappingURL=groupChannel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["getGroupChannelTitle","currentUserId","channel","EMPTY_USERNAME","NO_MEMBERS","DEFAULT_CHANNEL_NAME","name","memberCount","members","filter","userId","map","nickname","join","getGroupChannelPreviewTime","locale","timestamp","lastMessage","createdAt","joinedAt","isToday","format","isYesterday","getGroupChannelLastMessage","EMPTY_MESSAGE","MAX_LEN","message","isFileMessage","extIdx","lastIndexOf","file","slice","ext","truncate","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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5B,CAAP;AACD,CALM;;;;AAOA,MAAMQ,0BAA0B,GAAG,UAACrB,OAAD,EAAqE;EAAA,IAArCsB,aAAqC,uEAArB,EAAqB;EAAA,IAAjBC,OAAiB,uEAAP,EAAO;EAC7G,MAAMC,OAAO,GAAGxB,OAAO,CAACe,WAAxB;EACA,IAAI,CAACS,OAAL,EAAc,OAAOF,aAAP;;EAEd,IAAIE,OAAO,CAACC,aAAR,EAAJ,EAA6B;IAC3B,MAAMC,MAAM,GAAGF,OAAO,CAACpB,IAAR,CAAauB,WAAb,CAAyB,GAAzB,CAAf;;IACA,IAAID,MAAM,GAAG,CAAC,CAAd,EAAiB;MACf,MAAME,IAAI,GAAGJ,OAAO,CAACpB,IAAR,CAAayB,KAAb,CAAmB,CAAnB,EAAsBH,MAAtB,CAAb;MACA,MAAMI,GAAG,GAAGN,OAAO,CAACpB,IAAR,CAAayB,KAAb,CAAmBH,MAAnB,CAAZ;MACA,OAAO,IAAAK,gBAAA,EAASH,IAAT,EAAe;QAAEI,MAAM,EAAET;MAAV,CAAf,IAAsCO,GAA7C;IACD;;IAED,OAAO,IAAAC,gBAAA,EAASP,OAAO,CAACpB,IAAjB,EAAuB;MAAE4B,MAAM,EAAET;IAAV,CAAvB,CAAP;EACD;;EAED,OAAOC,OAAO,CAACA,OAAR,IAAmBF,aAA1B;AACD,CAhBM"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
import { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react';
|
|
3
|
+
const idPool = {};
|
|
4
|
+
export const useUniqId = key => {
|
|
5
|
+
return useState(() => {
|
|
6
|
+
if (!idPool[key]) idPool[key] = 1;
|
|
7
|
+
return idPool[key]++;
|
|
8
|
+
})[0];
|
|
9
|
+
};
|
|
10
|
+
export const useForceUpdate = () => {
|
|
11
|
+
const [, updater] = useState(0);
|
|
12
|
+
return useCallback(() => updater(prev => prev + 1), []);
|
|
13
|
+
};
|
|
14
|
+
export const useAsyncEffect = (asyncEffect, deps) => {
|
|
15
|
+
useEffect(createAsyncEffectCallback(asyncEffect), deps);
|
|
16
|
+
};
|
|
17
|
+
export const useAsyncLayoutEffect = (asyncEffect, deps) => {
|
|
18
|
+
useLayoutEffect(createAsyncEffectCallback(asyncEffect), deps);
|
|
19
|
+
};
|
|
20
|
+
export const useIIFE = callback => {
|
|
21
|
+
return iife(callback);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const iife = callback => callback();
|
|
25
|
+
|
|
26
|
+
const createAsyncEffectCallback = asyncEffect => () => {
|
|
27
|
+
const destructor = iife(asyncEffect);
|
|
28
|
+
return () => {
|
|
29
|
+
if (!destructor) return;
|
|
30
|
+
|
|
31
|
+
if (destructor instanceof Promise) {
|
|
32
|
+
iife(async () => {
|
|
33
|
+
const awaitedDestructor = await destructor;
|
|
34
|
+
if (awaitedDestructor) awaitedDestructor();
|
|
35
|
+
});
|
|
36
|
+
} else {
|
|
37
|
+
iife(destructor);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export const useIsMountedRef = () => {
|
|
43
|
+
const isMounted = useRef(true);
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
return () => {
|
|
46
|
+
isMounted.current = false;
|
|
47
|
+
};
|
|
48
|
+
}, []);
|
|
49
|
+
return isMounted;
|
|
50
|
+
};
|
|
51
|
+
export const useFreshCallback = callback => {
|
|
52
|
+
const ref = useRef(callback);
|
|
53
|
+
useLayoutEffect(() => {
|
|
54
|
+
ref.current = callback;
|
|
55
|
+
});
|
|
56
|
+
return useCallback(function () {
|
|
57
|
+
return ref.current(...arguments);
|
|
58
|
+
}, []);
|
|
59
|
+
};
|
|
60
|
+
//# sourceMappingURL=index.js.map
|