@codebit-programando-solucoes/codebit-web 1.1.20 → 1.1.21

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
@@ -24,17 +24,22 @@ var __webpack_require__ = {};
24
24
  var __webpack_exports__ = {};
25
25
  __webpack_require__.r(__webpack_exports__);
26
26
  __webpack_require__.d(__webpack_exports__, {
27
- fetchImageAsBlob: ()=>fetchImageAsBlob,
28
- getScrollbarWidth: ()=>getScrollbarWidth,
29
- loadImage: ()=>loadImage,
27
+ removeHashParam: ()=>removeHashParam,
30
28
  markdownItBrEmptyLines: ()=>markdownItBrEmptyLines,
31
- ErrorCode: ()=>ErrorCode,
29
+ getHashParams: ()=>getHashParams,
32
30
  ApiNetworkError: ()=>ApiNetworkError,
33
- Logger: ()=>Logger,
34
31
  copyToClipboard: ()=>copyToClipboard,
32
+ loadImage: ()=>loadImage,
33
+ createAdvancedPartialRegex: ()=>createAdvancedPartialRegex,
34
+ hasHashParam: ()=>hasHashParam,
35
+ ErrorCode: ()=>ErrorCode,
36
+ addHashParam: ()=>addHashParam,
37
+ getScrollbarWidth: ()=>getScrollbarWidth,
38
+ Logger: ()=>Logger,
39
+ getHashParamValue: ()=>getHashParamValue,
35
40
  Api: ()=>Api,
36
41
  ApiError: ()=>ApiError,
37
- createAdvancedPartialRegex: ()=>createAdvancedPartialRegex
42
+ fetchImageAsBlob: ()=>fetchImageAsBlob
38
43
  });
39
44
  class ApiError extends Error {
40
45
  constructor(response, request = null){
@@ -531,29 +536,79 @@ function getScrollbarWidth(scrollbarWidth = 'auto') {
531
536
  if ('none' === scrollbarWidth) return 0;
532
537
  return 16;
533
538
  }
539
+ const getHashParams = ()=>{
540
+ const hash = globalThis.location.hash.substring(1);
541
+ return new URLSearchParams(hash);
542
+ };
543
+ const hasHashParam = (param)=>{
544
+ const params = getHashParams();
545
+ return params.has(param);
546
+ };
547
+ const getHashParamValue = (param)=>{
548
+ const params = getHashParams();
549
+ return params.get(param);
550
+ };
551
+ const addHashParam = (param, value)=>{
552
+ const params = getHashParams();
553
+ if (null == value) {
554
+ if (!params.has(param)) {
555
+ const paramString = params.toString();
556
+ const separator = paramString ? '&' : '';
557
+ globalThis.location.hash = paramString + separator + encodeURIComponent(param);
558
+ }
559
+ } else if ('' === value) {
560
+ params.set(param, '');
561
+ const paramEntries = [];
562
+ for (const [key, val] of params.entries())if ('' === val) paramEntries.push(encodeURIComponent(key));
563
+ else paramEntries.push(encodeURIComponent(key) + '=' + encodeURIComponent(val));
564
+ globalThis.location.hash = paramEntries.join('&');
565
+ } else {
566
+ params.set(param, value);
567
+ globalThis.location.hash = params.toString();
568
+ }
569
+ };
570
+ const removeHashParam = (param)=>{
571
+ const params = getHashParams();
572
+ params.delete(param);
573
+ const paramEntries = [];
574
+ for (const [key, value] of params.entries())if ('' === value) paramEntries.push(encodeURIComponent(key));
575
+ else paramEntries.push(encodeURIComponent(key) + '=' + encodeURIComponent(value));
576
+ if (paramEntries.length > 0) globalThis.location.hash = paramEntries.join('&');
577
+ else globalThis.history.replaceState(null, '', globalThis.location.pathname + globalThis.location.search);
578
+ };
534
579
  exports.Api = __webpack_exports__.Api;
535
580
  exports.ApiError = __webpack_exports__.ApiError;
536
581
  exports.ApiNetworkError = __webpack_exports__.ApiNetworkError;
537
582
  exports.ErrorCode = __webpack_exports__.ErrorCode;
538
583
  exports.Logger = __webpack_exports__.Logger;
584
+ exports.addHashParam = __webpack_exports__.addHashParam;
539
585
  exports.copyToClipboard = __webpack_exports__.copyToClipboard;
540
586
  exports.createAdvancedPartialRegex = __webpack_exports__.createAdvancedPartialRegex;
541
587
  exports.fetchImageAsBlob = __webpack_exports__.fetchImageAsBlob;
588
+ exports.getHashParamValue = __webpack_exports__.getHashParamValue;
589
+ exports.getHashParams = __webpack_exports__.getHashParams;
542
590
  exports.getScrollbarWidth = __webpack_exports__.getScrollbarWidth;
591
+ exports.hasHashParam = __webpack_exports__.hasHashParam;
543
592
  exports.loadImage = __webpack_exports__.loadImage;
544
593
  exports.markdownItBrEmptyLines = __webpack_exports__.markdownItBrEmptyLines;
594
+ exports.removeHashParam = __webpack_exports__.removeHashParam;
545
595
  for(var __rspack_i in __webpack_exports__)if (-1 === [
546
596
  "Api",
547
597
  "ApiError",
548
598
  "ApiNetworkError",
549
599
  "ErrorCode",
550
600
  "Logger",
601
+ "addHashParam",
551
602
  "copyToClipboard",
552
603
  "createAdvancedPartialRegex",
553
604
  "fetchImageAsBlob",
605
+ "getHashParamValue",
606
+ "getHashParams",
554
607
  "getScrollbarWidth",
608
+ "hasHashParam",
555
609
  "loadImage",
556
- "markdownItBrEmptyLines"
610
+ "markdownItBrEmptyLines",
611
+ "removeHashParam"
557
612
  ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
558
613
  Object.defineProperty(exports, '__esModule', {
559
614
  value: true
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Utility functions for hash parameter manipulation
3
+ */
4
+
5
+ /**
6
+ * Helper function to get URLSearchParams from hash
7
+ * @returns URLSearchParams object containing hash parameters
8
+ */
9
+ export declare function getHashParams(): URLSearchParams;
10
+
11
+ /**
12
+ * Helper function to check if a parameter exists in hash
13
+ * @param param - Parameter to check
14
+ * @returns true if parameter exists, false otherwise
15
+ */
16
+ export declare function hasHashParam(param: string): boolean;
17
+
18
+ /**
19
+ * Helper function to get the value of a parameter from hash
20
+ * @param param - Parameter to get value for
21
+ * @returns Value of the parameter or null if not found
22
+ */
23
+ export declare function getHashParamValue(param: string): string | null;
24
+
25
+ /**
26
+ * Helper function to add a parameter to hash with optional value
27
+ * @param param - Parameter to add
28
+ * @param value - Optional value for the parameter
29
+ */
30
+ export declare function addHashParam(param: string, value?: string): void;
31
+
32
+ /**
33
+ * Helper function to remove a parameter from hash
34
+ * @param param - Parameter to remove
35
+ */
36
+ export declare function removeHashParam(param: string): void;
@@ -4,3 +4,4 @@ export * from './Image';
4
4
  export * from './Logger';
5
5
  export * from './markdown-it';
6
6
  export * from './Layout';
7
+ export * from './HashUtils';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codebit-programando-solucoes/codebit-web",
3
- "version": "1.1.20",
3
+ "version": "1.1.21",
4
4
  "main": "./dist/index.cjs",
5
5
  "type": "module",
6
6
  "types": "./dist/index.d.ts",