@droppii-org/chat-sdk 0.0.55 → 0.0.57

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.
@@ -8,6 +8,9 @@ interface FormatOptions {
8
8
  dateMonthFormat?: string;
9
9
  }
10
10
  export declare function formatTimestamp(timestamp: number, options?: FormatOptions): string;
11
+ export declare const urlRegex: RegExp;
11
12
  export declare function extractLinks(text: string): string[];
13
+ export declare function wrapLinksInHtml(htmlContent: string): string;
14
+ export declare const getHostFromUrl: (url: string) => string | null;
12
15
  export {};
13
16
  //# sourceMappingURL=common.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../src/utils/common.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAGtD,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAapD;AAED,eAAO,MAAM,iCAAiC,GAC5C,aAAa,WAAW,EACxB,YAAY,MAAM,WAkBnB,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAC7B,WAAW,MAAM,EACjB,gBAAgB,MAAM,EACtB,IAAI,GAAG,WAiCR,CAAC;AAEF,eAAO,MAAM,eAAe,GAC1B,MAAM,MAAM,EACZ,SAAS,MAAM,EACf,kBAAc,WA2Cf,CAAC;AAEF,UAAU,aAAa;IACrB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,wBAAgB,eAAe,CAC7B,SAAS,EAAE,MAAM,EACjB,OAAO,CAAC,EAAE,aAAa,GACtB,MAAM,CAqBR;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAKnD"}
1
+ {"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../src/utils/common.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAGtD,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAapD;AAED,eAAO,MAAM,iCAAiC,GAC5C,aAAa,WAAW,EACxB,YAAY,MAAM,WAkBnB,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAC7B,WAAW,MAAM,EACjB,gBAAgB,MAAM,EACtB,IAAI,GAAG,WAiCR,CAAC;AAEF,eAAO,MAAM,eAAe,GAC1B,MAAM,MAAM,EACZ,SAAS,MAAM,EACf,kBAAc,WA2Cf,CAAC;AAEF,UAAU,aAAa;IACrB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,wBAAgB,eAAe,CAC7B,SAAS,EAAE,MAAM,EACjB,OAAO,CAAC,EAAE,aAAa,GACtB,MAAM,CAqBR;AAED,eAAO,MAAM,QAAQ,QAAkD,CAAC;AAExE,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAEnD;AAED,wBAAgB,eAAe,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAqC3D;AAED,eAAO,MAAM,cAAc,GAAI,KAAK,MAAM,KAAG,MAAM,GAAG,IAOrD,CAAC"}
@@ -113,8 +113,45 @@ export function formatTimestamp(timestamp, options) {
113
113
  ? date.format(`HH:mm ${dateMonthFormat} YYYY`)
114
114
  : date.format(`${dateMonthFormat} YYYY`);
115
115
  }
116
+ export const urlRegex = /\bhttps?:\/\/[^\s<>"']*[^\s<>"',.!?()\[\]{}]/g;
116
117
  export function extractLinks(text) {
117
- // Regex match http:// hoặc https:// và domain
118
- const urlRegex = /\bhttps?:\/\/[^\s<>"']*[^\s<>"',.!?()\[\]{}]/g;
119
118
  return text.match(urlRegex) || [];
120
119
  }
120
+ export function wrapLinksInHtml(htmlContent) {
121
+ var _a;
122
+ // Regex để kiểm tra xem link có nằm trong thẻ <a> không
123
+ const anchorTagRegex = /<a\s[^>]*>.*?<\/a>/gi;
124
+ let result = "";
125
+ let lastIndex = 0;
126
+ // Tách các đoạn đã có <a> sẵn ra để tránh xử lý nhầm
127
+ const matches = [...htmlContent.matchAll(anchorTagRegex)];
128
+ for (const match of matches) {
129
+ const matchStart = (_a = match.index) !== null && _a !== void 0 ? _a : 0;
130
+ const matchEnd = matchStart + match[0].length;
131
+ // Xử lý phần nằm trước thẻ a
132
+ const before = htmlContent.slice(lastIndex, matchStart);
133
+ const replacedBefore = before.replace(urlRegex, (url) => {
134
+ return `<a href="${url}" target="_blank" rel="noopener noreferrer">${url}</a>`;
135
+ });
136
+ result += replacedBefore;
137
+ // Giữ nguyên phần trong thẻ a
138
+ result += match[0];
139
+ lastIndex = matchEnd;
140
+ }
141
+ // Xử lý phần còn lại sau thẻ a cuối cùng
142
+ const after = htmlContent.slice(lastIndex);
143
+ const replacedAfter = after.replace(urlRegex, (url) => {
144
+ return `<a class="text-blue-500 underline" href="${url}" target="_blank" rel="noopener noreferrer">${url}</a>`;
145
+ });
146
+ result += replacedAfter;
147
+ return result;
148
+ }
149
+ export const getHostFromUrl = (url) => {
150
+ try {
151
+ const u = new URL(url);
152
+ return u.host;
153
+ }
154
+ catch (err) {
155
+ return null;
156
+ }
157
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@droppii-org/chat-sdk",
3
- "version": "0.0.55",
3
+ "version": "0.0.57",
4
4
  "description": "Droppii React Chat SDK",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",