@teambit/react.ui.component-highlighter 0.0.485 → 0.0.486

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.
Files changed (69) hide show
  1. package/component-highlighter.docs.md +86 -31
  2. package/dist/component-highlighter.docs.md +86 -31
  3. package/dist/{component-highlighter/hover-highlighter → hover-highlighter}/hover-highlighter.compositions.d.ts +0 -0
  4. package/dist/{component-highlighter/hover-highlighter → hover-highlighter}/hover-highlighter.compositions.js +6 -3
  5. package/dist/hover-highlighter/hover-highlighter.compositions.js.map +1 -0
  6. package/dist/hover-highlighter/hover-highlighter.d.ts +3 -0
  7. package/dist/hover-highlighter/hover-highlighter.js +25 -0
  8. package/dist/hover-highlighter/hover-highlighter.js.map +1 -0
  9. package/dist/{component-highlighter/hover-highlighter → hover-highlighter}/hover-highlighter.spec.d.ts +0 -0
  10. package/dist/{component-highlighter/hover-highlighter → hover-highlighter}/hover-highlighter.spec.js +0 -0
  11. package/dist/hover-highlighter/hover-highlighter.spec.js.map +1 -0
  12. package/dist/hover-highlighter/index.d.ts +4 -0
  13. package/dist/hover-highlighter/index.js +8 -0
  14. package/dist/hover-highlighter/index.js.map +1 -0
  15. package/dist/hover-highlighter/use-hover-highlighter.d.ts +17 -0
  16. package/dist/hover-highlighter/use-hover-highlighter.js +66 -0
  17. package/dist/hover-highlighter/use-hover-highlighter.js.map +1 -0
  18. package/dist/hybrid-highligher/hybrid-highlighter.d.ts +34 -0
  19. package/dist/hybrid-highligher/hybrid-highlighter.js +74 -0
  20. package/dist/hybrid-highligher/hybrid-highlighter.js.map +1 -0
  21. package/dist/hybrid-highligher/index.d.ts +2 -0
  22. package/dist/hybrid-highligher/index.js +6 -0
  23. package/dist/hybrid-highligher/index.js.map +1 -0
  24. package/dist/index.d.ts +5 -2
  25. package/dist/index.js +5 -3
  26. package/dist/index.js.map +1 -1
  27. package/dist/multi-highlighter/multi-highlighter.composition.d.ts +2 -0
  28. package/dist/multi-highlighter/multi-highlighter.composition.js +34 -3
  29. package/dist/multi-highlighter/multi-highlighter.composition.js.map +1 -1
  30. package/dist/multi-highlighter/multi-highlighter.d.ts +3 -15
  31. package/dist/multi-highlighter/multi-highlighter.js +4 -63
  32. package/dist/multi-highlighter/multi-highlighter.js.map +1 -1
  33. package/dist/multi-highlighter/use-multi-highlighter.d.ts +13 -0
  34. package/dist/multi-highlighter/use-multi-highlighter.js +51 -0
  35. package/dist/multi-highlighter/use-multi-highlighter.js.map +1 -0
  36. package/dist/rule-matcher.d.ts +2 -0
  37. package/dist/rule-matcher.js +15 -0
  38. package/dist/rule-matcher.js.map +1 -0
  39. package/{component-highlighter/hover-highlighter → hover-highlighter}/hover-highlighter.compositions.tsx +4 -2
  40. package/{component-highlighter/hover-highlighter → hover-highlighter}/hover-highlighter.spec.tsx +0 -0
  41. package/hover-highlighter/hover-highlighter.tsx +8 -0
  42. package/hover-highlighter/index.ts +5 -0
  43. package/hover-highlighter/use-hover-highlighter.tsx +93 -0
  44. package/hybrid-highligher/hybrid-highlighter.tsx +126 -0
  45. package/hybrid-highligher/index.ts +2 -0
  46. package/index.ts +7 -2
  47. package/multi-highlighter/multi-highlighter.composition.tsx +40 -2
  48. package/multi-highlighter/multi-highlighter.tsx +5 -81
  49. package/multi-highlighter/use-multi-highlighter.tsx +70 -0
  50. package/package-tar/teambit-react.ui.component-highlighter-0.0.486.tgz +0 -0
  51. package/package.json +7 -5
  52. package/rule-matcher.tsx +15 -0
  53. package/component-highlighter/hover-highlighter/hover-highlighter.module.scss +0 -13
  54. package/component-highlighter/hover-highlighter/hover-highlighter.tsx +0 -120
  55. package/component-highlighter/hover-highlighter/index.ts +0 -1
  56. package/component-highlighter/index.ts +0 -2
  57. package/dist/component-highlighter/hover-highlighter/hover-highlighter.compositions.js.map +0 -1
  58. package/dist/component-highlighter/hover-highlighter/hover-highlighter.d.ts +0 -21
  59. package/dist/component-highlighter/hover-highlighter/hover-highlighter.js +0 -100
  60. package/dist/component-highlighter/hover-highlighter/hover-highlighter.js.map +0 -1
  61. package/dist/component-highlighter/hover-highlighter/hover-highlighter.module.scss +0 -13
  62. package/dist/component-highlighter/hover-highlighter/hover-highlighter.spec.js.map +0 -1
  63. package/dist/component-highlighter/hover-highlighter/index.d.ts +0 -1
  64. package/dist/component-highlighter/hover-highlighter/index.js +0 -6
  65. package/dist/component-highlighter/hover-highlighter/index.js.map +0 -1
  66. package/dist/component-highlighter/index.d.ts +0 -2
  67. package/dist/component-highlighter/index.js +0 -6
  68. package/dist/component-highlighter/index.js.map +0 -1
  69. package/package-tar/teambit-react.ui.component-highlighter-0.0.485.tgz +0 -0
@@ -12,18 +12,18 @@ It is mostly used for compositions debugging.
12
12
 
13
13
  ## How to use?
14
14
 
15
- Simplest way to use the component is by wrapping your code with `HoverHighlighter`.
15
+ Simplest way to use the component is by wrapping your code with `ComponentHighlighter`.
16
16
  It will automatically detect components from DOM elements, just by hovering on them.
17
17
 
18
18
  ```tsx
19
- import { HoverHighlighter } from '@teambit/react.ui.component-highlighter';
19
+ import { ComponentHighlighter } from '@teambit/react.ui.component-highlighter';
20
20
 
21
21
  function App() {
22
22
  return (
23
- <HoverHighlighter>
23
+ <ComponentHighlighter>
24
24
  <Header />
25
25
  <Feed />
26
- </HoverHighlighter>
26
+ </ComponentHighlighter>
27
27
  );
28
28
  }
29
29
  ```
@@ -31,25 +31,29 @@ function App() {
31
31
  You can also use it manually, to have more control:
32
32
 
33
33
  ```tsx
34
- const [element, setElement] = useState<HTMLElement | undefined>(undefined);
34
+ import { ElementHighlighter } from '@teambit/react.ui.component-highlighter';
35
35
 
36
- useEffect(() => setElement(document.getElementById('to-highlight')), [targetRef.current]);
36
+ function ManualHighlight() {
37
+ const [element, setElement] = useState<HTMLElement | undefined>(undefined);
37
38
 
38
- const target = targetElement && {
39
- element: targetElement,
40
- id: 'teambit.design/ui/icon-button',
39
+ useEffect(() => setElement(document.getElementById('to-highlight')), [targetRef.current]);
41
40
 
42
- // explicit overrides:
43
- link: 'https://bit.dev/teambit/design/ui/icon-button',
44
- scopeLink: 'https://bit.dev/teambit/design',
45
- };
41
+ const target = targetElement && {
42
+ element: targetElement,
43
+ id: 'teambit.design/ui/icon-button',
46
44
 
47
- return (
48
- <div>
49
- <div id="to-highlight">highlight target</div>
50
- {target && <ElementHighlighter target={target} />}
51
- </div>
52
- );
45
+ // explicit overrides:
46
+ link: 'https://bit.dev/teambit/design/ui/icon-button',
47
+ scopeLink: 'https://bit.dev/teambit/design',
48
+ };
49
+
50
+ return (
51
+ <div>
52
+ <div id="to-highlight">highlight target</div>
53
+ {target && <ElementHighlighter target={target} />}
54
+ </div>
55
+ );
56
+ }
53
57
  ```
54
58
 
55
59
  ## How does it work?
@@ -60,7 +64,7 @@ The automatic highlighter then adds an event listener for hover events, which au
60
64
 
61
65
  Where does the metadata come from? The highlighter assumes the code has been transpiled by Bit's [custom babel plugin](https://bit.dev/teambit/react/babel/bit-react-transformer). The plugin looks for React components (i.e. functions or classes), and attaches a metadata object to them.
62
66
 
63
- > The `Bit React Transformer` babel plugin is already running in the Preview during `bit start`.
67
+ > The `Bit React Transformer` babel plugin is already running in the Preview, during `bit start`.
64
68
  > It only effects the browser bundle, and not the dists.
65
69
 
66
70
  The result looks like this:
@@ -80,6 +84,33 @@ export function Button() {
80
84
  Button.__bit_component = __bit_component;
81
85
  ```
82
86
 
87
+ ### Modes
88
+
89
+ The Component Highlighter comes in a few different modes:
90
+
91
+ - `hover` - this will track your mouse movements, and show the highlighter for the element the user is currently hovering on.
92
+ - `allChildren` - this automatically detects all components nested inside the highlighter, and apply a highlighter to them. Currently, this detection only happens once on initial setup, so it does not detect changes.
93
+
94
+ In addition to changing the `mode` prop, you can also use convenience exports from the same package:
95
+
96
+ ```tsx
97
+ import { MultiHighlighter, HoverHighlighter } from '@teambit/react.ui.component-highlighter';
98
+
99
+ function example() {
100
+ return (
101
+ <div>
102
+ <HoverHighlighter>
103
+ <App />
104
+ </HoverHighlighter>
105
+
106
+ <MultiHighlighter>
107
+ <App />
108
+ </MultiHighlighter>
109
+ </div>
110
+ );
111
+ }
112
+ ```
113
+
83
114
  ### Debounce
84
115
 
85
116
  Normally, moving quickly between elements could produce a jitter effect, where the highlighter "jumps" between elements, making interaction difficult.
@@ -88,24 +119,40 @@ First time selection will always happen immediately, for a snappy experience.
88
119
 
89
120
  You can control the debounce rate with the `debounceSelection` prop. (default - `80ms`)
90
121
 
91
- ## Multi highlighter
122
+ ## Exclusions Zones
92
123
 
93
- This component is similar to the Hover Highlighter, but provides automatic highlighting to all components nested inside it.
94
-
95
- Simply wrap your code like so, and see the highlighting in action:
124
+ To disabled highlighting in a specific area of the DOM, you can use the `<ExcludeHighlighter />` component:
96
125
 
97
126
  ```tsx
98
- import { MultiHighlighter } from '@teambit/react.ui.component-highlighter';
127
+ import { ExcludeHighlighter, excludeHighlighterAtt } from '@teambit/react.ui.component-highlighter';
99
128
 
100
129
  // ...
101
130
 
102
131
  return (
103
- <MultiHighlighter>
104
- <App />
105
- </MultiHighlighter>
132
+ <div>
133
+ <ExcludeHighlighter>
134
+ <Card>this component will not be highlighted</Card>
135
+ </ExcludeHighlighter>
136
+
137
+ {/* you can also add the exclude attribute without making a new div */}
138
+ <Card {...excludeHighlighterAtt}>this component will also be skipped</Card>
139
+ </div>
106
140
  );
107
141
  ```
108
142
 
143
+ Another options would be use use the `rule` prop.
144
+ Inspired by Webpack rules, it provides a query selector or function that the highlighter target will have to match.
145
+ For example:
146
+
147
+ ```tsx
148
+ <ComponentHighlighter rule="#include *">
149
+ <Button>will not be highlighted</Button>
150
+ <div id="include">
151
+ <Button>this will be highlighted</Button>
152
+ </div>
153
+ </ComponentHighlighter>
154
+ ```
155
+
109
156
  ## Customization
110
157
 
111
158
  Use these CSS variables to edit the highlighter color
@@ -116,7 +163,15 @@ Use these CSS variables to edit the highlighter color
116
163
  --bit-highlighter-color-active: #e79db1;
117
164
  ```
118
165
 
119
- You can also pass these classes for complete control:
166
+ While it is preferred to use the css variables, you can also set them using react props:
167
+
168
+ ```tsx
169
+ <ComponentHighlighter bgColor="#eebcc9" bgColorHover="#f6dae2" bgColorActive="#e79db1">
170
+ ...
171
+ </ComponentHighlighter>
172
+ ```
173
+
174
+ And for complete control, you can pass these classes:
120
175
 
121
176
  ```tsx
122
177
  const classes = {
@@ -128,9 +183,9 @@ const classes = {
128
183
  label?: string;
129
184
  };
130
185
 
131
- <HoverHighlighter classes={classes}>
186
+ <ComponentHighlighter classes={classes}>
132
187
  ...
133
- </HoverHighlighter>
188
+ </ComponentHighlighter>
134
189
  ```
135
190
 
136
191
  You can control the size using regular `font-size`.
@@ -12,18 +12,18 @@ It is mostly used for compositions debugging.
12
12
 
13
13
  ## How to use?
14
14
 
15
- Simplest way to use the component is by wrapping your code with `HoverHighlighter`.
15
+ Simplest way to use the component is by wrapping your code with `ComponentHighlighter`.
16
16
  It will automatically detect components from DOM elements, just by hovering on them.
17
17
 
18
18
  ```tsx
19
- import { HoverHighlighter } from '@teambit/react.ui.component-highlighter';
19
+ import { ComponentHighlighter } from '@teambit/react.ui.component-highlighter';
20
20
 
21
21
  function App() {
22
22
  return (
23
- <HoverHighlighter>
23
+ <ComponentHighlighter>
24
24
  <Header />
25
25
  <Feed />
26
- </HoverHighlighter>
26
+ </ComponentHighlighter>
27
27
  );
28
28
  }
29
29
  ```
@@ -31,25 +31,29 @@ function App() {
31
31
  You can also use it manually, to have more control:
32
32
 
33
33
  ```tsx
34
- const [element, setElement] = useState<HTMLElement | undefined>(undefined);
34
+ import { ElementHighlighter } from '@teambit/react.ui.component-highlighter';
35
35
 
36
- useEffect(() => setElement(document.getElementById('to-highlight')), [targetRef.current]);
36
+ function ManualHighlight() {
37
+ const [element, setElement] = useState<HTMLElement | undefined>(undefined);
37
38
 
38
- const target = targetElement && {
39
- element: targetElement,
40
- id: 'teambit.design/ui/icon-button',
39
+ useEffect(() => setElement(document.getElementById('to-highlight')), [targetRef.current]);
41
40
 
42
- // explicit overrides:
43
- link: 'https://bit.dev/teambit/design/ui/icon-button',
44
- scopeLink: 'https://bit.dev/teambit/design',
45
- };
41
+ const target = targetElement && {
42
+ element: targetElement,
43
+ id: 'teambit.design/ui/icon-button',
46
44
 
47
- return (
48
- <div>
49
- <div id="to-highlight">highlight target</div>
50
- {target && <ElementHighlighter target={target} />}
51
- </div>
52
- );
45
+ // explicit overrides:
46
+ link: 'https://bit.dev/teambit/design/ui/icon-button',
47
+ scopeLink: 'https://bit.dev/teambit/design',
48
+ };
49
+
50
+ return (
51
+ <div>
52
+ <div id="to-highlight">highlight target</div>
53
+ {target && <ElementHighlighter target={target} />}
54
+ </div>
55
+ );
56
+ }
53
57
  ```
54
58
 
55
59
  ## How does it work?
@@ -60,7 +64,7 @@ The automatic highlighter then adds an event listener for hover events, which au
60
64
 
61
65
  Where does the metadata come from? The highlighter assumes the code has been transpiled by Bit's [custom babel plugin](https://bit.dev/teambit/react/babel/bit-react-transformer). The plugin looks for React components (i.e. functions or classes), and attaches a metadata object to them.
62
66
 
63
- > The `Bit React Transformer` babel plugin is already running in the Preview during `bit start`.
67
+ > The `Bit React Transformer` babel plugin is already running in the Preview, during `bit start`.
64
68
  > It only effects the browser bundle, and not the dists.
65
69
 
66
70
  The result looks like this:
@@ -80,6 +84,33 @@ export function Button() {
80
84
  Button.__bit_component = __bit_component;
81
85
  ```
82
86
 
87
+ ### Modes
88
+
89
+ The Component Highlighter comes in a few different modes:
90
+
91
+ - `hover` - this will track your mouse movements, and show the highlighter for the element the user is currently hovering on.
92
+ - `allChildren` - this automatically detects all components nested inside the highlighter, and apply a highlighter to them. Currently, this detection only happens once on initial setup, so it does not detect changes.
93
+
94
+ In addition to changing the `mode` prop, you can also use convenience exports from the same package:
95
+
96
+ ```tsx
97
+ import { MultiHighlighter, HoverHighlighter } from '@teambit/react.ui.component-highlighter';
98
+
99
+ function example() {
100
+ return (
101
+ <div>
102
+ <HoverHighlighter>
103
+ <App />
104
+ </HoverHighlighter>
105
+
106
+ <MultiHighlighter>
107
+ <App />
108
+ </MultiHighlighter>
109
+ </div>
110
+ );
111
+ }
112
+ ```
113
+
83
114
  ### Debounce
84
115
 
85
116
  Normally, moving quickly between elements could produce a jitter effect, where the highlighter "jumps" between elements, making interaction difficult.
@@ -88,24 +119,40 @@ First time selection will always happen immediately, for a snappy experience.
88
119
 
89
120
  You can control the debounce rate with the `debounceSelection` prop. (default - `80ms`)
90
121
 
91
- ## Multi highlighter
122
+ ## Exclusions Zones
92
123
 
93
- This component is similar to the Hover Highlighter, but provides automatic highlighting to all components nested inside it.
94
-
95
- Simply wrap your code like so, and see the highlighting in action:
124
+ To disabled highlighting in a specific area of the DOM, you can use the `<ExcludeHighlighter />` component:
96
125
 
97
126
  ```tsx
98
- import { MultiHighlighter } from '@teambit/react.ui.component-highlighter';
127
+ import { ExcludeHighlighter, excludeHighlighterAtt } from '@teambit/react.ui.component-highlighter';
99
128
 
100
129
  // ...
101
130
 
102
131
  return (
103
- <MultiHighlighter>
104
- <App />
105
- </MultiHighlighter>
132
+ <div>
133
+ <ExcludeHighlighter>
134
+ <Card>this component will not be highlighted</Card>
135
+ </ExcludeHighlighter>
136
+
137
+ {/* you can also add the exclude attribute without making a new div */}
138
+ <Card {...excludeHighlighterAtt}>this component will also be skipped</Card>
139
+ </div>
106
140
  );
107
141
  ```
108
142
 
143
+ Another options would be use use the `rule` prop.
144
+ Inspired by Webpack rules, it provides a query selector or function that the highlighter target will have to match.
145
+ For example:
146
+
147
+ ```tsx
148
+ <ComponentHighlighter rule="#include *">
149
+ <Button>will not be highlighted</Button>
150
+ <div id="include">
151
+ <Button>this will be highlighted</Button>
152
+ </div>
153
+ </ComponentHighlighter>
154
+ ```
155
+
109
156
  ## Customization
110
157
 
111
158
  Use these CSS variables to edit the highlighter color
@@ -116,7 +163,15 @@ Use these CSS variables to edit the highlighter color
116
163
  --bit-highlighter-color-active: #e79db1;
117
164
  ```
118
165
 
119
- You can also pass these classes for complete control:
166
+ While it is preferred to use the css variables, you can also set them using react props:
167
+
168
+ ```tsx
169
+ <ComponentHighlighter bgColor="#eebcc9" bgColorHover="#f6dae2" bgColorActive="#e79db1">
170
+ ...
171
+ </ComponentHighlighter>
172
+ ```
173
+
174
+ And for complete control, you can pass these classes:
120
175
 
121
176
  ```tsx
122
177
  const classes = {
@@ -128,9 +183,9 @@ const classes = {
128
183
  label?: string;
129
184
  };
130
185
 
131
- <HoverHighlighter classes={classes}>
186
+ <ComponentHighlighter classes={classes}>
132
187
  ...
133
- </HoverHighlighter>
188
+ </ComponentHighlighter>
134
189
  ```
135
190
 
136
191
  You can control the size using regular `font-size`.
@@ -25,13 +25,16 @@ const design_ui_icon_button_1 = require("@teambit/design.ui.icon-button");
25
25
  const hover_highlighter_1 = require("./hover-highlighter");
26
26
  const ShowWhenHovering = () => {
27
27
  const [disabled, setDisabled] = (0, react_1.useState)(false);
28
- return (react_1.default.createElement("div", { style: { padding: '16px 80px 32px 16px' } },
28
+ return (react_1.default.createElement("div", { style: { padding: '16px 50px 32px 16px', minWidth: 300 } },
29
29
  react_1.default.createElement(hover_highlighter_1.HoverHighlighter, { style: { padding: 16 }, disabled: disabled },
30
30
  react_1.default.createElement("div", null,
31
- "some div",
32
31
  react_1.default.createElement("br", null),
33
32
  react_1.default.createElement("div", null,
34
- react_1.default.createElement(design_ui_icon_button_1.IconButton, { onClick: () => setDisabled((x) => !x) }, "Hover here"))))));
33
+ react_1.default.createElement(design_ui_icon_button_1.IconButton, { onClick: () => setDisabled((x) => !x) }, "Hover here")),
34
+ react_1.default.createElement("div", null,
35
+ disabled ? 'X' : '✓',
36
+ " highlighter is ",
37
+ disabled ? 'disabled' : 'enabled')))));
35
38
  };
36
39
  exports.ShowWhenHovering = ShowWhenHovering;
37
40
  //# sourceMappingURL=hover-highlighter.compositions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hover-highlighter.compositions.js","sourceRoot":"","sources":["../../hover-highlighter/hover-highlighter.compositions.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAwC;AACxC,0EAA4D;AAC5D,2DAAuD;AAEhD,MAAM,gBAAgB,GAAG,GAAG,EAAE;IACnC,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,IAAA,gBAAQ,EAAU,KAAK,CAAC,CAAC;IAEzD,OAAO,CACL,uCAAK,KAAK,EAAE,EAAE,OAAO,EAAE,qBAAqB,EAAE,QAAQ,EAAE,GAAG,EAAE;QAC3D,8BAAC,oCAAgB,IAAC,KAAK,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,EAAE,QAAQ,EAAE,QAAQ;YAC1D;gBACE,yCAAM;gBACN;oBACE,8BAAC,kCAAU,IAAC,OAAO,EAAE,GAAG,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,iBAAyB,CACtE;gBACN;oBACG,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG;;oBAAkB,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS,CACpE,CACF,CACW,CACf,CACP,CAAC;AACJ,CAAC,CAAC;AAlBW,QAAA,gBAAgB,oBAkB3B"}
@@ -0,0 +1,3 @@
1
+ import { HybridHighlighterProps } from '../hybrid-highligher';
2
+ export declare type HoverHighlighterProps = Omit<HybridHighlighterProps, 'mode'>;
3
+ export declare function HoverHighlighter({ ...props }: HoverHighlighterProps): JSX.Element;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ var __rest = (this && this.__rest) || function (s, e) {
3
+ var t = {};
4
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
+ t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
+ t[p[i]] = s[p[i]];
10
+ }
11
+ return t;
12
+ };
13
+ var __importDefault = (this && this.__importDefault) || function (mod) {
14
+ return (mod && mod.__esModule) ? mod : { "default": mod };
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.HoverHighlighter = void 0;
18
+ const react_1 = __importDefault(require("react"));
19
+ const hybrid_highligher_1 = require("../hybrid-highligher");
20
+ function HoverHighlighter(_a) {
21
+ var props = __rest(_a, []);
22
+ return react_1.default.createElement(hybrid_highligher_1.HybridHighlighter, Object.assign({}, props, { mode: 'hover' }));
23
+ }
24
+ exports.HoverHighlighter = HoverHighlighter;
25
+ //# sourceMappingURL=hover-highlighter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hover-highlighter.js","sourceRoot":"","sources":["../../hover-highlighter/hover-highlighter.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,kDAA0B;AAC1B,4DAAiF;AAIjF,SAAgB,gBAAgB,CAAC,EAAmC;QAA9B,KAAK,cAAV,EAAY,CAAF;IACzC,OAAO,8BAAC,qCAAiB,oBAAK,KAAK,IAAE,IAAI,EAAE,OAAO,IAAI,CAAC;AACzD,CAAC;AAFD,4CAEC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hover-highlighter.spec.js","sourceRoot":"","sources":["../../hover-highlighter/hover-highlighter.spec.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,kDAAyC;AACzC,qDAA2C;AAC3C,kDAAsF;AACtF,oJAAwH;AAExH,2DAAuD;AAEvD,MAAM,YAAY,GAAG,CAAC,CAAC;AAEvB,SAAS,eAAe,CAAC,EAAE,QAAQ,EAA2B;IAC5D,OAAO,8CAAS,QAAQ,CAAU,CAAC;AACrC,CAAC;AAED,eAAe,CAAC,+EAAkB,CAAC,GAAG;IACpC,wDAAwD;IACxD,EAAE,EAAE,8BAA8B;CAClB,CAAC;AAEnB,EAAE,CAAC,yDAAyD,EAAE,GAAS,EAAE;IACvE,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,GAAG,IAAA,cAAM,EAC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gBAAG,EAAC,GAAS,EAAE;QACnB,iBAAS,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;IAChC,CAAC,CAAA,CAAC,CAAC;IAEH,MAAM,eAAe,GAAG,MAAM,UAAU,CAAC,cAAc,CAAC,CAAC;IAEzD,MAAM,IAAA,gBAAG,EAAC,GAAS,EAAE;QACnB,uBAAuB;QACvB,iBAAS,CAAC,UAAU,CAAC,eAAe,CAAC,CAAC;QACtC,wBAAwB;QACxB,iBAAS,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAC;QACpC,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,YAAY,GAAG,EAAE,CAAC,CAAC,CAAC;IACzE,CAAC,CAAA,CAAC,CAAC;IAEH,sDAAsD;IACtD,uEAAuE;IACvE,MAAM,CAAC,WAAW,CAAC,cAAc,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;AACjD,CAAC,CAAA,CAAC,CAAC"}
@@ -0,0 +1,4 @@
1
+ export { useHoverHighlighter } from './use-hover-highlighter';
2
+ export type { useHoverHighlighterOptions } from './use-hover-highlighter';
3
+ export { HoverHighlighter } from './hover-highlighter';
4
+ export type { HoverHighlighterProps } from './hover-highlighter';
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HoverHighlighter = exports.useHoverHighlighter = void 0;
4
+ var use_hover_highlighter_1 = require("./use-hover-highlighter");
5
+ Object.defineProperty(exports, "useHoverHighlighter", { enumerable: true, get: function () { return use_hover_highlighter_1.useHoverHighlighter; } });
6
+ var hover_highlighter_1 = require("./hover-highlighter");
7
+ Object.defineProperty(exports, "HoverHighlighter", { enumerable: true, get: function () { return hover_highlighter_1.HoverHighlighter; } });
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../hover-highlighter/index.ts"],"names":[],"mappings":";;;AAAA,iEAA8D;AAArD,4HAAA,mBAAmB,OAAA;AAG5B,yDAAuD;AAA9C,qHAAA,gBAAgB,OAAA"}
@@ -0,0 +1,17 @@
1
+ import React from 'react';
2
+ import { HighlightTarget } from '../element-highlighter';
3
+ import { MatchRule } from '../rule-matcher';
4
+ export declare type useHoverHighlighterOptions = {
5
+ debounceDuration: number;
6
+ scopeClass: string;
7
+ disabled?: boolean;
8
+ rule?: MatchRule;
9
+ };
10
+ /** fires onChange when targeting a new component */
11
+ export declare function useHoverHighlighter<T extends HTMLElement = HTMLElement>(onChange: (target?: HighlightTarget) => void, props: React.HTMLAttributes<T>, { debounceDuration, scopeClass, disabled, rule }: useHoverHighlighterOptions): {
12
+ onMouseOver: (event: React.MouseEvent<T, MouseEvent>) => void;
13
+ onMouseLeave: (event: React.MouseEvent<T, MouseEvent>) => void;
14
+ } | {
15
+ onMouseOver?: undefined;
16
+ onMouseLeave?: undefined;
17
+ };
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useHoverHighlighter = void 0;
4
+ const react_1 = require("react");
5
+ const use_debounce_1 = require("use-debounce");
6
+ const react_modules_dom_to_react_1 = require("@teambit/react.modules.dom-to-react");
7
+ const react_ui_hover_selector_1 = require("@teambit/react.ui.hover-selector");
8
+ const react_ui_highlighter_component_metadata_bit_component_meta_1 = require("@teambit/react.ui.highlighter.component-metadata.bit-component-meta");
9
+ const ignore_highlighter_1 = require("../ignore-highlighter");
10
+ const rule_matcher_1 = require("../rule-matcher");
11
+ /** fires onChange when targeting a new component */
12
+ function useHoverHighlighter(onChange, props = {}, { debounceDuration, scopeClass, disabled, rule }) {
13
+ const { handleElement } = useHoverHandler({ onChange, scopeClass, debounceDuration, disabled, rule });
14
+ const handlers = (0, react_ui_hover_selector_1.useHoverSelection)(disabled ? undefined : handleElement, props);
15
+ return handlers;
16
+ }
17
+ exports.useHoverHighlighter = useHoverHighlighter;
18
+ function useHoverHandler({ onChange, scopeClass = '', debounceDuration, disabled, rule }) {
19
+ // debounced method is ref'ed, so no need for useCallback
20
+ const _handleElement = (element) => {
21
+ // clear highlighter at the edges:
22
+ if (!element || element.hasAttribute('data-nullify-component-highlight')) {
23
+ onChange(undefined);
24
+ return;
25
+ }
26
+ // skip DOM trees having 'data-ignore-component-highlight'
27
+ if (element.closest(`.${scopeClass} ${ignore_highlighter_1.excludeHighlighterSelector}`))
28
+ return;
29
+ const result = bubbleToBitComponent(element, rule ? (current) => (0, rule_matcher_1.ruleMatcher)(current, rule) : undefined);
30
+ if (!result)
31
+ return;
32
+ onChange({
33
+ element: result.element,
34
+ id: result.meta.id,
35
+ scopeLink: undefined,
36
+ link: result.meta.homepage,
37
+ local: result.meta.exported === false,
38
+ });
39
+ };
40
+ const handleElement = (0, use_debounce_1.useDebouncedCallback)(_handleElement, debounceDuration);
41
+ // clear when disabling
42
+ (0, react_1.useEffect)(() => {
43
+ if (disabled)
44
+ handleElement.cancel();
45
+ }, [disabled, handleElement]);
46
+ return { handleElement };
47
+ }
48
+ /** go up the dom tree until reaching a react bit component */
49
+ function bubbleToBitComponent(element, filter) {
50
+ for (let current = element; current; current = current.parentElement) {
51
+ current = (0, react_modules_dom_to_react_1.toRootElement)(current);
52
+ if (!current || (filter === null || filter === void 0 ? void 0 : filter(current)) === false)
53
+ return undefined;
54
+ const component = (0, react_modules_dom_to_react_1.domToReact)(current);
55
+ if ((0, react_ui_highlighter_component_metadata_bit_component_meta_1.hasComponentMeta)(component)) {
56
+ const meta = component.__bit_component;
57
+ return {
58
+ element: current,
59
+ component,
60
+ meta,
61
+ };
62
+ }
63
+ }
64
+ return undefined;
65
+ }
66
+ //# sourceMappingURL=use-hover-highlighter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-hover-highlighter.js","sourceRoot":"","sources":["../../hover-highlighter/use-hover-highlighter.tsx"],"names":[],"mappings":";;;AAAA,iCAAyC;AACzC,+CAAoD;AACpD,oFAAgF;AAChF,8EAAqE;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YAClB,SAAS,EAAE,SAAS;YACpB,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,QAAQ;YAC1B,KAAK,EAAE,MAAM,CAAC,IAAI,CAAC,QAAQ,KAAK,KAAK;SACtC,CAAC,CAAC;IACL,CAAC,CAAC;IAEF,MAAM,aAAa,GAAG,IAAA,mCAAoB,EAAC,cAAc,EAAE,gBAAgB,CAAC,CAAC;IAE7E,uBAAuB;IACvB,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,IAAI,QAAQ;YAAE,aAAa,CAAC,MAAM,EAAE,CAAC;IACvC,CAAC,EAAE,CAAC,QAAQ,EAAE,aAAa,CAAC,CAAC,CAAC;IAE9B,OAAO,EAAE,aAAa,EAAE,CAAC;AAC3B,CAAC;AAED,8DAA8D;AAC9D,SAAS,oBAAoB,CAAC,OAA2B,EAAE,MAAuC;IAChG,KAAK,IAAI,OAAO,GAAG,OAAO,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,aAAa,EAAE;QACpE,OAAO,GAAG,IAAA,0CAAa,EAAC,OAAO,CAAC,CAAC;QACjC,IAAI,CAAC,OAAO,IAAI,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAG,OAAO,CAAC,MAAK,KAAK;YAAE,OAAO,SAAS,CAAC;QAE9D,MAAM,SAAS,GAAG,IAAA,uCAAU,EAAC,OAAO,CAAC,CAAC;QAEtC,IAAI,IAAA,6EAAgB,EAAC,SAAS,CAAC,EAAE;YAC/B,MAAM,IAAI,GAAG,SAAS,CAAC,eAAe,CAAC;YAEvC,OAAO;gBACL,OAAO,EAAE,OAAO;gBAChB,SAAS;gBACT,IAAI;aACL,CAAC;SACH;KACF;IAED,OAAO,SAAS,CAAC;AACnB,CAAC"}
@@ -0,0 +1,34 @@
1
+ import React, { CSSProperties } from 'react';
2
+ import { Placement, HighlightClasses } from '../element-highlighter';
3
+ import type { MatchRule } from '../rule-matcher';
4
+ export interface HybridHighlighterProps extends React.HTMLAttributes<HTMLDivElement> {
5
+ /** stop all highlighting and drop listeners */
6
+ disabled?: boolean;
7
+ /** default pop location for the label */
8
+ placement?: Placement;
9
+ /** customize styles */
10
+ classes?: HighlightClasses;
11
+ /** customize highlighter */
12
+ highlightStyle?: CSSProperties;
13
+ /** debounces element hover selection.
14
+ * A higher value will reduce element lookups as well as "keep" the highlight on the current element for longer.
15
+ * Initial selection (when no element is currently selected) will always happen immediately to improve the user experience.
16
+ * @default 80ms
17
+ */
18
+ debounceSelection?: number;
19
+ /** continually update frame position to match moving elements */
20
+ watchMotion?: boolean;
21
+ /** filter highlighter targets by this query selector. (May be a more complex object in the future) */
22
+ rule?: MatchRule;
23
+ /** set the behavior of the highlighter.
24
+ * `disabled` - stops highlighting.
25
+ * `allChildren` - highlights all components rendered under children
26
+ * `hover` - highlighters the component immediately under the mouse cursor
27
+ * */
28
+ mode?: 'allChildren' | 'hover';
29
+ bgColor?: string;
30
+ bgColorHover?: string;
31
+ bgColorActive?: string;
32
+ }
33
+ /** automatically highlight components on hover */
34
+ export declare function HybridHighlighter({ disabled, mode, debounceSelection, watchMotion, placement, rule, classes, highlightStyle, className, style, bgColor, bgColorHover, bgColorActive, children, ...rest }: HybridHighlighterProps): JSX.Element;