@djangocfg/ui-tools 2.1.167 → 2.1.168

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@djangocfg/ui-tools",
3
- "version": "2.1.167",
3
+ "version": "2.1.168",
4
4
  "description": "Heavy React tools with lazy loading - for Electron, Vite, CRA, Next.js apps",
5
5
  "keywords": [
6
6
  "ui-tools",
@@ -78,8 +78,8 @@
78
78
  "check": "tsc --noEmit"
79
79
  },
80
80
  "peerDependencies": {
81
- "@djangocfg/i18n": "^2.1.167",
82
- "@djangocfg/ui-core": "^2.1.167",
81
+ "@djangocfg/i18n": "^2.1.168",
82
+ "@djangocfg/ui-core": "^2.1.168",
83
83
  "lucide-react": "^0.545.0",
84
84
  "react": "^19.0.0",
85
85
  "react-dom": "^19.0.0",
@@ -112,10 +112,10 @@
112
112
  "@maplibre/maplibre-gl-geocoder": "^1.7.0"
113
113
  },
114
114
  "devDependencies": {
115
- "@djangocfg/i18n": "^2.1.167",
115
+ "@djangocfg/i18n": "^2.1.168",
116
116
  "@djangocfg/playground": "workspace:*",
117
- "@djangocfg/typescript-config": "^2.1.167",
118
- "@djangocfg/ui-core": "^2.1.167",
117
+ "@djangocfg/typescript-config": "^2.1.168",
118
+ "@djangocfg/ui-core": "^2.1.168",
119
119
  "@types/mapbox__mapbox-gl-draw": "^1.4.8",
120
120
  "@types/node": "^24.7.2",
121
121
  "@types/react": "^19.1.0",
@@ -1,5 +1,14 @@
1
+ import { emitRuntimeError } from '@djangocfg/ui-core/utils';
2
+
1
3
  import { logger } from './logger';
2
4
 
5
+ /**
6
+ * Safely escape string for use in CSS attribute selector
7
+ */
8
+ function escapeCSS(str: string): string {
9
+ return str.replace(/["\\]/g, '\\$&');
10
+ }
11
+
3
12
  /**
4
13
  * Find target elements for a tour step.
5
14
  * Supports CSS selectors and data-tour-step-id attribute.
@@ -10,10 +19,18 @@ export function findTargetElements(
10
19
  ): HTMLElement[] {
11
20
  if (!target) {
12
21
  // Fallback to data-tour-step-id attribute
13
- const elements = document.querySelectorAll<HTMLElement>(
14
- `[data-tour-step-id="${stepId}"], [data-tour-step-id*="${stepId}"]`
15
- );
16
- return filterValidElements(Array.from(elements));
22
+ try {
23
+ const escapedStepId = escapeCSS(stepId);
24
+ const elements = document.querySelectorAll<HTMLElement>(
25
+ `[data-tour-step-id="${escapedStepId}"], [data-tour-step-id*="${escapedStepId}"]`
26
+ );
27
+ return filterValidElements(Array.from(elements));
28
+ } catch (error) {
29
+ const err = error instanceof Error ? error : new Error(String(error));
30
+ logger.error(`Tour: Invalid stepId selector "${stepId}"`, { error: err.message, stepId });
31
+ emitRuntimeError('Tour', `Invalid stepId: ${stepId}`, err);
32
+ return [];
33
+ }
17
34
  }
18
35
 
19
36
  // Try as CSS selector first
@@ -21,15 +38,26 @@ export function findTargetElements(
21
38
  const elements = document.querySelectorAll<HTMLElement>(target);
22
39
  const valid = filterValidElements(Array.from(elements));
23
40
  if (valid.length > 0) return valid;
24
- } catch {
25
- logger.warn(`Invalid selector: ${target}`);
41
+ } catch (error) {
42
+ const err = error instanceof Error ? error : new Error(String(error));
43
+ logger.warn(`Tour: Invalid target selector "${target}"`, { error: err.message, target, stepId });
44
+ emitRuntimeError('Tour', `Invalid selector: ${target}`, err);
45
+ return [];
26
46
  }
27
47
 
28
48
  // Fallback to data attribute
29
- const elements = document.querySelectorAll<HTMLElement>(
30
- `[data-tour-step-id="${target}"], [data-tour-step-id*="${target}"]`
31
- );
32
- return filterValidElements(Array.from(elements));
49
+ try {
50
+ const escapedTarget = escapeCSS(target);
51
+ const elements = document.querySelectorAll<HTMLElement>(
52
+ `[data-tour-step-id="${escapedTarget}"], [data-tour-step-id*="${escapedTarget}"]`
53
+ );
54
+ return filterValidElements(Array.from(elements));
55
+ } catch (error) {
56
+ const err = error instanceof Error ? error : new Error(String(error));
57
+ logger.error(`Tour: Invalid fallback selector for "${target}"`, { error: err.message, target, stepId });
58
+ emitRuntimeError('Tour', `Invalid fallback selector: ${target}`, err);
59
+ return [];
60
+ }
33
61
  }
34
62
 
35
63
  /**