@karta.io/utils 1.0.0-beta.38 → 1.0.0-beta.39

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/dist/index.cjs CHANGED
@@ -1010,9 +1010,20 @@ function useGlobalScroll() {
1010
1010
 
1011
1011
  const CONFIRM_TEXT = "Are you sure you want to close? \nAll changes will be lost.";
1012
1012
  let dialogs = [];
1013
- function useDialog() {
1014
- let appContext;
1013
+ const HASH_PREFIX = "#ud_";
1014
+ function useDialog(options) {
1015
1015
  const logger = useLogger("use-dialog");
1016
+ let hashPrefix = HASH_PREFIX;
1017
+ if (options?.hashPrefix) {
1018
+ if (options.hashPrefix.charAt(0) === "#") {
1019
+ hashPrefix = options?.hashPrefix;
1020
+ } else {
1021
+ logger.warn(
1022
+ `*hashPrefix* must start with "#". The default prefix "${HASH_PREFIX}" will be used`
1023
+ );
1024
+ }
1025
+ }
1026
+ let appContext;
1016
1027
  const {
1017
1028
  isLocked: isGlobalScrollLocked,
1018
1029
  lock: lockGlobalScroll,
@@ -1020,15 +1031,26 @@ function useDialog() {
1020
1031
  } = useGlobalScroll();
1021
1032
  const route = vueRouter.useRoute();
1022
1033
  const router = vueRouter.useRouter();
1023
- const HASH_PREFIX = "#ud_";
1034
+ const genHash = ({
1035
+ layer = 0,
1036
+ componentName,
1037
+ props
1038
+ }) => {
1039
+ const data = {
1040
+ name: componentName,
1041
+ layer,
1042
+ props
1043
+ };
1044
+ return `${hashPrefix}${window.btoa(JSON.stringify(data))}`;
1045
+ };
1024
1046
  const parseHash = (hash, componentName) => {
1025
1047
  if (!hash)
1026
1048
  return void 0;
1027
- if (!hash.includes(HASH_PREFIX))
1049
+ if (!hash.includes(hashPrefix))
1028
1050
  return void 0;
1029
1051
  let dataFromHash;
1030
1052
  try {
1031
- dataFromHash = JSON.parse(window.atob(hash.slice(HASH_PREFIX.length)));
1053
+ dataFromHash = JSON.parse(window.atob(hash.slice(hashPrefix.length)));
1032
1054
  } catch (_error) {
1033
1055
  logger.warn("*parseHash* cant parse hash");
1034
1056
  }
@@ -1076,7 +1098,7 @@ function useDialog() {
1076
1098
  vnode2.component.props.modelValue = value;
1077
1099
  if (!value && route?.hash) {
1078
1100
  const dataFromHash = parseHash(route.hash, component.name);
1079
- if (dataFromHash)
1101
+ if (dataFromHash?.layer === layer)
1080
1102
  clearHash();
1081
1103
  }
1082
1104
  if (!value && (dialogs.length === 1 || layer === 0) && isGlobalScrollLocked.value) {
@@ -1092,7 +1114,7 @@ function useDialog() {
1092
1114
  if (!route?.hash)
1093
1115
  return;
1094
1116
  const dataFromHash = parseHash(route.hash, component.name);
1095
- if (dataFromHash)
1117
+ if (dataFromHash?.layer === layer)
1096
1118
  clearHash();
1097
1119
  };
1098
1120
  vnode2.props.onDestroy = () => {
@@ -1185,15 +1207,10 @@ function useDialog() {
1185
1207
  component,
1186
1208
  props
1187
1209
  }) => {
1188
- const data = {
1189
- name: component.name,
1190
- layer,
1191
- props
1192
- };
1193
1210
  router.push({
1194
1211
  name: route.name || void 0,
1195
1212
  query: route.query,
1196
- hash: `${HASH_PREFIX}${window.btoa(JSON.stringify(data))}`
1213
+ hash: genHash({ layer, props, componentName: component.name })
1197
1214
  });
1198
1215
  };
1199
1216
  const watchHash = ({
@@ -1243,6 +1260,9 @@ function useDialog() {
1243
1260
  closeAll,
1244
1261
  showConfirm,
1245
1262
  isOnTop,
1263
+ genHash,
1264
+ parseHash,
1265
+ clearHash,
1246
1266
  openByHash,
1247
1267
  watchHash
1248
1268
  };
package/dist/index.d.cts CHANGED
@@ -269,7 +269,21 @@ declare function useDetectBrowser(versions: VersionsList, userAgent?: any): Brow
269
269
  interface VNodeCustom$1 extends VNode {
270
270
  close: () => void;
271
271
  }
272
- declare function useDialog(): {
272
+ interface Dialog {
273
+ uuid: string;
274
+ name?: string;
275
+ vnode: VNodeCustom$1;
276
+ layer: number;
277
+ }
278
+ interface DialogOptions {
279
+ hashPrefix?: string;
280
+ }
281
+ interface DialogParseHashResult {
282
+ name: string;
283
+ layer: number;
284
+ [key: string]: any;
285
+ }
286
+ declare function useDialog(options?: DialogOptions): {
273
287
  open: ({ layer, component, props, }: {
274
288
  component: Component;
275
289
  props?: any;
@@ -281,6 +295,13 @@ declare function useDialog(): {
281
295
  closeAll: () => void;
282
296
  showConfirm: (text?: string) => boolean;
283
297
  isOnTop: (uuid: string) => boolean;
298
+ genHash: ({ layer, componentName, props, }: {
299
+ componentName: string;
300
+ props?: any;
301
+ layer?: number;
302
+ }) => string;
303
+ parseHash: (hash: string, componentName: string) => DialogParseHashResult | undefined;
304
+ clearHash: () => void;
284
305
  openByHash: ({ layer, component, props, }: {
285
306
  component: Component;
286
307
  props?: any;
@@ -369,4 +390,4 @@ declare function isTypeUrl(message?: string): RuleItem;
369
390
  declare function isTypeNumber(value?: number, message?: string): RuleItem;
370
391
  declare function isStrictLength(value?: number, message?: string): RuleItem;
371
392
 
372
- export { AppComponentsResolver, type BrowserInfo, type Dictionary, EnrichError, type ResponseError, UiComponentsResolver, type VersionsList, camelizeKeys, convertEnumToOptions, formatErrorDataMessage, formatErrorForNotify, formatMoney, genHash, genRandomNumber, genUUID, getCardNumber, getCountryFromPhone, getPaginationLimit, getPaginationOffset, getPaginationPages, getPaginationParams, getStatusMessage, isElementIgnored, isEmptyObject, isHtml, isMax, isMin, isRequired, isStrictLength, isTypeEmail, isTypeNumber, isTypeUrl, mapDataObjectForFilters, parsePhone, snakelizeKeys, unformatNumber, useAbortController, useAsyncItems, useAsyncMultiselect, useAsyncSelect, useBreakpoint, useClassName, useDayjs, useDetectBrowser, useDialog, useFilters, useGlobalScroll, useLogger, usePanel, validateNumber, validatePhone };
393
+ export { AppComponentsResolver, type BrowserInfo, type Dialog, type DialogOptions, type DialogParseHashResult, type Dictionary, EnrichError, type ResponseError, UiComponentsResolver, type VersionsList, camelizeKeys, convertEnumToOptions, formatErrorDataMessage, formatErrorForNotify, formatMoney, genHash, genRandomNumber, genUUID, getCardNumber, getCountryFromPhone, getPaginationLimit, getPaginationOffset, getPaginationPages, getPaginationParams, getStatusMessage, isElementIgnored, isEmptyObject, isHtml, isMax, isMin, isRequired, isStrictLength, isTypeEmail, isTypeNumber, isTypeUrl, mapDataObjectForFilters, parsePhone, snakelizeKeys, unformatNumber, useAbortController, useAsyncItems, useAsyncMultiselect, useAsyncSelect, useBreakpoint, useClassName, useDayjs, useDetectBrowser, useDialog, useFilters, useGlobalScroll, useLogger, usePanel, validateNumber, validatePhone };
package/dist/index.d.mts CHANGED
@@ -269,7 +269,21 @@ declare function useDetectBrowser(versions: VersionsList, userAgent?: any): Brow
269
269
  interface VNodeCustom$1 extends VNode {
270
270
  close: () => void;
271
271
  }
272
- declare function useDialog(): {
272
+ interface Dialog {
273
+ uuid: string;
274
+ name?: string;
275
+ vnode: VNodeCustom$1;
276
+ layer: number;
277
+ }
278
+ interface DialogOptions {
279
+ hashPrefix?: string;
280
+ }
281
+ interface DialogParseHashResult {
282
+ name: string;
283
+ layer: number;
284
+ [key: string]: any;
285
+ }
286
+ declare function useDialog(options?: DialogOptions): {
273
287
  open: ({ layer, component, props, }: {
274
288
  component: Component;
275
289
  props?: any;
@@ -281,6 +295,13 @@ declare function useDialog(): {
281
295
  closeAll: () => void;
282
296
  showConfirm: (text?: string) => boolean;
283
297
  isOnTop: (uuid: string) => boolean;
298
+ genHash: ({ layer, componentName, props, }: {
299
+ componentName: string;
300
+ props?: any;
301
+ layer?: number;
302
+ }) => string;
303
+ parseHash: (hash: string, componentName: string) => DialogParseHashResult | undefined;
304
+ clearHash: () => void;
284
305
  openByHash: ({ layer, component, props, }: {
285
306
  component: Component;
286
307
  props?: any;
@@ -369,4 +390,4 @@ declare function isTypeUrl(message?: string): RuleItem;
369
390
  declare function isTypeNumber(value?: number, message?: string): RuleItem;
370
391
  declare function isStrictLength(value?: number, message?: string): RuleItem;
371
392
 
372
- export { AppComponentsResolver, type BrowserInfo, type Dictionary, EnrichError, type ResponseError, UiComponentsResolver, type VersionsList, camelizeKeys, convertEnumToOptions, formatErrorDataMessage, formatErrorForNotify, formatMoney, genHash, genRandomNumber, genUUID, getCardNumber, getCountryFromPhone, getPaginationLimit, getPaginationOffset, getPaginationPages, getPaginationParams, getStatusMessage, isElementIgnored, isEmptyObject, isHtml, isMax, isMin, isRequired, isStrictLength, isTypeEmail, isTypeNumber, isTypeUrl, mapDataObjectForFilters, parsePhone, snakelizeKeys, unformatNumber, useAbortController, useAsyncItems, useAsyncMultiselect, useAsyncSelect, useBreakpoint, useClassName, useDayjs, useDetectBrowser, useDialog, useFilters, useGlobalScroll, useLogger, usePanel, validateNumber, validatePhone };
393
+ export { AppComponentsResolver, type BrowserInfo, type Dialog, type DialogOptions, type DialogParseHashResult, type Dictionary, EnrichError, type ResponseError, UiComponentsResolver, type VersionsList, camelizeKeys, convertEnumToOptions, formatErrorDataMessage, formatErrorForNotify, formatMoney, genHash, genRandomNumber, genUUID, getCardNumber, getCountryFromPhone, getPaginationLimit, getPaginationOffset, getPaginationPages, getPaginationParams, getStatusMessage, isElementIgnored, isEmptyObject, isHtml, isMax, isMin, isRequired, isStrictLength, isTypeEmail, isTypeNumber, isTypeUrl, mapDataObjectForFilters, parsePhone, snakelizeKeys, unformatNumber, useAbortController, useAsyncItems, useAsyncMultiselect, useAsyncSelect, useBreakpoint, useClassName, useDayjs, useDetectBrowser, useDialog, useFilters, useGlobalScroll, useLogger, usePanel, validateNumber, validatePhone };
package/dist/index.d.ts CHANGED
@@ -269,7 +269,21 @@ declare function useDetectBrowser(versions: VersionsList, userAgent?: any): Brow
269
269
  interface VNodeCustom$1 extends VNode {
270
270
  close: () => void;
271
271
  }
272
- declare function useDialog(): {
272
+ interface Dialog {
273
+ uuid: string;
274
+ name?: string;
275
+ vnode: VNodeCustom$1;
276
+ layer: number;
277
+ }
278
+ interface DialogOptions {
279
+ hashPrefix?: string;
280
+ }
281
+ interface DialogParseHashResult {
282
+ name: string;
283
+ layer: number;
284
+ [key: string]: any;
285
+ }
286
+ declare function useDialog(options?: DialogOptions): {
273
287
  open: ({ layer, component, props, }: {
274
288
  component: Component;
275
289
  props?: any;
@@ -281,6 +295,13 @@ declare function useDialog(): {
281
295
  closeAll: () => void;
282
296
  showConfirm: (text?: string) => boolean;
283
297
  isOnTop: (uuid: string) => boolean;
298
+ genHash: ({ layer, componentName, props, }: {
299
+ componentName: string;
300
+ props?: any;
301
+ layer?: number;
302
+ }) => string;
303
+ parseHash: (hash: string, componentName: string) => DialogParseHashResult | undefined;
304
+ clearHash: () => void;
284
305
  openByHash: ({ layer, component, props, }: {
285
306
  component: Component;
286
307
  props?: any;
@@ -369,4 +390,4 @@ declare function isTypeUrl(message?: string): RuleItem;
369
390
  declare function isTypeNumber(value?: number, message?: string): RuleItem;
370
391
  declare function isStrictLength(value?: number, message?: string): RuleItem;
371
392
 
372
- export { AppComponentsResolver, type BrowserInfo, type Dictionary, EnrichError, type ResponseError, UiComponentsResolver, type VersionsList, camelizeKeys, convertEnumToOptions, formatErrorDataMessage, formatErrorForNotify, formatMoney, genHash, genRandomNumber, genUUID, getCardNumber, getCountryFromPhone, getPaginationLimit, getPaginationOffset, getPaginationPages, getPaginationParams, getStatusMessage, isElementIgnored, isEmptyObject, isHtml, isMax, isMin, isRequired, isStrictLength, isTypeEmail, isTypeNumber, isTypeUrl, mapDataObjectForFilters, parsePhone, snakelizeKeys, unformatNumber, useAbortController, useAsyncItems, useAsyncMultiselect, useAsyncSelect, useBreakpoint, useClassName, useDayjs, useDetectBrowser, useDialog, useFilters, useGlobalScroll, useLogger, usePanel, validateNumber, validatePhone };
393
+ export { AppComponentsResolver, type BrowserInfo, type Dialog, type DialogOptions, type DialogParseHashResult, type Dictionary, EnrichError, type ResponseError, UiComponentsResolver, type VersionsList, camelizeKeys, convertEnumToOptions, formatErrorDataMessage, formatErrorForNotify, formatMoney, genHash, genRandomNumber, genUUID, getCardNumber, getCountryFromPhone, getPaginationLimit, getPaginationOffset, getPaginationPages, getPaginationParams, getStatusMessage, isElementIgnored, isEmptyObject, isHtml, isMax, isMin, isRequired, isStrictLength, isTypeEmail, isTypeNumber, isTypeUrl, mapDataObjectForFilters, parsePhone, snakelizeKeys, unformatNumber, useAbortController, useAsyncItems, useAsyncMultiselect, useAsyncSelect, useBreakpoint, useClassName, useDayjs, useDetectBrowser, useDialog, useFilters, useGlobalScroll, useLogger, usePanel, validateNumber, validatePhone };
package/dist/index.mjs CHANGED
@@ -991,9 +991,20 @@ function useGlobalScroll() {
991
991
 
992
992
  const CONFIRM_TEXT = "Are you sure you want to close? \nAll changes will be lost.";
993
993
  let dialogs = [];
994
- function useDialog() {
995
- let appContext;
994
+ const HASH_PREFIX = "#ud_";
995
+ function useDialog(options) {
996
996
  const logger = useLogger("use-dialog");
997
+ let hashPrefix = HASH_PREFIX;
998
+ if (options?.hashPrefix) {
999
+ if (options.hashPrefix.charAt(0) === "#") {
1000
+ hashPrefix = options?.hashPrefix;
1001
+ } else {
1002
+ logger.warn(
1003
+ `*hashPrefix* must start with "#". The default prefix "${HASH_PREFIX}" will be used`
1004
+ );
1005
+ }
1006
+ }
1007
+ let appContext;
997
1008
  const {
998
1009
  isLocked: isGlobalScrollLocked,
999
1010
  lock: lockGlobalScroll,
@@ -1001,15 +1012,26 @@ function useDialog() {
1001
1012
  } = useGlobalScroll();
1002
1013
  const route = useRoute();
1003
1014
  const router = useRouter();
1004
- const HASH_PREFIX = "#ud_";
1015
+ const genHash = ({
1016
+ layer = 0,
1017
+ componentName,
1018
+ props
1019
+ }) => {
1020
+ const data = {
1021
+ name: componentName,
1022
+ layer,
1023
+ props
1024
+ };
1025
+ return `${hashPrefix}${window.btoa(JSON.stringify(data))}`;
1026
+ };
1005
1027
  const parseHash = (hash, componentName) => {
1006
1028
  if (!hash)
1007
1029
  return void 0;
1008
- if (!hash.includes(HASH_PREFIX))
1030
+ if (!hash.includes(hashPrefix))
1009
1031
  return void 0;
1010
1032
  let dataFromHash;
1011
1033
  try {
1012
- dataFromHash = JSON.parse(window.atob(hash.slice(HASH_PREFIX.length)));
1034
+ dataFromHash = JSON.parse(window.atob(hash.slice(hashPrefix.length)));
1013
1035
  } catch (_error) {
1014
1036
  logger.warn("*parseHash* cant parse hash");
1015
1037
  }
@@ -1057,7 +1079,7 @@ function useDialog() {
1057
1079
  vnode2.component.props.modelValue = value;
1058
1080
  if (!value && route?.hash) {
1059
1081
  const dataFromHash = parseHash(route.hash, component.name);
1060
- if (dataFromHash)
1082
+ if (dataFromHash?.layer === layer)
1061
1083
  clearHash();
1062
1084
  }
1063
1085
  if (!value && (dialogs.length === 1 || layer === 0) && isGlobalScrollLocked.value) {
@@ -1073,7 +1095,7 @@ function useDialog() {
1073
1095
  if (!route?.hash)
1074
1096
  return;
1075
1097
  const dataFromHash = parseHash(route.hash, component.name);
1076
- if (dataFromHash)
1098
+ if (dataFromHash?.layer === layer)
1077
1099
  clearHash();
1078
1100
  };
1079
1101
  vnode2.props.onDestroy = () => {
@@ -1166,15 +1188,10 @@ function useDialog() {
1166
1188
  component,
1167
1189
  props
1168
1190
  }) => {
1169
- const data = {
1170
- name: component.name,
1171
- layer,
1172
- props
1173
- };
1174
1191
  router.push({
1175
1192
  name: route.name || void 0,
1176
1193
  query: route.query,
1177
- hash: `${HASH_PREFIX}${window.btoa(JSON.stringify(data))}`
1194
+ hash: genHash({ layer, props, componentName: component.name })
1178
1195
  });
1179
1196
  };
1180
1197
  const watchHash = ({
@@ -1224,6 +1241,9 @@ function useDialog() {
1224
1241
  closeAll,
1225
1242
  showConfirm,
1226
1243
  isOnTop,
1244
+ genHash,
1245
+ parseHash,
1246
+ clearHash,
1227
1247
  openByHash,
1228
1248
  watchHash
1229
1249
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@karta.io/utils",
3
- "version": "1.0.0-beta.38",
3
+ "version": "1.0.0-beta.39",
4
4
  "description": "karta.io utils for admin and application",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -25,7 +25,7 @@
25
25
  "vue": "3.x"
26
26
  },
27
27
  "dependencies": {
28
- "@karta.io/common-data": "^1.0.0-beta.38",
28
+ "@karta.io/common-data": "^1.0.0-beta.39",
29
29
  "@tanstack/vue-query": "5.52.3",
30
30
  "@vueuse/core": "11.0.3",
31
31
  "async-validator": "4.2.5",