@libs-ui/components-preview-text-data 0.2.357-27 → 0.2.357-29
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/README.md +79 -0
- package/esm2022/index.mjs +2 -1
- package/esm2022/preview-text-data.component.mjs +72 -4
- package/esm2022/preview-text-data.define.mjs +30 -1
- package/esm2022/sql-format.define.mjs +364 -0
- package/fesm2022/libs-ui-components-preview-text-data.mjs +464 -4
- package/fesm2022/libs-ui-components-preview-text-data.mjs.map +1 -1
- package/index.d.ts +1 -0
- package/package.json +7 -7
- package/preview-text-data.component.d.ts +34 -1
- package/preview-text-data.define.d.ts +14 -0
- package/sql-format.define.d.ts +58 -0
|
@@ -154,6 +154,35 @@ const DEFAULT_SECURITY_PATTERNS = [
|
|
|
154
154
|
/document\.write\s*\(/i,
|
|
155
155
|
/window\.location\s*=/i,
|
|
156
156
|
];
|
|
157
|
+
/**
|
|
158
|
+
* Bộ pattern chặn mặc định cho ô soạn **SQL** — dùng với `[forbiddenPatterns]`.
|
|
159
|
+
*
|
|
160
|
+
* 🔴 `DEFAULT_SECURITY_PATTERNS` ở trên CHỈ chặn API JavaScript (`eval`, `fetch`, `localStorage`…)
|
|
161
|
+
* nên không dùng được cho SQL. Bộ này chặn câu lệnh GHI và truy vấn siêu dữ liệu, dành cho các màn
|
|
162
|
+
* chỉ cho phép đọc (BI, dashboard, báo cáo).
|
|
163
|
+
*
|
|
164
|
+
* 🔴 Đây là lớp THUẬN TIỆN cho người dùng — báo sớm ngay khi gõ sai loại câu lệnh, KHÔNG phải lớp
|
|
165
|
+
* bảo mật: người dùng vẫn gọi API trực tiếp được. Backend BẮT BUỘC tự kiểm lại.
|
|
166
|
+
*
|
|
167
|
+
* Màn thật sự cần chạy câu lệnh ghi thì tự truyền bộ pattern riêng, hoặc lọc bớt bộ này:
|
|
168
|
+
* `DEFAULT_SQL_FORBIDDEN_PATTERNS.filter((p) => !String(p).includes('delete'))`.
|
|
169
|
+
*/
|
|
170
|
+
const DEFAULT_SQL_FORBIDDEN_PATTERNS = [
|
|
171
|
+
// Câu lệnh đổi lược đồ.
|
|
172
|
+
/\b(drop|truncate|alter|create)\b/i,
|
|
173
|
+
// Câu lệnh ghi dữ liệu.
|
|
174
|
+
/\b(delete|update|insert)\b/i,
|
|
175
|
+
// Câu lệnh đổi quyền.
|
|
176
|
+
/\b(grant|revoke)\b/i,
|
|
177
|
+
// Ghi kết quả ra tệp trên máy chủ cơ sở dữ liệu.
|
|
178
|
+
/\binto\s+outfile\b/i,
|
|
179
|
+
// Đọc siêu dữ liệu — lộ toàn bộ danh sách bảng/cột của hệ thống.
|
|
180
|
+
/\binformation_schema\b/i,
|
|
181
|
+
// Bảng/hàm hệ thống của PostgreSQL.
|
|
182
|
+
/\bpg_[a-z_]+\b/i,
|
|
183
|
+
// Dấu chấm phẩy rồi còn nội dung phía sau ⇒ nối thêm câu lệnh thứ hai.
|
|
184
|
+
/;\s*\S/,
|
|
185
|
+
];
|
|
157
186
|
/**
|
|
158
187
|
* Các key của AST node KHÔNG phải node con (metadata vị trí, comment...) — bỏ qua khi duyệt.
|
|
159
188
|
*/
|
|
@@ -861,6 +890,370 @@ const applyMaxHeight = (view, options) => {
|
|
|
861
890
|
}));
|
|
862
891
|
};
|
|
863
892
|
|
|
893
|
+
/**
|
|
894
|
+
* Định dạng lại câu lệnh SQL cho dễ đọc — người dùng không phải tự căn chỉnh bằng tay.
|
|
895
|
+
*
|
|
896
|
+
* 🔴 Đây là bộ định dạng THUẦN (không thêm phụ thuộc nào vào thư viện dùng chung). Nó xử lý được
|
|
897
|
+
* phần lớn câu lệnh truy vấn thường gặp; câu quá lạ thì giữ nguyên chứ KHÔNG làm sai — xem
|
|
898
|
+
* `sqlFormat` đoạn về nguyên tắc "không đổi nghĩa".
|
|
899
|
+
*
|
|
900
|
+
* Việc nó làm:
|
|
901
|
+
* - mỗi từ khoá mở đầu một mệnh đề (`SELECT`, `FROM`, `WHERE`, `GROUP BY`…) xuống dòng mới;
|
|
902
|
+
* - mỗi cột trong `SELECT` một dòng, thụt vào một cấp;
|
|
903
|
+
* - `AND` / `OR` trong `WHERE` xuống dòng, thụt vào;
|
|
904
|
+
* - `JOIN … ON …` xuống dòng, `ON` thụt vào một cấp;
|
|
905
|
+
* - ngoặc lồng (câu con) tăng một cấp thụt;
|
|
906
|
+
* - toán tử so sánh có đúng một dấu cách hai bên (`c=1` → `c = 1`);
|
|
907
|
+
* - từ khoá viết HOA, tên bảng/cột giữ nguyên nguyên văn người dùng gõ;
|
|
908
|
+
* - gom nhiều dòng trắng liên tiếp thành một.
|
|
909
|
+
*/
|
|
910
|
+
/** Một cấp thụt = 2 dấu cách. Hai cấp là đủ thấy tầng mà không đẩy chữ ra xa mép. */
|
|
911
|
+
const INDENT_STEP = ' ';
|
|
912
|
+
/**
|
|
913
|
+
* Từ khoá mở đầu một MỆNH ĐỀ — luôn bắt đầu một dòng mới, ở cấp thụt hiện tại.
|
|
914
|
+
*
|
|
915
|
+
* 🔴 Xếp cụm DÀI trước cụm ngắn (`GROUP BY` trước `GROUP`, `LEFT JOIN` trước `JOIN`): bộ so khớp
|
|
916
|
+
* lấy cụm khớp đầu tiên, để ngắn trước thì `GROUP BY` bị cắt thành `GROUP` rồi `BY` lạc ra ngoài.
|
|
917
|
+
*/
|
|
918
|
+
const CLAUSE_KEYWORDS = [
|
|
919
|
+
'SELECT DISTINCT', 'SELECT',
|
|
920
|
+
'FROM',
|
|
921
|
+
'LEFT OUTER JOIN', 'RIGHT OUTER JOIN', 'FULL OUTER JOIN',
|
|
922
|
+
'LEFT JOIN', 'RIGHT JOIN', 'INNER JOIN', 'CROSS JOIN', 'FULL JOIN', 'JOIN',
|
|
923
|
+
'WHERE',
|
|
924
|
+
'GROUP BY', 'HAVING',
|
|
925
|
+
'ORDER BY',
|
|
926
|
+
'LIMIT', 'OFFSET',
|
|
927
|
+
'UNION ALL', 'UNION', 'INTERSECT', 'EXCEPT',
|
|
928
|
+
'WITH',
|
|
929
|
+
];
|
|
930
|
+
/** Từ khoá xuống dòng nhưng THỤT THÊM một cấp — nằm trong mệnh đề chứ không mở mệnh đề mới. */
|
|
931
|
+
const INDENTED_KEYWORDS = ['AND', 'OR', 'ON'];
|
|
932
|
+
/** Từ khoá chỉ viết HOA, không đụng tới dòng — nằm giữa biểu thức. */
|
|
933
|
+
const INLINE_KEYWORDS = [
|
|
934
|
+
'CASE', 'WHEN', 'THEN', 'ELSE', 'END',
|
|
935
|
+
'AS', 'IN', 'NOT', 'NULL', 'IS', 'LIKE', 'ILIKE', 'BETWEEN', 'EXISTS',
|
|
936
|
+
'ASC', 'DESC', 'OVER', 'PARTITION BY', 'CAST', 'INTERVAL', 'USING',
|
|
937
|
+
];
|
|
938
|
+
/**
|
|
939
|
+
* Toán tử so sánh / tính toán — luôn có ĐÚNG MỘT dấu cách hai bên.
|
|
940
|
+
*
|
|
941
|
+
* 🔴 Xếp toán tử HAI KÝ TỰ trước một ký tự (`<=` trước `<`, `!=` trước `!`): so khớp lấy cụm đầu
|
|
942
|
+
* tiên, để ngắn trước thì `a <= b` bị tách thành `a < = b` — sai cú pháp.
|
|
943
|
+
*
|
|
944
|
+
* 🔴 KHÔNG có `*`: `select *` và `count(*)` là dùng phổ biến nhất, chèn dấu cách quanh nó thành
|
|
945
|
+
* `select *` thì vô hại nhưng `count( * )` thì khó đọc. Phép nhân thật thì người dùng tự gõ cách.
|
|
946
|
+
*/
|
|
947
|
+
const OPERATORS = ['<=', '>=', '<>', '!=', '||', '=', '<', '>', '+', '-', '/', '%'];
|
|
948
|
+
/**
|
|
949
|
+
* Tách câu lệnh thành các mẩu, đánh dấu mẩu nào phải giữ nguyên văn.
|
|
950
|
+
*
|
|
951
|
+
* 🔴 Chuỗi · định danh trích dẫn · chú thích KHÔNG được đụng tới: đổi chữ trong `'Hà Nội'` thành
|
|
952
|
+
* `'HÀ NỘI'` là đổi DỮ LIỆU, còn chèn dòng mới vào giữa chuỗi là làm hỏng câu lệnh. Đây là lý do
|
|
953
|
+
* phải quét một lượt có trạng thái thay vì dùng regex trần.
|
|
954
|
+
*/
|
|
955
|
+
const sqlSplitPreservingLiterals = (sql) => {
|
|
956
|
+
const fragments = [];
|
|
957
|
+
let buffer = '';
|
|
958
|
+
let i = 0;
|
|
959
|
+
const flushBuffer = () => {
|
|
960
|
+
if (buffer) {
|
|
961
|
+
fragments.push({ text: buffer, isLiteral: false });
|
|
962
|
+
}
|
|
963
|
+
buffer = '';
|
|
964
|
+
};
|
|
965
|
+
while (i < sql.length) {
|
|
966
|
+
const ch = sql[i];
|
|
967
|
+
const next = sql[i + 1];
|
|
968
|
+
// Chú thích dòng `-- …`.
|
|
969
|
+
if (ch === '-' && next === '-') {
|
|
970
|
+
const end = sql.indexOf('\n', i);
|
|
971
|
+
const stop = end === -1 ? sql.length : end;
|
|
972
|
+
flushBuffer();
|
|
973
|
+
fragments.push({ text: sql.slice(i, stop), isLiteral: true });
|
|
974
|
+
i = stop;
|
|
975
|
+
continue;
|
|
976
|
+
}
|
|
977
|
+
// Chú thích khối `/* … */`.
|
|
978
|
+
if (ch === '/' && next === '*') {
|
|
979
|
+
const end = sql.indexOf('*/', i + 2);
|
|
980
|
+
const stop = end === -1 ? sql.length : end + 2;
|
|
981
|
+
flushBuffer();
|
|
982
|
+
fragments.push({ text: sql.slice(i, stop), isLiteral: true });
|
|
983
|
+
i = stop;
|
|
984
|
+
continue;
|
|
985
|
+
}
|
|
986
|
+
// Chuỗi và định danh trích dẫn: `'…'`, `"…"`, `` `…` ``.
|
|
987
|
+
if (ch === "'" || ch === '"' || ch === '`') {
|
|
988
|
+
let j = i + 1;
|
|
989
|
+
while (j < sql.length) {
|
|
990
|
+
if (sql[j] === '\\') {
|
|
991
|
+
j += 2;
|
|
992
|
+
continue;
|
|
993
|
+
}
|
|
994
|
+
if (sql[j] !== ch) {
|
|
995
|
+
j += 1;
|
|
996
|
+
continue;
|
|
997
|
+
}
|
|
998
|
+
// Nhân đôi dấu đóng = một dấu theo nghĩa đen, chuỗi chưa kết thúc.
|
|
999
|
+
if (sql[j + 1] === ch) {
|
|
1000
|
+
j += 2;
|
|
1001
|
+
continue;
|
|
1002
|
+
}
|
|
1003
|
+
break;
|
|
1004
|
+
}
|
|
1005
|
+
const stop = Math.min(j + 1, sql.length);
|
|
1006
|
+
flushBuffer();
|
|
1007
|
+
fragments.push({ text: sql.slice(i, stop), isLiteral: true });
|
|
1008
|
+
i = stop;
|
|
1009
|
+
continue;
|
|
1010
|
+
}
|
|
1011
|
+
buffer += ch;
|
|
1012
|
+
i += 1;
|
|
1013
|
+
}
|
|
1014
|
+
flushBuffer();
|
|
1015
|
+
return fragments;
|
|
1016
|
+
};
|
|
1017
|
+
/** Từ khoá khớp tại vị trí này (đã chuẩn hoá khoảng trắng), hoặc rỗng. */
|
|
1018
|
+
const matchKeyword = (text, position, keywordList) => {
|
|
1019
|
+
for (const keyword of keywordList) {
|
|
1020
|
+
const slice = text.slice(position, position + keyword.length);
|
|
1021
|
+
if (slice.toUpperCase() !== keyword) {
|
|
1022
|
+
continue;
|
|
1023
|
+
}
|
|
1024
|
+
// Phải là RANH GIỚI TỪ hai đầu: `FROM` trong `FROMAGE` không phải từ khoá, và `x.on` cũng vậy.
|
|
1025
|
+
const prevChar = position === 0 ? ' ' : text[position - 1];
|
|
1026
|
+
const nextChar = text[position + keyword.length] ?? ' ';
|
|
1027
|
+
if (/[a-zA-Z0-9_$.]/.test(prevChar) || /[a-zA-Z0-9_$.]/.test(nextChar)) {
|
|
1028
|
+
continue;
|
|
1029
|
+
}
|
|
1030
|
+
return keyword;
|
|
1031
|
+
}
|
|
1032
|
+
return '';
|
|
1033
|
+
};
|
|
1034
|
+
/**
|
|
1035
|
+
* Thêm một dòng mới ở cấp thụt cho trước, gộp khoảng trắng đuôi.
|
|
1036
|
+
*
|
|
1037
|
+
* 🔴 Đang ở ĐẦU DÒNG rồi thì chỉ đặt lại mức thụt, KHÔNG thêm `\n` nữa: mở ngoặc câu con rồi gặp
|
|
1038
|
+
* ngay `SELECT` là hai lần gọi liên tiếp, thêm cả hai thì sinh một dòng trắng giữa `FROM (` và
|
|
1039
|
+
* `SELECT` (đo 21/09/2026).
|
|
1040
|
+
*/
|
|
1041
|
+
const breakLine = (state, indentLevel) => {
|
|
1042
|
+
const indent = INDENT_STEP.repeat(Math.max(indentLevel, 0));
|
|
1043
|
+
const trimmed = state.out.replace(/[ \t]+$/, '');
|
|
1044
|
+
state.out = trimmed.endsWith('\n') ? `${trimmed}${indent}` : `${trimmed}\n${indent}`;
|
|
1045
|
+
};
|
|
1046
|
+
/**
|
|
1047
|
+
* Định dạng lại một câu lệnh SQL.
|
|
1048
|
+
*
|
|
1049
|
+
* 🔴 NGUYÊN TẮC BẤT BIẾN: chỉ đổi KHOẢNG TRẮNG và CHỮ HOA-THƯỜNG CỦA TỪ KHOÁ. Không thêm, không bớt,
|
|
1050
|
+
* không đổi thứ tự bất kỳ ký tự nào khác — nhờ vậy định dạng lại không bao giờ làm sai câu lệnh.
|
|
1051
|
+
* Bỏ khoảng trắng và chuẩn hoá chữ thì chuỗi trước và sau phải trùng khít; spec có ca kiểm điều này.
|
|
1052
|
+
*
|
|
1053
|
+
* 🔴 Câu lệnh rỗng hoặc chỉ có khoảng trắng thì trả `''` — nơi gọi không phải tự kiểm.
|
|
1054
|
+
*/
|
|
1055
|
+
const sqlFormat = (sql) => {
|
|
1056
|
+
if (!sql?.trim()) {
|
|
1057
|
+
return '';
|
|
1058
|
+
}
|
|
1059
|
+
const fragments = sqlSplitPreservingLiterals(sql);
|
|
1060
|
+
const state = { out: '', depth: 0, fnDepth: 0 };
|
|
1061
|
+
for (const fragment of fragments) {
|
|
1062
|
+
if (fragment.isLiteral) {
|
|
1063
|
+
state.out += fragment.text;
|
|
1064
|
+
continue;
|
|
1065
|
+
}
|
|
1066
|
+
// Gộp mọi chuỗi khoảng trắng thành một dấu cách để xử lý đồng nhất.
|
|
1067
|
+
const text = fragment.text.replace(/\s+/g, ' ');
|
|
1068
|
+
let i = 0;
|
|
1069
|
+
while (i < text.length) {
|
|
1070
|
+
const ch = text[i];
|
|
1071
|
+
// Mở ngoặc: tăng cấp. Ngoặc của HÀM thì đánh dấu để dấu phẩy bên trong không xuống dòng.
|
|
1072
|
+
if (ch === '(') {
|
|
1073
|
+
// 🔴 Phải xét TỪ đứng ngay trước: ngoặc dán liền một định danh (`coalesce(`) là ngoặc hàm,
|
|
1074
|
+
// còn ngoặc sau một TỪ KHOÁ (`FROM (`, `IN (`, `EXISTS (`) mở một CÂU CON và phải được định
|
|
1075
|
+
// dạng như câu lệnh đầy đủ. Chỉ kiểm `[a-zA-Z0-9_$]\s*$` thì `FROM (` bị nhận nhầm là hàm,
|
|
1076
|
+
// nên toàn bộ câu con giữ nguyên chữ thường và không xuống dòng (đo 21/09/2026).
|
|
1077
|
+
const prevWord = (/([a-zA-Z0-9_$]+)\s*$/.exec(state.out)?.[1] ?? '').toUpperCase();
|
|
1078
|
+
const isGluedToPrev = /[a-zA-Z0-9_$]$/.test(state.out);
|
|
1079
|
+
const isKeyword = [...CLAUSE_KEYWORDS, ...INDENTED_KEYWORDS, ...INLINE_KEYWORDS].includes(prevWord);
|
|
1080
|
+
/**
|
|
1081
|
+
* 🔴 Ngoặc sau các từ khoá này chứa DANH SÁCH GIÁ TRỊ hoặc một biểu thức ngắn, không phải
|
|
1082
|
+
* câu con — giữ trên một dòng. Tách ra thì `y IN (1, 2, 3)` thành 5 dòng, đọc còn khó hơn
|
|
1083
|
+
* lúc chưa định dạng (đo 21/09/2026).
|
|
1084
|
+
*/
|
|
1085
|
+
const isInlineParen = ['IN', 'VALUES', 'OVER', 'PARTITION BY', 'USING', 'CAST'].includes(prevWord);
|
|
1086
|
+
const isFnCall = (isGluedToPrev && !isKeyword) || isInlineParen;
|
|
1087
|
+
state.out += '(';
|
|
1088
|
+
state.depth += 1;
|
|
1089
|
+
if (isFnCall) {
|
|
1090
|
+
state.fnDepth += 1;
|
|
1091
|
+
}
|
|
1092
|
+
else {
|
|
1093
|
+
breakLine(state, state.depth);
|
|
1094
|
+
}
|
|
1095
|
+
i += 1;
|
|
1096
|
+
continue;
|
|
1097
|
+
}
|
|
1098
|
+
if (ch === ')') {
|
|
1099
|
+
state.depth = Math.max(state.depth - 1, 0);
|
|
1100
|
+
if (state.fnDepth > 0) {
|
|
1101
|
+
state.fnDepth -= 1;
|
|
1102
|
+
}
|
|
1103
|
+
else {
|
|
1104
|
+
breakLine(state, state.depth);
|
|
1105
|
+
}
|
|
1106
|
+
state.out += ')';
|
|
1107
|
+
i += 1;
|
|
1108
|
+
continue;
|
|
1109
|
+
}
|
|
1110
|
+
// Dấu phẩy: xuống dòng, TRỪ khi đang trong ngoặc của hàm (`sum(a, b)` giữ một dòng).
|
|
1111
|
+
if (ch === ',') {
|
|
1112
|
+
state.out = state.out.replace(/[ \t]+$/, '');
|
|
1113
|
+
state.out += ',';
|
|
1114
|
+
if (!state.fnDepth) {
|
|
1115
|
+
breakLine(state, state.depth + 1);
|
|
1116
|
+
}
|
|
1117
|
+
else {
|
|
1118
|
+
state.out += ' ';
|
|
1119
|
+
}
|
|
1120
|
+
i += 1;
|
|
1121
|
+
continue;
|
|
1122
|
+
}
|
|
1123
|
+
// Dấu chấm phẩy kết câu: sát chữ trước rồi xuống dòng.
|
|
1124
|
+
if (ch === ';') {
|
|
1125
|
+
state.out = `${state.out.replace(/[ \t]+$/, '')};`;
|
|
1126
|
+
state.depth = 0;
|
|
1127
|
+
state.fnDepth = 0;
|
|
1128
|
+
breakLine(state, 0);
|
|
1129
|
+
i += 1;
|
|
1130
|
+
continue;
|
|
1131
|
+
}
|
|
1132
|
+
// 🔴 Trong ngoặc của HÀM thì không xét từ khoá mệnh đề: `count(*) over (partition by x)` mà
|
|
1133
|
+
// tách `PARTITION BY` ra dòng riêng thì đọc còn khó hơn.
|
|
1134
|
+
if (!state.fnDepth) {
|
|
1135
|
+
const clauseKeyword = matchKeyword(text, i, CLAUSE_KEYWORDS);
|
|
1136
|
+
if (clauseKeyword) {
|
|
1137
|
+
if (state.out.trim()) {
|
|
1138
|
+
breakLine(state, state.depth);
|
|
1139
|
+
}
|
|
1140
|
+
state.out += `${clauseKeyword} `;
|
|
1141
|
+
i += clauseKeyword.length;
|
|
1142
|
+
// Bỏ dấu cách ngay sau từ khoá, đã tự thêm ở trên.
|
|
1143
|
+
if (text[i] === ' ') {
|
|
1144
|
+
i += 1;
|
|
1145
|
+
}
|
|
1146
|
+
continue;
|
|
1147
|
+
}
|
|
1148
|
+
const indentedKeyword = matchKeyword(text, i, INDENTED_KEYWORDS);
|
|
1149
|
+
if (indentedKeyword) {
|
|
1150
|
+
if (state.out.trim()) {
|
|
1151
|
+
breakLine(state, state.depth + 1);
|
|
1152
|
+
}
|
|
1153
|
+
state.out += `${indentedKeyword} `;
|
|
1154
|
+
i += indentedKeyword.length;
|
|
1155
|
+
if (text[i] === ' ') {
|
|
1156
|
+
i += 1;
|
|
1157
|
+
}
|
|
1158
|
+
continue;
|
|
1159
|
+
}
|
|
1160
|
+
}
|
|
1161
|
+
const inlineKeyword = matchKeyword(text, i, INLINE_KEYWORDS);
|
|
1162
|
+
if (inlineKeyword) {
|
|
1163
|
+
state.out += inlineKeyword;
|
|
1164
|
+
i += inlineKeyword.length;
|
|
1165
|
+
continue;
|
|
1166
|
+
}
|
|
1167
|
+
// Toán tử: đúng một dấu cách hai bên, dù người dùng gõ `c=1` hay `c = 1`.
|
|
1168
|
+
const operator = OPERATORS.find((op) => text.startsWith(op, i));
|
|
1169
|
+
if (operator) {
|
|
1170
|
+
/**
|
|
1171
|
+
* 🔴 Dấu trừ đứng đầu biểu thức là DẤU ÂM, không phải phép trừ: `-1` giữ nguyên, `a - 1`
|
|
1172
|
+
* thì tách. Nhận nhầm thì `limit -1` thành `limit - 1` — đổi hẳn nghĩa câu lệnh.
|
|
1173
|
+
*
|
|
1174
|
+
* Ba chỗ nó là dấu âm: đầu câu, ngay sau một dấu ngắt/toán tử khác, và ngay sau một TỪ KHOÁ
|
|
1175
|
+
* (`LIMIT -1`, `WHERE -1 = x`). Trường hợp cuối phải xét riêng vì ký tự liền trước là chữ
|
|
1176
|
+
* cái, không khớp bảng dấu ngắt (đo 21/09/2026).
|
|
1177
|
+
*/
|
|
1178
|
+
const trimmedLeft = state.out.replace(/[ \t]+$/, '');
|
|
1179
|
+
const adjacentWord = /([a-zA-Z0-9_$]+)$/.exec(trimmedLeft)?.[1] ?? '';
|
|
1180
|
+
const afterKeyword = Boolean(adjacentWord) && [...CLAUSE_KEYWORDS, ...INDENTED_KEYWORDS, ...INLINE_KEYWORDS].includes(adjacentWord.toUpperCase());
|
|
1181
|
+
const isNegativeSign = operator === '-' && (!trimmedLeft || /[(,=<>+\-*/%]$/.test(trimmedLeft) || afterKeyword);
|
|
1182
|
+
if (isNegativeSign) {
|
|
1183
|
+
/**
|
|
1184
|
+
* 🔴 Dán liền dấu âm vào SỐ, nhưng phải giữ khoảng cách với thứ đứng trước nó — chỉ có
|
|
1185
|
+
* `(` và `,` là dán được:
|
|
1186
|
+
* `(-1)` · `(a, -1)` → dán liền
|
|
1187
|
+
* `LIMIT -1` · `b = -1` → phải có dấu cách, cắt sạch thì ra `LIMIT-1` / `b =-1`
|
|
1188
|
+
*/
|
|
1189
|
+
const glueToPrev = /[(,]$/.test(trimmedLeft);
|
|
1190
|
+
state.out = glueToPrev ? `${trimmedLeft}${operator}` : `${trimmedLeft} ${operator}`;
|
|
1191
|
+
i += operator.length;
|
|
1192
|
+
continue;
|
|
1193
|
+
}
|
|
1194
|
+
state.out = `${trimmedLeft} ${operator} `;
|
|
1195
|
+
i += operator.length;
|
|
1196
|
+
// Bỏ khoảng trắng người dùng đã gõ sau toán tử, đã tự thêm một dấu cách ở trên.
|
|
1197
|
+
while (text[i] === ' ') {
|
|
1198
|
+
i += 1;
|
|
1199
|
+
}
|
|
1200
|
+
continue;
|
|
1201
|
+
}
|
|
1202
|
+
// Không gộp hai dấu cách liền nhau, và không mở đầu dòng bằng dấu cách.
|
|
1203
|
+
if (ch === ' ' && (state.out.endsWith(' ') || state.out.endsWith('\n') || !state.out)) {
|
|
1204
|
+
i += 1;
|
|
1205
|
+
continue;
|
|
1206
|
+
}
|
|
1207
|
+
state.out += ch;
|
|
1208
|
+
i += 1;
|
|
1209
|
+
}
|
|
1210
|
+
}
|
|
1211
|
+
return state.out
|
|
1212
|
+
// Gom nhiều dòng trắng liên tiếp thành một dòng trắng.
|
|
1213
|
+
.replace(/\n{3,}/g, '\n\n')
|
|
1214
|
+
// Bỏ khoảng trắng cuối mỗi dòng.
|
|
1215
|
+
.split('\n')
|
|
1216
|
+
.map((line) => line.replace(/\s+$/, ''))
|
|
1217
|
+
.join('\n')
|
|
1218
|
+
.trim();
|
|
1219
|
+
};
|
|
1220
|
+
/**
|
|
1221
|
+
* Bỏ mọi khoảng trắng và chuẩn hoá chữ — dùng để KIỂM việc định dạng không đổi nghĩa câu lệnh.
|
|
1222
|
+
*
|
|
1223
|
+
* 🔴 Giữ nguyên nội dung vùng chuỗi/chú thích khi chuẩn hoá: chữ trong `'Hà Nội'` là dữ liệu, không
|
|
1224
|
+
* phải mã lệnh, nên không được viết hoa nó khi so sánh.
|
|
1225
|
+
*/
|
|
1226
|
+
const sqlNormalizeForCompare = (sql) => sqlSplitPreservingLiterals(sql)
|
|
1227
|
+
.map((fragment) => (fragment.isLiteral ? fragment.text : fragment.text.replace(/\s+/g, '').toUpperCase()))
|
|
1228
|
+
.join('');
|
|
1229
|
+
/** Ngôn ngữ có bộ định dạng — nơi khác hỏi trước khi hiện nút "Định dạng". */
|
|
1230
|
+
const FORMATTABLE_LANGUAGES = ['sql', 'json'];
|
|
1231
|
+
/**
|
|
1232
|
+
* Định dạng nội dung theo NGÔN NGỮ đang chọn. Ngôn ngữ chưa hỗ trợ thì trả nguyên văn.
|
|
1233
|
+
*
|
|
1234
|
+
* 🔴 Trả NGUYÊN VĂN khi không định dạng được (kể cả JSON hỏng cú pháp), KHÔNG ném lỗi và cũng không
|
|
1235
|
+
* trả rỗng: người dùng bấm nhầm nút trên một đoạn đang viết dở mà mất sạch chữ thì còn tệ hơn nhiều
|
|
1236
|
+
* so với việc nút không làm gì.
|
|
1237
|
+
*/
|
|
1238
|
+
const formatByLanguage = (content, language) => {
|
|
1239
|
+
if (!content?.trim()) {
|
|
1240
|
+
return content ?? '';
|
|
1241
|
+
}
|
|
1242
|
+
if (language === 'sql') {
|
|
1243
|
+
return sqlFormat(content);
|
|
1244
|
+
}
|
|
1245
|
+
if (language === 'json') {
|
|
1246
|
+
try {
|
|
1247
|
+
return JSON.stringify(JSON.parse(content), null, 2);
|
|
1248
|
+
}
|
|
1249
|
+
catch {
|
|
1250
|
+
// JSON chưa hợp lệ (đang gõ dở) — giữ nguyên, người dùng tự sửa rồi bấm lại.
|
|
1251
|
+
return content;
|
|
1252
|
+
}
|
|
1253
|
+
}
|
|
1254
|
+
return content;
|
|
1255
|
+
};
|
|
1256
|
+
|
|
864
1257
|
class LibsUiComponentsPreviewTextDataComponent {
|
|
865
1258
|
// ==========================================================================
|
|
866
1259
|
// PRIVATE PROPERTIES
|
|
@@ -947,6 +1340,26 @@ class LibsUiComponentsPreviewTextDataComponent {
|
|
|
947
1340
|
background = input('#f8f9fa', {
|
|
948
1341
|
transform: (value) => value ?? '#f8f9fa',
|
|
949
1342
|
});
|
|
1343
|
+
/**
|
|
1344
|
+
* Hiện nút "Định dạng" trên thanh công cụ — bấm một lần là nội dung tự căn chỉnh gọn gàng, người
|
|
1345
|
+
* dùng không phải gõ dấu cách và xuống dòng bằng tay.
|
|
1346
|
+
*
|
|
1347
|
+
* 🔴 Mặc định BẬT nhưng CHỈ hiện khi ô đang sửa được và ngôn ngữ đang chọn có bộ định dạng
|
|
1348
|
+
* (hiện có `sql` và `json`) — xem `coTheDinhDang`. Nhờ vậy nơi dùng không phải khai gì thêm, mà
|
|
1349
|
+
* ô chỉ-đọc hay ngôn ngữ chưa hỗ trợ cũng không mọc ra một nút bấm không làm gì.
|
|
1350
|
+
*/
|
|
1351
|
+
showFormatAction = input(true, {
|
|
1352
|
+
transform: (value) => value ?? true,
|
|
1353
|
+
});
|
|
1354
|
+
/**
|
|
1355
|
+
* Tự định dạng NGAY khi nạp nội dung vào ô.
|
|
1356
|
+
*
|
|
1357
|
+
* 🔴 Mặc định TẮT: nội dung người dùng đã lưu có thể đang được họ căn theo ý riêng, tự sửa lúc mở
|
|
1358
|
+
* ra là ghi đè công của họ mà không ai bấm gì. Bật khi nguồn nội dung là máy sinh (mock, mẫu).
|
|
1359
|
+
*/
|
|
1360
|
+
autoFormatOnLoad = input(false, {
|
|
1361
|
+
transform: (value) => value ?? false,
|
|
1362
|
+
});
|
|
950
1363
|
// ==========================================================================
|
|
951
1364
|
// OUTPUTS
|
|
952
1365
|
// ==========================================================================
|
|
@@ -963,7 +1376,11 @@ class LibsUiComponentsPreviewTextDataComponent {
|
|
|
963
1376
|
constructor() {
|
|
964
1377
|
// Effect để sync content từ input vào editor
|
|
965
1378
|
effect(() => {
|
|
966
|
-
|
|
1379
|
+
// 🔴 `autoFormatOnLoad` áp NGAY TẠI ĐÂY, không ở `ngOnInit`: nội dung có thể về sau một nhịp
|
|
1380
|
+
// (từ API), lúc `ngOnInit` chạy thì `content()` còn rỗng.
|
|
1381
|
+
// 🔴 Đọc `langSelected` (model.required) CHỈ khi editor đã dựng — trước đó nó chưa có giá trị
|
|
1382
|
+
// và đọc là văng `NG0952`.
|
|
1383
|
+
const newContent = this.autoFormatOnLoad() && this.isInitialized ? formatByLanguage(this.content(), this.langSelected()) : this.content();
|
|
967
1384
|
if (this.isInitialized && this.editorViewInstance) {
|
|
968
1385
|
const currentContent = this.editorViewInstance.state.doc.toString();
|
|
969
1386
|
if (newContent !== currentContent) {
|
|
@@ -1157,6 +1574,49 @@ class LibsUiComponentsPreviewTextDataComponent {
|
|
|
1157
1574
|
// ==========================================================================
|
|
1158
1575
|
// PROTECTED METHODS - Event handlers
|
|
1159
1576
|
// ==========================================================================
|
|
1577
|
+
/**
|
|
1578
|
+
* Nút "Định dạng" có hiện không.
|
|
1579
|
+
*
|
|
1580
|
+
* 🔴 Ba điều kiện cùng lúc: nơi dùng chưa tắt · ô đang SỬA ĐƯỢC · ngôn ngữ đang chọn có bộ định
|
|
1581
|
+
* dạng. Ô chỉ-đọc mà mọc ra nút bấm không làm gì thì người dùng bấm rồi tưởng hỏng.
|
|
1582
|
+
*/
|
|
1583
|
+
canFormat = computed(() => {
|
|
1584
|
+
if (!this.showFormatAction() || !this.editable()) {
|
|
1585
|
+
return false;
|
|
1586
|
+
}
|
|
1587
|
+
// 🔴 `langSelected` là `model.required` — đọc lúc nơi dùng chưa gán là văng `NG0952`, mà
|
|
1588
|
+
// `computed` này chạy ngay nhịp vẽ đầu. Bọc lại để nút chỉ ẩn đi thay vì làm vỡ cả ô soạn.
|
|
1589
|
+
try {
|
|
1590
|
+
return FORMATTABLE_LANGUAGES.includes(this.langSelected());
|
|
1591
|
+
}
|
|
1592
|
+
catch {
|
|
1593
|
+
return false;
|
|
1594
|
+
}
|
|
1595
|
+
});
|
|
1596
|
+
/**
|
|
1597
|
+
* Căn chỉnh lại nội dung đang gõ theo ngôn ngữ đang chọn.
|
|
1598
|
+
*
|
|
1599
|
+
* 🔴 Đọc nội dung từ CHÍNH editor (`state.doc`), không từ `content()`: `content` là input ban đầu,
|
|
1600
|
+
* còn thứ người dùng vừa gõ chỉ có trong doc — lấy nhầm là bấm Định dạng xong chữ nhảy về bản cũ.
|
|
1601
|
+
*
|
|
1602
|
+
* KHÔNG phát `outChange` ở đây: `createUpdateListener` đã nghe `docChanged` và tự phát rồi, phát
|
|
1603
|
+
* thêm là nơi dùng nhận hai lượt cho một thao tác.
|
|
1604
|
+
*/
|
|
1605
|
+
handlerFormat() {
|
|
1606
|
+
// 🔴 Thoát sớm khi editor CHƯA dựng: `langSelected` là `model.required`, đọc lúc chưa có giá trị
|
|
1607
|
+
// là văng `NG0952`. Không có editor thì cũng chẳng có gì để định dạng.
|
|
1608
|
+
if (!this.editorViewInstance) {
|
|
1609
|
+
return;
|
|
1610
|
+
}
|
|
1611
|
+
const current = this.editorViewInstance.state.doc.toString();
|
|
1612
|
+
const isAligned = formatByLanguage(current, this.langSelected());
|
|
1613
|
+
if (!isAligned || isAligned === current) {
|
|
1614
|
+
return;
|
|
1615
|
+
}
|
|
1616
|
+
this.editorViewInstance.dispatch({
|
|
1617
|
+
changes: { from: 0, to: current.length, insert: isAligned },
|
|
1618
|
+
});
|
|
1619
|
+
}
|
|
1160
1620
|
handlerCopy() {
|
|
1161
1621
|
navigator.clipboard.writeText(this.content() || '');
|
|
1162
1622
|
this.notificationService.showCompTypeTextInfo('Sao chép thành công');
|
|
@@ -1199,16 +1659,16 @@ class LibsUiComponentsPreviewTextDataComponent {
|
|
|
1199
1659
|
});
|
|
1200
1660
|
}
|
|
1201
1661
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: LibsUiComponentsPreviewTextDataComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
1202
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "18.2.14", type: LibsUiComponentsPreviewTextDataComponent, isStandalone: true, selector: "libs_ui-components-preview_text_data", inputs: { content: { classPropertyName: "content", publicName: "content", isSignal: true, isRequired: false, transformFunction: null }, langSelected: { classPropertyName: "langSelected", publicName: "langSelected", isSignal: true, isRequired: true, transformFunction: null }, langsAccept: { classPropertyName: "langsAccept", publicName: "langsAccept", isSignal: true, isRequired: false, transformFunction: null }, langsChangeLabel: { classPropertyName: "langsChangeLabel", publicName: "langsChangeLabel", isSignal: true, isRequired: false, transformFunction: null }, editable: { classPropertyName: "editable", publicName: "editable", isSignal: true, isRequired: false, transformFunction: null }, hiddenAction: { classPropertyName: "hiddenAction", publicName: "hiddenAction", isSignal: true, isRequired: false, transformFunction: null }, minLines: { classPropertyName: "minLines", publicName: "minLines", isSignal: true, isRequired: false, transformFunction: null }, maxLines: { classPropertyName: "maxLines", publicName: "maxLines", isSignal: true, isRequired: false, transformFunction: null }, containerElement: { classPropertyName: "containerElement", publicName: "containerElement", isSignal: true, isRequired: false, transformFunction: null }, zIndexPopover: { classPropertyName: "zIndexPopover", publicName: "zIndexPopover", isSignal: true, isRequired: false, transformFunction: null }, hiddenSearchLang: { classPropertyName: "hiddenSearchLang", publicName: "hiddenSearchLang", isSignal: true, isRequired: false, transformFunction: null }, lintIgnorePatterns: { classPropertyName: "lintIgnorePatterns", publicName: "lintIgnorePatterns", isSignal: true, isRequired: false, transformFunction: null }, completions: { classPropertyName: "completions", publicName: "completions", isSignal: true, isRequired: false, transformFunction: null }, forbiddenPatterns: { classPropertyName: "forbiddenPatterns", publicName: "forbiddenPatterns", isSignal: true, isRequired: false, transformFunction: null }, background: { classPropertyName: "background", publicName: "background", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { langSelected: "langSelectedChange", outChange: "outChange", syntaxErrors: "syntaxErrors", outViolations: "outViolations" }, viewQueries: [{ propertyName: "containerPreview", first: true, predicate: ["containerPreview"], descendants: true, isSignal: true }], ngImport: i0, template: "<div\n class=\"libs-ui-preview-data-container flex flex-col w-full h-auto rounded-[8px] libs-ui-border-general px-[8px]\"\n [style.--background-color]=\"background()\"\n [class.pt-[8px]]=\"!hiddenAction()\">\n @if (!hiddenAction()) {\n <div class=\"flex items-center content-between color-[#6a7383]\">\n <libs_ui-components-dropdown\n classInclude=\"w-[200px]\"\n [listConfig]=\"configLoadDataIsHttpConfig()\"\n [listMaxItemShow]=\"5\"\n [zIndex]=\"zIndexPopover()\"\n [isNgContent]=\"true\"\n [readonly]=\"!editable() || !acceptChangeLang()\"\n [listHasButtonUnSelectOption]=\"false\"\n [listHiddenInputSearch]=\"hiddenSearchLang()\"\n (outSelectKey)=\"handlerSelectKey($event)\">\n <libs_ui-components-buttons-button\n [type]=\"'button-link-third'\"\n [label]=\"labelLang() || ''\"\n [sizeButton]=\"'small'\"\n [classIconRight]=\"editable() && acceptChangeLang() ? 'libs-ui-icon-move-right rotate-90' : ''\"\n [classInclude]=\"'!p-[0px]' + (editable() && acceptChangeLang() ? '' : '!pointer-events-none !cursor-default hover:!text-[#6A7383]')\" />\n </libs_ui-components-dropdown>\n <div class=\"flex items-center\">\n <libs_ui-components-buttons-button\n [type]=\"'button-link-third'\"\n [label]=\"isWrap() ? 'i18n_remove_line_wrap' : 'i18n_line_wrap'\"\n [sizeButton]=\"'small'\"\n [classIconLeft]=\"isWrap() ? 'libs-ui-icon-unwrap' : 'libs-ui-icon-wrap'\"\n [classInclude]=\"'mo-lib-p-0px mo-lib-mr-16px'\"\n (outClick)=\"handlerLineWrap()\" />\n <libs_ui-components-buttons-button\n [type]=\"'button-link-third'\"\n [label]=\"'i18n_copy'\"\n [sizeButton]=\"'small'\"\n [classIconLeft]=\"'libs-ui-icon-copy'\"\n [classInclude]=\"'mo-lib-p-0px'\"\n (outClick)=\"handlerCopy()\" />\n </div>\n </div>\n }\n <div #containerPreview></div>\n</div>\n", styles: [":host ::ng-deep .libs-ui-preview-data-container{background-color:var(--background-color)!important}:host ::ng-deep .libs-ui-preview-data-container .cm-line{white-space:pre-wrap}:host ::ng-deep .libs-ui-preview-data-container .cm-lintRange-error{background-color:#ff323233;border-bottom:2px solid red}:host ::ng-deep .libs-ui-preview-data-container .cm-lintRange-warning{background-color:#ffc80026}:host ::ng-deep .libs-ui-preview-data-container .cm-tooltip-lint{background:#fff8f8;color:#d32f2f;border:1px solid #f44336;padding:8px 10px;font-size:13px;font-family:Inter,sans-serif;border-radius:6px;box-shadow:0 2px 8px #ff000026}:host ::ng-deep .libs-ui-preview-data-container .cm-focused{outline:none!important}:host ::ng-deep .libs-ui-preview-data-container .cm-selectionBackground{background-color:#007aff40!important}:host ::ng-deep .libs-ui-preview-data-container .cm-selectionLayer{z-index:1!important}:host ::ng-deep .libs-ui-preview-data-container .cm-gutters{background-color:var(--background-color)!important}\n"], dependencies: [{ kind: "component", type: LibsUiComponentsDropdownComponent, selector: "libs_ui-components-dropdown", inputs: ["useXssFilter", "popoverElementRefCustom", "classInclude", "ignoreStopPropagationEvent", "flagMouse", "flagMouseContent", "popoverCustomConfig", "isNgContent", "zIndex", "convertItemSelected", "getPopoverItemSelected", "httpRequestDetailItemById", "lengthKeys", "textDisplayWhenNoSelect", "textDisplayWhenMultiSelect", "classIncludeTextDisplayWhenNoSelect", "fieldLabel", "fieldGetLabel", "labelPopoverConfig", "labelPopoverFullWidth", "hasContentUnitRight", "listSearchNoDataTemplateRef", "dropdownTemplateRefNotSearchNoData", "fieldGetImage", "imageSize", "typeShape", "fieldGetIcon", "fieldGetTextAvatar", "fieldGetColorAvatar", "classAvatarInclude", "getLastTextAfterSpace", "linkImageError", "showError", "showBorderError", "disable", "readonly", "labelConfig", "disableLabel", "listSearchConfig", "isSearchOnline", "listHiddenInputSearch", "listSearchPadding", "listKeySearch", "listDividerClassInclude", "listConfig", "listButtonsOther", "listHasButtonUnSelectOption", "listClickExactly", "listBackgroundCustom", "listMaxItemShow", "listKeySelected", "listMultiKeySelected", "listKeysDisable", "listKeysHidden", "validRequired", "validMaxItemSelected", "changeValidUndefinedResetError", "allowSelectItemMultiple", "focusInputSearch", "onlyEmitDataWhenReset", "onlyEmitMultiKeyWhenManualClick", "resetKeyWhenSelectAllKey", "listConfigHasDivider", "classIncludeIcon", "classIncludeContent", "listIgnoreClassDisableDefaultWhenUseKeysDisableItem", "tabKeyActive", "tabsConfig", "ignoreBorderBottom"], outputs: ["flagMouseChange", "flagMouseContentChange", "lengthKeysChange", "showBorderErrorChange", "listKeySelectedChange", "listMultiKeySelectedChange", "tabKeyActiveChange", "outSelectKey", "outSelectMultiKey", "outFunctionsControl", "outValidEvent", "outChangStageFlagMouse", "outDataChange", "outClickButtonOther", "outShowList", "outChangeTabKeyActive"] }, { kind: "component", type: LibsUiComponentsButtonsButtonComponent, selector: "libs_ui-components-buttons-button", inputs: ["flagMouse", "type", "buttonCustom", "sizeButton", "label", "disable", "isPending", "imageLeft", "classInclude", "classIconLeft", "classIconRight", "classLabel", "iconOnlyType", "popover", "ignoreStopPropagationEvent", "zIndex", "widthLabelPopover", "styleIconLeft", "styleButton", "ignoreFocusWhenInputTab", "ignoreSetClickWhenShowPopover", "ignorePointerEvent", "isActive", "isHandlerEnterDocumentClickButton"], outputs: ["outClick", "outPopoverEvent", "outFunctionsControl"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
1662
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "18.2.14", type: LibsUiComponentsPreviewTextDataComponent, isStandalone: true, selector: "libs_ui-components-preview_text_data", inputs: { content: { classPropertyName: "content", publicName: "content", isSignal: true, isRequired: false, transformFunction: null }, langSelected: { classPropertyName: "langSelected", publicName: "langSelected", isSignal: true, isRequired: true, transformFunction: null }, langsAccept: { classPropertyName: "langsAccept", publicName: "langsAccept", isSignal: true, isRequired: false, transformFunction: null }, langsChangeLabel: { classPropertyName: "langsChangeLabel", publicName: "langsChangeLabel", isSignal: true, isRequired: false, transformFunction: null }, editable: { classPropertyName: "editable", publicName: "editable", isSignal: true, isRequired: false, transformFunction: null }, hiddenAction: { classPropertyName: "hiddenAction", publicName: "hiddenAction", isSignal: true, isRequired: false, transformFunction: null }, minLines: { classPropertyName: "minLines", publicName: "minLines", isSignal: true, isRequired: false, transformFunction: null }, maxLines: { classPropertyName: "maxLines", publicName: "maxLines", isSignal: true, isRequired: false, transformFunction: null }, containerElement: { classPropertyName: "containerElement", publicName: "containerElement", isSignal: true, isRequired: false, transformFunction: null }, zIndexPopover: { classPropertyName: "zIndexPopover", publicName: "zIndexPopover", isSignal: true, isRequired: false, transformFunction: null }, hiddenSearchLang: { classPropertyName: "hiddenSearchLang", publicName: "hiddenSearchLang", isSignal: true, isRequired: false, transformFunction: null }, lintIgnorePatterns: { classPropertyName: "lintIgnorePatterns", publicName: "lintIgnorePatterns", isSignal: true, isRequired: false, transformFunction: null }, completions: { classPropertyName: "completions", publicName: "completions", isSignal: true, isRequired: false, transformFunction: null }, forbiddenPatterns: { classPropertyName: "forbiddenPatterns", publicName: "forbiddenPatterns", isSignal: true, isRequired: false, transformFunction: null }, background: { classPropertyName: "background", publicName: "background", isSignal: true, isRequired: false, transformFunction: null }, showFormatAction: { classPropertyName: "showFormatAction", publicName: "showFormatAction", isSignal: true, isRequired: false, transformFunction: null }, autoFormatOnLoad: { classPropertyName: "autoFormatOnLoad", publicName: "autoFormatOnLoad", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { langSelected: "langSelectedChange", outChange: "outChange", syntaxErrors: "syntaxErrors", outViolations: "outViolations" }, viewQueries: [{ propertyName: "containerPreview", first: true, predicate: ["containerPreview"], descendants: true, isSignal: true }], ngImport: i0, template: "<div\n class=\"libs-ui-preview-data-container flex flex-col w-full h-auto rounded-[8px] libs-ui-border-general px-[8px]\"\n [style.--background-color]=\"background()\"\n [class.pt-[8px]]=\"!hiddenAction()\">\n @if (!hiddenAction()) {\n <div class=\"flex items-center content-between color-[#6a7383]\">\n <libs_ui-components-dropdown\n classInclude=\"w-[200px]\"\n [listConfig]=\"configLoadDataIsHttpConfig()\"\n [listMaxItemShow]=\"5\"\n [zIndex]=\"zIndexPopover()\"\n [isNgContent]=\"true\"\n [readonly]=\"!editable() || !acceptChangeLang()\"\n [listHasButtonUnSelectOption]=\"false\"\n [listHiddenInputSearch]=\"hiddenSearchLang()\"\n (outSelectKey)=\"handlerSelectKey($event)\">\n <libs_ui-components-buttons-button\n [type]=\"'button-link-third'\"\n [label]=\"labelLang() || ''\"\n [sizeButton]=\"'small'\"\n [classIconRight]=\"editable() && acceptChangeLang() ? 'libs-ui-icon-move-right rotate-90' : ''\"\n [classInclude]=\"'!p-[0px]' + (editable() && acceptChangeLang() ? '' : '!pointer-events-none !cursor-default hover:!text-[#6A7383]')\" />\n </libs_ui-components-dropdown>\n <div class=\"flex items-center\">\n <!-- \u0110\u1ECBnh d\u1EA1ng: \u0111\u1EE9ng tr\u01B0\u1EDBc \"Xu\u1ED1ng d\u00F2ng\" v\u00EC n\u00F3 l\u00E0 thao t\u00E1c tr\u00EAn N\u1ED8I DUNG, hai n\u00FAt sau ch\u1EC9 \u0111\u1ED5i\n c\u00E1ch hi\u1EC3n th\u1ECB. Ch\u1EC9 hi\u1EC7n khi \u00F4 s\u1EEDa \u0111\u01B0\u1EE3c v\u00E0 ng\u00F4n ng\u1EEF c\u00F3 b\u1ED9 \u0111\u1ECBnh d\u1EA1ng \u2014 xem `canFormat`. -->\n @if (canFormat()) {\n <libs_ui-components-buttons-button\n [type]=\"'button-link-third'\"\n [label]=\"'i18n_format_code'\"\n [sizeButton]=\"'small'\"\n [classIconLeft]=\"'libs-ui-icon-align-left'\"\n [classInclude]=\"'mo-lib-p-0px mo-lib-mr-16px'\"\n (outClick)=\"handlerFormat()\" />\n }\n <libs_ui-components-buttons-button\n [type]=\"'button-link-third'\"\n [label]=\"isWrap() ? 'i18n_remove_line_wrap' : 'i18n_line_wrap'\"\n [sizeButton]=\"'small'\"\n [classIconLeft]=\"isWrap() ? 'libs-ui-icon-unwrap' : 'libs-ui-icon-wrap'\"\n [classInclude]=\"'mo-lib-p-0px mo-lib-mr-16px'\"\n (outClick)=\"handlerLineWrap()\" />\n <libs_ui-components-buttons-button\n [type]=\"'button-link-third'\"\n [label]=\"'i18n_copy'\"\n [sizeButton]=\"'small'\"\n [classIconLeft]=\"'libs-ui-icon-copy'\"\n [classInclude]=\"'mo-lib-p-0px'\"\n (outClick)=\"handlerCopy()\" />\n </div>\n </div>\n }\n <div #containerPreview></div>\n</div>\n", styles: [":host ::ng-deep .libs-ui-preview-data-container{background-color:var(--background-color)!important}:host ::ng-deep .libs-ui-preview-data-container .cm-line{white-space:pre-wrap}:host ::ng-deep .libs-ui-preview-data-container .cm-lintRange-error{background-color:#ff323233;border-bottom:2px solid red}:host ::ng-deep .libs-ui-preview-data-container .cm-lintRange-warning{background-color:#ffc80026}:host ::ng-deep .libs-ui-preview-data-container .cm-tooltip-lint{background:#fff8f8;color:#d32f2f;border:1px solid #f44336;padding:8px 10px;font-size:13px;font-family:Inter,sans-serif;border-radius:6px;box-shadow:0 2px 8px #ff000026}:host ::ng-deep .libs-ui-preview-data-container .cm-focused{outline:none!important}:host ::ng-deep .libs-ui-preview-data-container .cm-content,:host ::ng-deep .libs-ui-preview-data-container .cm-gutters{font-family:JetBrains Mono,Fira Code,Cascadia Mono,Consolas,DejaVu Sans Mono,monospace;font-size:12px}:host ::ng-deep .libs-ui-preview-data-container .cm-activeLine{background-color:#f4f8ff!important}:host ::ng-deep .libs-ui-preview-data-container .cm-activeLineGutter{background-color:#f4f8ff!important;color:#1a73e8}:host ::ng-deep .libs-ui-preview-data-container .cm-lineNumbers .cm-gutterElement{color:#9aa0a6}:host ::ng-deep .libs-ui-preview-data-container .cm-cursor,:host ::ng-deep .libs-ui-preview-data-container .cm-dropCursor{border-left-color:#1a73e8!important}:host ::ng-deep .libs-ui-preview-data-container .cm-matchingBracket{background-color:#d2e3fc!important;color:inherit!important;font-weight:600}:host ::ng-deep .libs-ui-preview-data-container .cm-nonmatchingBracket{background-color:#fce8e6!important;color:#c5221f!important}:host ::ng-deep .libs-ui-preview-data-container .cm-selectionBackground{background-color:#007aff40!important}:host ::ng-deep .libs-ui-preview-data-container .cm-selectionLayer{z-index:1!important}:host ::ng-deep .libs-ui-preview-data-container .cm-gutters{background-color:var(--background-color)!important}:host ::ng-deep .libs-ui-preview-data-container .cm-tooltip-autocomplete{border:1px solid #e6e7ea;border-radius:6px;background:#fff;box-shadow:0 4px 12px #0f172a1f;overflow:hidden}:host ::ng-deep .libs-ui-preview-data-container .cm-tooltip-autocomplete>ul{max-height:260px;font-family:var(--libs-ui-font-family-name, \"Arial\")}:host ::ng-deep .libs-ui-preview-data-container .cm-tooltip-autocomplete>ul>li{display:flex;align-items:baseline;gap:10px;padding:5px 10px!important;line-height:18px}:host ::ng-deep .libs-ui-preview-data-container .cm-tooltip-autocomplete>ul>li[aria-selected]{background:#e9f1fe;color:#071631}:host ::ng-deep .libs-ui-preview-data-container .cm-tooltip-autocomplete .cm-completionLabel{flex:0 0 auto;font-family:var(--libs-ui-font-family-name, \"Arial\");font-size:12px;font-weight:500;color:#071631}:host ::ng-deep .libs-ui-preview-data-container .cm-tooltip-autocomplete .cm-completionDetail{flex:1 1 auto;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-family:var(--libs-ui-font-family-name, \"Arial\");font-size:11px;font-style:normal;color:#6a7383;text-align:right}:host ::ng-deep .libs-ui-preview-data-container .cm-tooltip-autocomplete .cm-completionIcon{flex:0 0 auto;font-family:var(--libs-ui-font-family-name, \"Arial\");opacity:.5}:host ::ng-deep .libs-ui-preview-data-container .cm-completionInfo{border:1px solid #e6e7ea;border-radius:6px;background:#fff;padding:8px 10px;font-family:var(--libs-ui-font-family-name, \"Arial\");font-size:11px;color:#6a7383}\n"], dependencies: [{ kind: "component", type: LibsUiComponentsDropdownComponent, selector: "libs_ui-components-dropdown", inputs: ["useXssFilter", "popoverElementRefCustom", "classInclude", "ignoreStopPropagationEvent", "flagMouse", "flagMouseContent", "popoverCustomConfig", "isNgContent", "zIndex", "convertItemSelected", "getPopoverItemSelected", "httpRequestDetailItemById", "lengthKeys", "textDisplayWhenNoSelect", "textDisplayWhenMultiSelect", "classIncludeTextDisplayWhenNoSelect", "fieldLabel", "fieldGetLabel", "labelPopoverConfig", "labelPopoverFullWidth", "hasContentUnitRight", "listSearchNoDataTemplateRef", "dropdownTemplateRefNotSearchNoData", "fieldGetImage", "imageSize", "typeShape", "fieldGetIcon", "fieldGetTextAvatar", "fieldGetColorAvatar", "classAvatarInclude", "getLastTextAfterSpace", "linkImageError", "showError", "showBorderError", "disable", "readonly", "labelConfig", "disableLabel", "listSearchConfig", "isSearchOnline", "listHiddenInputSearch", "listSearchPadding", "listKeySearch", "listDividerClassInclude", "listConfig", "listButtonsOther", "listHasButtonUnSelectOption", "listClickExactly", "listBackgroundCustom", "listMaxItemShow", "listKeySelected", "listMultiKeySelected", "listKeysDisable", "listKeysHidden", "validRequired", "validMaxItemSelected", "changeValidUndefinedResetError", "allowSelectItemMultiple", "focusInputSearch", "onlyEmitDataWhenReset", "onlyEmitMultiKeyWhenManualClick", "resetKeyWhenSelectAllKey", "listConfigHasDivider", "classIncludeIcon", "classIncludeContent", "listIgnoreClassDisableDefaultWhenUseKeysDisableItem", "tabKeyActive", "tabsConfig", "ignoreBorderBottom"], outputs: ["flagMouseChange", "flagMouseContentChange", "lengthKeysChange", "showBorderErrorChange", "listKeySelectedChange", "listMultiKeySelectedChange", "tabKeyActiveChange", "outSelectKey", "outSelectMultiKey", "outFunctionsControl", "outValidEvent", "outChangStageFlagMouse", "outDataChange", "outClickButtonOther", "outShowList", "outChangeTabKeyActive"] }, { kind: "component", type: LibsUiComponentsButtonsButtonComponent, selector: "libs_ui-components-buttons-button", inputs: ["flagMouse", "type", "buttonCustom", "sizeButton", "label", "disable", "isPending", "imageLeft", "classInclude", "classIconLeft", "classIconRight", "classLabel", "iconOnlyType", "popover", "ignoreStopPropagationEvent", "zIndex", "widthLabelPopover", "styleIconLeft", "styleButton", "ignoreFocusWhenInputTab", "ignoreSetClickWhenShowPopover", "ignorePointerEvent", "isActive", "isHandlerEnterDocumentClickButton"], outputs: ["outClick", "outPopoverEvent", "outFunctionsControl"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
1203
1663
|
}
|
|
1204
1664
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: LibsUiComponentsPreviewTextDataComponent, decorators: [{
|
|
1205
1665
|
type: Component,
|
|
1206
|
-
args: [{ selector: 'libs_ui-components-preview_text_data', standalone: true, changeDetection: ChangeDetectionStrategy.OnPush, imports: [LibsUiComponentsDropdownComponent, LibsUiComponentsButtonsButtonComponent], template: "<div\n class=\"libs-ui-preview-data-container flex flex-col w-full h-auto rounded-[8px] libs-ui-border-general px-[8px]\"\n [style.--background-color]=\"background()\"\n [class.pt-[8px]]=\"!hiddenAction()\">\n @if (!hiddenAction()) {\n <div class=\"flex items-center content-between color-[#6a7383]\">\n <libs_ui-components-dropdown\n classInclude=\"w-[200px]\"\n [listConfig]=\"configLoadDataIsHttpConfig()\"\n [listMaxItemShow]=\"5\"\n [zIndex]=\"zIndexPopover()\"\n [isNgContent]=\"true\"\n [readonly]=\"!editable() || !acceptChangeLang()\"\n [listHasButtonUnSelectOption]=\"false\"\n [listHiddenInputSearch]=\"hiddenSearchLang()\"\n (outSelectKey)=\"handlerSelectKey($event)\">\n <libs_ui-components-buttons-button\n [type]=\"'button-link-third'\"\n [label]=\"labelLang() || ''\"\n [sizeButton]=\"'small'\"\n [classIconRight]=\"editable() && acceptChangeLang() ? 'libs-ui-icon-move-right rotate-90' : ''\"\n [classInclude]=\"'!p-[0px]' + (editable() && acceptChangeLang() ? '' : '!pointer-events-none !cursor-default hover:!text-[#6A7383]')\" />\n </libs_ui-components-dropdown>\n <div class=\"flex items-center\">\n <libs_ui-components-buttons-button\n [type]=\"'button-link-third'\"\n [label]=\"isWrap() ? 'i18n_remove_line_wrap' : 'i18n_line_wrap'\"\n [sizeButton]=\"'small'\"\n [classIconLeft]=\"isWrap() ? 'libs-ui-icon-unwrap' : 'libs-ui-icon-wrap'\"\n [classInclude]=\"'mo-lib-p-0px mo-lib-mr-16px'\"\n (outClick)=\"handlerLineWrap()\" />\n <libs_ui-components-buttons-button\n [type]=\"'button-link-third'\"\n [label]=\"'i18n_copy'\"\n [sizeButton]=\"'small'\"\n [classIconLeft]=\"'libs-ui-icon-copy'\"\n [classInclude]=\"'mo-lib-p-0px'\"\n (outClick)=\"handlerCopy()\" />\n </div>\n </div>\n }\n <div #containerPreview></div>\n</div>\n", styles: [":host ::ng-deep .libs-ui-preview-data-container{background-color:var(--background-color)!important}:host ::ng-deep .libs-ui-preview-data-container .cm-line{white-space:pre-wrap}:host ::ng-deep .libs-ui-preview-data-container .cm-lintRange-error{background-color:#ff323233;border-bottom:2px solid red}:host ::ng-deep .libs-ui-preview-data-container .cm-lintRange-warning{background-color:#ffc80026}:host ::ng-deep .libs-ui-preview-data-container .cm-tooltip-lint{background:#fff8f8;color:#d32f2f;border:1px solid #f44336;padding:8px 10px;font-size:13px;font-family:Inter,sans-serif;border-radius:6px;box-shadow:0 2px 8px #ff000026}:host ::ng-deep .libs-ui-preview-data-container .cm-focused{outline:none!important}:host ::ng-deep .libs-ui-preview-data-container .cm-selectionBackground{background-color:#007aff40!important}:host ::ng-deep .libs-ui-preview-data-container .cm-selectionLayer{z-index:1!important}:host ::ng-deep .libs-ui-preview-data-container .cm-gutters{background-color:var(--background-color)!important}\n"] }]
|
|
1666
|
+
args: [{ selector: 'libs_ui-components-preview_text_data', standalone: true, changeDetection: ChangeDetectionStrategy.OnPush, imports: [LibsUiComponentsDropdownComponent, LibsUiComponentsButtonsButtonComponent], template: "<div\n class=\"libs-ui-preview-data-container flex flex-col w-full h-auto rounded-[8px] libs-ui-border-general px-[8px]\"\n [style.--background-color]=\"background()\"\n [class.pt-[8px]]=\"!hiddenAction()\">\n @if (!hiddenAction()) {\n <div class=\"flex items-center content-between color-[#6a7383]\">\n <libs_ui-components-dropdown\n classInclude=\"w-[200px]\"\n [listConfig]=\"configLoadDataIsHttpConfig()\"\n [listMaxItemShow]=\"5\"\n [zIndex]=\"zIndexPopover()\"\n [isNgContent]=\"true\"\n [readonly]=\"!editable() || !acceptChangeLang()\"\n [listHasButtonUnSelectOption]=\"false\"\n [listHiddenInputSearch]=\"hiddenSearchLang()\"\n (outSelectKey)=\"handlerSelectKey($event)\">\n <libs_ui-components-buttons-button\n [type]=\"'button-link-third'\"\n [label]=\"labelLang() || ''\"\n [sizeButton]=\"'small'\"\n [classIconRight]=\"editable() && acceptChangeLang() ? 'libs-ui-icon-move-right rotate-90' : ''\"\n [classInclude]=\"'!p-[0px]' + (editable() && acceptChangeLang() ? '' : '!pointer-events-none !cursor-default hover:!text-[#6A7383]')\" />\n </libs_ui-components-dropdown>\n <div class=\"flex items-center\">\n <!-- \u0110\u1ECBnh d\u1EA1ng: \u0111\u1EE9ng tr\u01B0\u1EDBc \"Xu\u1ED1ng d\u00F2ng\" v\u00EC n\u00F3 l\u00E0 thao t\u00E1c tr\u00EAn N\u1ED8I DUNG, hai n\u00FAt sau ch\u1EC9 \u0111\u1ED5i\n c\u00E1ch hi\u1EC3n th\u1ECB. Ch\u1EC9 hi\u1EC7n khi \u00F4 s\u1EEDa \u0111\u01B0\u1EE3c v\u00E0 ng\u00F4n ng\u1EEF c\u00F3 b\u1ED9 \u0111\u1ECBnh d\u1EA1ng \u2014 xem `canFormat`. -->\n @if (canFormat()) {\n <libs_ui-components-buttons-button\n [type]=\"'button-link-third'\"\n [label]=\"'i18n_format_code'\"\n [sizeButton]=\"'small'\"\n [classIconLeft]=\"'libs-ui-icon-align-left'\"\n [classInclude]=\"'mo-lib-p-0px mo-lib-mr-16px'\"\n (outClick)=\"handlerFormat()\" />\n }\n <libs_ui-components-buttons-button\n [type]=\"'button-link-third'\"\n [label]=\"isWrap() ? 'i18n_remove_line_wrap' : 'i18n_line_wrap'\"\n [sizeButton]=\"'small'\"\n [classIconLeft]=\"isWrap() ? 'libs-ui-icon-unwrap' : 'libs-ui-icon-wrap'\"\n [classInclude]=\"'mo-lib-p-0px mo-lib-mr-16px'\"\n (outClick)=\"handlerLineWrap()\" />\n <libs_ui-components-buttons-button\n [type]=\"'button-link-third'\"\n [label]=\"'i18n_copy'\"\n [sizeButton]=\"'small'\"\n [classIconLeft]=\"'libs-ui-icon-copy'\"\n [classInclude]=\"'mo-lib-p-0px'\"\n (outClick)=\"handlerCopy()\" />\n </div>\n </div>\n }\n <div #containerPreview></div>\n</div>\n", styles: [":host ::ng-deep .libs-ui-preview-data-container{background-color:var(--background-color)!important}:host ::ng-deep .libs-ui-preview-data-container .cm-line{white-space:pre-wrap}:host ::ng-deep .libs-ui-preview-data-container .cm-lintRange-error{background-color:#ff323233;border-bottom:2px solid red}:host ::ng-deep .libs-ui-preview-data-container .cm-lintRange-warning{background-color:#ffc80026}:host ::ng-deep .libs-ui-preview-data-container .cm-tooltip-lint{background:#fff8f8;color:#d32f2f;border:1px solid #f44336;padding:8px 10px;font-size:13px;font-family:Inter,sans-serif;border-radius:6px;box-shadow:0 2px 8px #ff000026}:host ::ng-deep .libs-ui-preview-data-container .cm-focused{outline:none!important}:host ::ng-deep .libs-ui-preview-data-container .cm-content,:host ::ng-deep .libs-ui-preview-data-container .cm-gutters{font-family:JetBrains Mono,Fira Code,Cascadia Mono,Consolas,DejaVu Sans Mono,monospace;font-size:12px}:host ::ng-deep .libs-ui-preview-data-container .cm-activeLine{background-color:#f4f8ff!important}:host ::ng-deep .libs-ui-preview-data-container .cm-activeLineGutter{background-color:#f4f8ff!important;color:#1a73e8}:host ::ng-deep .libs-ui-preview-data-container .cm-lineNumbers .cm-gutterElement{color:#9aa0a6}:host ::ng-deep .libs-ui-preview-data-container .cm-cursor,:host ::ng-deep .libs-ui-preview-data-container .cm-dropCursor{border-left-color:#1a73e8!important}:host ::ng-deep .libs-ui-preview-data-container .cm-matchingBracket{background-color:#d2e3fc!important;color:inherit!important;font-weight:600}:host ::ng-deep .libs-ui-preview-data-container .cm-nonmatchingBracket{background-color:#fce8e6!important;color:#c5221f!important}:host ::ng-deep .libs-ui-preview-data-container .cm-selectionBackground{background-color:#007aff40!important}:host ::ng-deep .libs-ui-preview-data-container .cm-selectionLayer{z-index:1!important}:host ::ng-deep .libs-ui-preview-data-container .cm-gutters{background-color:var(--background-color)!important}:host ::ng-deep .libs-ui-preview-data-container .cm-tooltip-autocomplete{border:1px solid #e6e7ea;border-radius:6px;background:#fff;box-shadow:0 4px 12px #0f172a1f;overflow:hidden}:host ::ng-deep .libs-ui-preview-data-container .cm-tooltip-autocomplete>ul{max-height:260px;font-family:var(--libs-ui-font-family-name, \"Arial\")}:host ::ng-deep .libs-ui-preview-data-container .cm-tooltip-autocomplete>ul>li{display:flex;align-items:baseline;gap:10px;padding:5px 10px!important;line-height:18px}:host ::ng-deep .libs-ui-preview-data-container .cm-tooltip-autocomplete>ul>li[aria-selected]{background:#e9f1fe;color:#071631}:host ::ng-deep .libs-ui-preview-data-container .cm-tooltip-autocomplete .cm-completionLabel{flex:0 0 auto;font-family:var(--libs-ui-font-family-name, \"Arial\");font-size:12px;font-weight:500;color:#071631}:host ::ng-deep .libs-ui-preview-data-container .cm-tooltip-autocomplete .cm-completionDetail{flex:1 1 auto;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-family:var(--libs-ui-font-family-name, \"Arial\");font-size:11px;font-style:normal;color:#6a7383;text-align:right}:host ::ng-deep .libs-ui-preview-data-container .cm-tooltip-autocomplete .cm-completionIcon{flex:0 0 auto;font-family:var(--libs-ui-font-family-name, \"Arial\");opacity:.5}:host ::ng-deep .libs-ui-preview-data-container .cm-completionInfo{border:1px solid #e6e7ea;border-radius:6px;background:#fff;padding:8px 10px;font-family:var(--libs-ui-font-family-name, \"Arial\");font-size:11px;color:#6a7383}\n"] }]
|
|
1207
1667
|
}], ctorParameters: () => [] });
|
|
1208
1668
|
|
|
1209
1669
|
/**
|
|
1210
1670
|
* Generated bundle index. Do not edit.
|
|
1211
1671
|
*/
|
|
1212
1672
|
|
|
1213
|
-
export { DEFAULT_SECURITY_PATTERNS, LibsUiComponentsPreviewTextDataComponent, astSkipKeys, astTypeKeys, createDefaultLanguage, httpRequestConfigGetOptionsLang, languageRegistry, optionsLangData, tsValueNodes };
|
|
1673
|
+
export { DEFAULT_SECURITY_PATTERNS, DEFAULT_SQL_FORBIDDEN_PATTERNS, FORMATTABLE_LANGUAGES, LibsUiComponentsPreviewTextDataComponent, astSkipKeys, astTypeKeys, createDefaultLanguage, formatByLanguage, httpRequestConfigGetOptionsLang, languageRegistry, optionsLangData, sqlFormat, sqlNormalizeForCompare, sqlSplitPreservingLiterals, tsValueNodes };
|
|
1214
1674
|
//# sourceMappingURL=libs-ui-components-preview-text-data.mjs.map
|