@dotglitch/ngx-common 1.0.48 → 1.0.49

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.
@@ -1092,24 +1092,133 @@ const saveObjectAsFile = (name, data) => {
1092
1092
  a.click();
1093
1093
  a.remove();
1094
1094
  };
1095
+ class Emoticon {
1096
+ constructor(icon) {
1097
+ this.icon = icon;
1098
+ }
1099
+ }
1100
+ /**
1101
+ * authorization 🔐 \
1102
+ * user 🪪 \
1103
+ * security 🛡 \
1104
+ * system 🖥 \
1105
+ * toolbox 🧰 \
1106
+ * chore ⚙ \
1107
+ * config 🛠 \
1108
+ * renderer 📐 \
1109
+ * package 📦 \
1110
+ * time ⏳ \
1111
+ * download 📥 \
1112
+ * upload 📤 \
1113
+ * bug 🦠 \
1114
+ * bomb 💣 \
1115
+ * tnt 🧨 \
1116
+ * warning ⚠️ \
1117
+ * chart 📊 \
1118
+ * chart_up 📈 \
1119
+ * chart_down 📉 \
1120
+ * circle_red 🔴 \
1121
+ * circle_orange 🟠 \
1122
+ * circle_yellow 🟡 \
1123
+ * circle_green 🟢 \
1124
+ * circle_blue 🔵 \
1125
+ * circle_violet 🟣 \
1126
+ * circle_black ⚫️ \
1127
+ * circle_white ⚪️ \
1128
+ * circle_brown 🟤 \
1129
+ * square_red 🟥 \
1130
+ * square_orange 🟧 \
1131
+ * square_yellow 🟨 \
1132
+ * square_green 🟩 \
1133
+ * square_blue 🟦 \
1134
+ * square_violet 🟪 \
1135
+ * square_black ⬛️ \
1136
+ * square_white ⬜️ \
1137
+ * square_brown 🟫
1138
+ */
1139
+ const LogIcon = {
1140
+ authorization: new Emoticon("🔐"),
1141
+ user: new Emoticon("🪪"),
1142
+ security: new Emoticon("🛡"),
1143
+ system: new Emoticon("🖥"),
1144
+ toolbox: new Emoticon("🧰"),
1145
+ chore: new Emoticon("⚙"),
1146
+ config: new Emoticon("🛠"),
1147
+ renderer: new Emoticon("📐"),
1148
+ package: new Emoticon("📦"),
1149
+ time: new Emoticon("⏳"),
1150
+ download: new Emoticon("📥"),
1151
+ upload: new Emoticon("📤"),
1152
+ bug: new Emoticon("🦠"),
1153
+ bomb: new Emoticon("💣"),
1154
+ tnt: new Emoticon("🧨"),
1155
+ warning: new Emoticon("⚠️"),
1156
+ chart: new Emoticon("📊"),
1157
+ chart_up: new Emoticon("📈"),
1158
+ chart_down: new Emoticon("📉"),
1159
+ circle_red: new Emoticon("🔴"),
1160
+ circle_orange: new Emoticon("🟠"),
1161
+ circle_yellow: new Emoticon("🟡"),
1162
+ circle_green: new Emoticon("🟢"),
1163
+ circle_blue: new Emoticon("🔵"),
1164
+ circle_violet: new Emoticon("🟣"),
1165
+ circle_black: new Emoticon("⚫️"),
1166
+ circle_white: new Emoticon("⚪️"),
1167
+ circle_brown: new Emoticon("🟤"),
1168
+ square_red: new Emoticon("🟥"),
1169
+ square_orange: new Emoticon("🟧"),
1170
+ square_yellow: new Emoticon("🟨"),
1171
+ square_green: new Emoticon("🟩"),
1172
+ square_blue: new Emoticon("🟦"),
1173
+ square_violet: new Emoticon("🟪"),
1174
+ square_black: new Emoticon("⬛️"),
1175
+ square_white: new Emoticon("⬜️"),
1176
+ square_brown: new Emoticon("🟫")
1177
+ };
1178
+ class Log {
1179
+ constructor(context, contextColor, textColor) {
1180
+ this.context = context;
1181
+ this.contextColor = contextColor;
1182
+ this.textColor = textColor;
1183
+ }
1184
+ log(iconOrMessage, messageText, ...args) {
1185
+ if (iconOrMessage instanceof Emoticon) {
1186
+ console.log(`${iconOrMessage} %c[${this.context}] %c${messageText}`, 'color: ' + this.contextColor, 'color: ' + this.textColor, ...args);
1187
+ }
1188
+ else {
1189
+ console.log(`%c[${this.context}] %c${iconOrMessage}`, 'color: ' + this.contextColor, 'color: ' + this.textColor, ...args);
1190
+ }
1191
+ }
1192
+ warn(iconOrMessage, messageText, ...args) {
1193
+ if (iconOrMessage instanceof Emoticon) {
1194
+ console.warn(`${iconOrMessage} %c[${this.context}] %c${messageText}`, 'color: ' + this.contextColor, 'color: ' + this.textColor, ...args);
1195
+ }
1196
+ else {
1197
+ console.warn(`%c[${this.context}] %c${iconOrMessage}`, 'color: ' + this.contextColor, 'color: ' + this.textColor, ...args);
1198
+ }
1199
+ }
1200
+ err(iconOrMessage, messageText, ...args) {
1201
+ if (iconOrMessage instanceof Emoticon) {
1202
+ console.error(`${iconOrMessage} %c[${this.context}] %c${messageText}`, 'color: ' + this.contextColor, 'color: ' + this.textColor, ...args);
1203
+ }
1204
+ else {
1205
+ console.error(`%c[${this.context}] %c${iconOrMessage}`, 'color: ' + this.contextColor, 'color: ' + this.textColor, ...args);
1206
+ }
1207
+ }
1208
+ error(iconOrMessage, messageText, ...args) {
1209
+ if (iconOrMessage instanceof Emoticon) {
1210
+ console.error(`${iconOrMessage} %c[${this.context}] %c${messageText}`, 'color: ' + this.contextColor, 'color: ' + this.textColor, ...args);
1211
+ }
1212
+ else {
1213
+ console.error(`%c[${this.context}] %c${iconOrMessage}`, 'color: ' + this.contextColor, 'color: ' + this.textColor, ...args);
1214
+ }
1215
+ }
1216
+ }
1095
1217
  /**
1096
1218
  * Formatted logger that will print a bit of context before the message.
1097
1219
  * @returns
1098
1220
  */
1099
- const Logger = (context, contextColor, textColor = "#03a9f4") => ({
1100
- log: (message, ...args) => {
1101
- console.log(`%c[${context}] %c${message}`, 'color: ' + contextColor, 'color: ' + textColor, ...args);
1102
- },
1103
- warn: (message, ...args) => {
1104
- console.warn(`%c[${context}] %c${message}`, 'color: ' + contextColor, 'color: ' + textColor, ...args);
1105
- },
1106
- err: (message, ...args) => {
1107
- console.error(`%c[${context}] %c${message}`, 'color: ' + contextColor, 'color: ' + textColor, ...args);
1108
- },
1109
- error: (message, ...args) => {
1110
- console.error(`%c[${context}] %c${message}`, 'color: ' + contextColor, 'color: ' + textColor, ...args);
1111
- }
1112
- });
1221
+ const ConsoleLogger = (context, contextColor, textColor = "#03a9f4") => new Log(context, contextColor, textColor);
1113
1222
  /**
1114
1223
  * Convert a string `fooBAR baz_160054''"1]"` into a slug: `foobar-baz-1600541`
1115
1224
  */
@@ -1118,6 +1227,54 @@ const stringToSlug = (text) => (text || '')
1118
1227
  .toLowerCase()
1119
1228
  .replace(/[\-_+ ]/g, '-')
1120
1229
  .replace(/[^a-z0-9\-]/g, '');
1230
+ /**
1231
+ * Helper to update the page URL.
1232
+ * @param page component page ID to load.
1233
+ * @param data string or JSON data for query params.
1234
+ */
1235
+ const updateUrl = (page, data = {}, replaceState = false) => {
1236
+ const [oldHash, qstring] = location.hash.split('?');
1237
+ if (!page)
1238
+ page = oldHash.split('/')[1];
1239
+ const hash = `#/${page}`;
1240
+ // Convert the data object to JSON.
1241
+ if (data instanceof URLSearchParams) {
1242
+ data = [...data.entries()].map(([k, v]) => ({ [k]: v })).reduce((a, b) => (Object.assign(Object.assign({}, a), b)), {});
1243
+ }
1244
+ const query = new URLSearchParams(data);
1245
+ const prevParams = new URLSearchParams(qstring);
1246
+ // If the hash is the same, retain params.
1247
+ if (hash == oldHash) {
1248
+ replaceState = true;
1249
+ for (const [key, value] of prevParams.entries())
1250
+ if (!query.has(key))
1251
+ query.set(key, prevParams.get(key));
1252
+ }
1253
+ for (const [key, val] of query.entries()) {
1254
+ if (val == null ||
1255
+ val == undefined ||
1256
+ val == '' ||
1257
+ val == 'null' ||
1258
+ Number.isNaN(val) ||
1259
+ val == 'NaN')
1260
+ query.delete(key);
1261
+ }
1262
+ if (!(hash.toLowerCase() == "#/frame") || data['id'] == -1)
1263
+ query.delete('id');
1264
+ const strQuery = query.toString();
1265
+ console.log(data, hash, strQuery);
1266
+ if (replaceState) {
1267
+ window.history.replaceState(data, '', hash + (strQuery ? ('?' + strQuery) : ''));
1268
+ }
1269
+ else {
1270
+ window.history.pushState(data, '', hash + (strQuery ? ('?' + strQuery) : ''));
1271
+ }
1272
+ };
1273
+ const getUrlData = (source = window.location.hash) => {
1274
+ const [hash, query] = source.split('?');
1275
+ let data = new URLSearchParams(query);
1276
+ return [...data.entries()].map(([k, v]) => ({ [k]: v })).reduce((a, b) => (Object.assign(Object.assign({}, a), b)), {});
1277
+ };
1121
1278
 
1122
1279
  const SCRIPT_INIT_TIMEOUT = 500; // ms
1123
1280
  /**
@@ -1212,7 +1369,7 @@ class LazyLoaderService {
1212
1369
  }
1213
1370
  static configure(config) {
1214
1371
  var _a;
1215
- const { log, warn, err } = Logger("ngx-lazy-loader", "#009688");
1372
+ const { log, warn, err } = ConsoleLogger("ngx-lazy-loader", "#009688");
1216
1373
  this.config = Object.assign({ componentResolveStrategy: ComponentResolveStrategy.PickFirst, logger: {
1217
1374
  log,
1218
1375
  warn,
@@ -1772,7 +1929,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
1772
1929
  type: Output
1773
1930
  }] } });
1774
1931
 
1775
- const { log: log$1, warn: warn$1, err: err$1 } = Logger("DialogService", "#607d8b");
1932
+ const { log: log$1, warn: warn$1, err: err$1 } = ConsoleLogger("DialogService", "#607d8b");
1776
1933
  class DialogService {
1777
1934
  constructor(dialog, lazyLoader) {
1778
1935
  this.dialog = dialog;
@@ -2076,7 +2233,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
2076
2233
  }]
2077
2234
  }], ctorParameters: function () { return []; } });
2078
2235
 
2079
- const { log, warn, err } = Logger("NavigationService", "#ff9800");
2236
+ const { log, warn, err } = ConsoleLogger("NavigationService", "#ff9800");
2080
2237
  class NavigationService {
2081
2238
  constructor(lazyLoader) {
2082
2239
  this.lazyLoader = lazyLoader;
@@ -10650,5 +10807,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
10650
10807
  * Generated bundle index. Do not edit.
10651
10808
  */
10652
10809
 
10653
- export { ComponentResolveStrategy, DependencyService, DialogService, DynamicHTMLComponent, DynamicHTMLOptions, DynamicHTMLRenderer, Fetch, FileService, FilemanagerComponent, HtmlBypass, InstallMonacoUMD, KeyboardService, LazyLoaderComponent, LazyLoaderModule, LazyLoaderService, MenuDirective, NGX_DYNAMIC_CONFIG, NGX_LAZY_LOADER_CONFIG, NGX_WEB_COMPONENTS_CONFIG, NavigationService, NgxDynamicHTMLModule, OnMount, ReactMagicWrapperComponent, ResourceBypass, ScriptBypass, StyleBypass, TabulatorComponent, ThemeService, TooltipDirective, UrlBypass, VscodeComponent, openMenu, openTooltip };
10810
+ export { ComponentResolveStrategy, ConsoleLogger, DependencyService, DialogService, DynamicHTMLComponent, DynamicHTMLOptions, DynamicHTMLRenderer, Fetch, FileService, FilemanagerComponent, HtmlBypass, InstallMonacoUMD, KeyboardService, LazyLoaderComponent, LazyLoaderModule, LazyLoaderService, LogIcon, MenuDirective, NGX_DYNAMIC_CONFIG, NGX_LAZY_LOADER_CONFIG, NGX_WEB_COMPONENTS_CONFIG, NavigationService, NgxDynamicHTMLModule, OnMount, ReactMagicWrapperComponent, ResourceBypass, ScriptBypass, StyleBypass, TabulatorComponent, ThemeService, TooltipDirective, UrlBypass, VscodeComponent, openMenu, openTooltip };
10654
10811
  //# sourceMappingURL=dotglitch-ngx-common.mjs.map