@teambit/react.ui.component-highlighter 0.0.485 → 0.0.489
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/component-highlighter.docs.md +86 -31
- package/dist/component-highlighter.docs.md +86 -31
- package/dist/{component-highlighter/hover-highlighter → hover-highlighter}/hover-highlighter.compositions.d.ts +0 -0
- package/dist/{component-highlighter/hover-highlighter → hover-highlighter}/hover-highlighter.compositions.js +6 -3
- package/dist/hover-highlighter/hover-highlighter.compositions.js.map +1 -0
- package/dist/hover-highlighter/hover-highlighter.d.ts +3 -0
- package/dist/hover-highlighter/hover-highlighter.js +25 -0
- package/dist/hover-highlighter/hover-highlighter.js.map +1 -0
- package/dist/{component-highlighter/hover-highlighter → hover-highlighter}/hover-highlighter.spec.d.ts +0 -0
- package/dist/{component-highlighter/hover-highlighter → hover-highlighter}/hover-highlighter.spec.js +0 -0
- package/dist/hover-highlighter/hover-highlighter.spec.js.map +1 -0
- package/dist/hover-highlighter/index.d.ts +4 -0
- package/dist/hover-highlighter/index.js +8 -0
- package/dist/hover-highlighter/index.js.map +1 -0
- package/dist/hover-highlighter/use-hover-highlighter.d.ts +17 -0
- package/dist/hover-highlighter/use-hover-highlighter.js +66 -0
- package/dist/hover-highlighter/use-hover-highlighter.js.map +1 -0
- package/dist/hybrid-highligher/hybrid-highlighter.d.ts +34 -0
- package/dist/hybrid-highligher/hybrid-highlighter.js +74 -0
- package/dist/hybrid-highligher/hybrid-highlighter.js.map +1 -0
- package/dist/hybrid-highligher/index.d.ts +2 -0
- package/dist/hybrid-highligher/index.js +6 -0
- package/dist/hybrid-highligher/index.js.map +1 -0
- package/dist/index.d.ts +5 -2
- package/dist/index.js +5 -3
- package/dist/index.js.map +1 -1
- package/dist/multi-highlighter/multi-highlighter.composition.d.ts +2 -0
- package/dist/multi-highlighter/multi-highlighter.composition.js +34 -3
- package/dist/multi-highlighter/multi-highlighter.composition.js.map +1 -1
- package/dist/multi-highlighter/multi-highlighter.d.ts +3 -15
- package/dist/multi-highlighter/multi-highlighter.js +4 -63
- package/dist/multi-highlighter/multi-highlighter.js.map +1 -1
- package/dist/multi-highlighter/use-multi-highlighter.d.ts +13 -0
- package/dist/multi-highlighter/use-multi-highlighter.js +51 -0
- package/dist/multi-highlighter/use-multi-highlighter.js.map +1 -0
- package/dist/rule-matcher.d.ts +2 -0
- package/dist/rule-matcher.js +15 -0
- package/dist/rule-matcher.js.map +1 -0
- package/{component-highlighter/hover-highlighter → hover-highlighter}/hover-highlighter.compositions.tsx +4 -2
- package/{component-highlighter/hover-highlighter → hover-highlighter}/hover-highlighter.spec.tsx +0 -0
- package/hover-highlighter/hover-highlighter.tsx +8 -0
- package/hover-highlighter/index.ts +5 -0
- package/hover-highlighter/use-hover-highlighter.tsx +93 -0
- package/hybrid-highligher/hybrid-highlighter.tsx +126 -0
- package/hybrid-highligher/index.ts +2 -0
- package/index.ts +7 -2
- package/multi-highlighter/multi-highlighter.composition.tsx +40 -2
- package/multi-highlighter/multi-highlighter.tsx +5 -81
- package/multi-highlighter/use-multi-highlighter.tsx +70 -0
- package/package-tar/teambit-react.ui.component-highlighter-0.0.489.tgz +0 -0
- package/package.json +14 -12
- package/rule-matcher.tsx +15 -0
- package/component-highlighter/hover-highlighter/hover-highlighter.module.scss +0 -13
- package/component-highlighter/hover-highlighter/hover-highlighter.tsx +0 -120
- package/component-highlighter/hover-highlighter/index.ts +0 -1
- package/component-highlighter/index.ts +0 -2
- package/dist/component-highlighter/hover-highlighter/hover-highlighter.compositions.js.map +0 -1
- package/dist/component-highlighter/hover-highlighter/hover-highlighter.d.ts +0 -21
- package/dist/component-highlighter/hover-highlighter/hover-highlighter.js +0 -100
- package/dist/component-highlighter/hover-highlighter/hover-highlighter.js.map +0 -1
- package/dist/component-highlighter/hover-highlighter/hover-highlighter.module.scss +0 -13
- package/dist/component-highlighter/hover-highlighter/hover-highlighter.spec.js.map +0 -1
- package/dist/component-highlighter/hover-highlighter/index.d.ts +0 -1
- package/dist/component-highlighter/hover-highlighter/index.js +0 -6
- package/dist/component-highlighter/hover-highlighter/index.js.map +0 -1
- package/dist/component-highlighter/index.d.ts +0 -2
- package/dist/component-highlighter/index.js +0 -6
- package/dist/component-highlighter/index.js.map +0 -1
- package/package-tar/teambit-react.ui.component-highlighter-0.0.485.tgz +0 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
22
|
+
var t = {};
|
|
23
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
24
|
+
t[p] = s[p];
|
|
25
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
26
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
27
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
28
|
+
t[p[i]] = s[p[i]];
|
|
29
|
+
}
|
|
30
|
+
return t;
|
|
31
|
+
};
|
|
32
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
33
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
34
|
+
};
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.HybridHighlighter = void 0;
|
|
37
|
+
const react_1 = __importStar(require("react"));
|
|
38
|
+
const classnames_1 = __importDefault(require("classnames"));
|
|
39
|
+
const uuid_1 = require("uuid");
|
|
40
|
+
const hover_highlighter_1 = require("../hover-highlighter");
|
|
41
|
+
const element_highlighter_1 = require("../element-highlighter");
|
|
42
|
+
const use_multi_highlighter_1 = require("../multi-highlighter/use-multi-highlighter");
|
|
43
|
+
/** automatically highlight components on hover */
|
|
44
|
+
function HybridHighlighter(_a) {
|
|
45
|
+
var { disabled, mode = 'hover', debounceSelection = 80, watchMotion = true, placement, rule, classes, highlightStyle, className, style, bgColor, bgColorHover, bgColorActive, children } = _a, rest = __rest(_a, ["disabled", "mode", "debounceSelection", "watchMotion", "placement", "rule", "classes", "highlightStyle", "className", "style", "bgColor", "bgColorHover", "bgColorActive", "children"]);
|
|
46
|
+
const ref = (0, react_1.createRef)();
|
|
47
|
+
const [targets, setTarget] = (0, react_1.useState)({});
|
|
48
|
+
const scopeClass = (0, react_1.useRef)(`hl-scope-${(0, uuid_1.v4)()}`).current;
|
|
49
|
+
const hasTargets = Object.entries(targets).length > 0;
|
|
50
|
+
// clear targets when disabled
|
|
51
|
+
(0, react_1.useEffect)(() => {
|
|
52
|
+
if (disabled)
|
|
53
|
+
setTarget({});
|
|
54
|
+
}, [disabled]);
|
|
55
|
+
const handlers = (0, hover_highlighter_1.useHoverHighlighter)((nextTarget) => setTarget(nextTarget ? { 'hover-target': nextTarget } : {}), rest, {
|
|
56
|
+
debounceDuration: hasTargets ? debounceSelection : 0,
|
|
57
|
+
scopeClass,
|
|
58
|
+
disabled: disabled || mode !== 'hover',
|
|
59
|
+
rule,
|
|
60
|
+
});
|
|
61
|
+
(0, use_multi_highlighter_1.useMultiHighlighter)({
|
|
62
|
+
onChange: setTarget,
|
|
63
|
+
scopeRef: ref,
|
|
64
|
+
scopeClass,
|
|
65
|
+
disabled: disabled || mode !== 'allChildren',
|
|
66
|
+
rule,
|
|
67
|
+
});
|
|
68
|
+
const _styles = (0, react_1.useMemo)(() => (Object.assign({ '--bit-highlighter-color': bgColor, '--bit-highlighter-color-hover': bgColorHover, '--bit-highlighter-color-active': bgColorActive }, style)), [bgColor, bgColorHover, bgColorActive, style]);
|
|
69
|
+
return (react_1.default.createElement("div", Object.assign({ ref: ref }, rest, handlers, { style: _styles, className: (0, classnames_1.default)(className, scopeClass), "data-nullify-component-highlight": true }),
|
|
70
|
+
children,
|
|
71
|
+
Object.entries(targets).map(([key, target]) => (react_1.default.createElement(element_highlighter_1.ElementHighlighter, { key: key, target: target, classes: classes, style: highlightStyle, placement: placement, watchMotion: watchMotion })))));
|
|
72
|
+
}
|
|
73
|
+
exports.HybridHighlighter = HybridHighlighter;
|
|
74
|
+
//# sourceMappingURL=hybrid-highlighter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hybrid-highlighter.js","sourceRoot":"","sources":["../../hybrid-highligher/hybrid-highlighter.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAA8F;AAC9F,4DAAoC;AACpC,+BAA0B;AAE1B,4DAA2D;AAC3D,gEAA0G;AAC1G,sFAAiF;AAmCjF,kDAAkD;AAClD,SAAgB,iBAAiB,CAAC,EAiBT;QAjBS,EAChC,QAAQ,EACR,IAAI,GAAG,OAAO,EACd,iBAAiB,GAAG,EAAE,EACtB,WAAW,GAAG,IAAI,EAClB,SAAS,EACT,IAAI,EAEJ,OAAO,EACP,cAAc,EACd,SAAS,EACT,KAAK,EACL,OAAO,EACP,YAAY,EACZ,aAAa,EACb,QAAQ,OAEe,EADpB,IAAI,cAhByB,wLAiBjC,CADQ;IAEP,MAAM,GAAG,GAAG,IAAA,iBAAS,GAAkB,CAAC;IACxC,MAAM,CAAC,OAAO,EAAE,SAAS,CAAC,GAAG,IAAA,gBAAQ,EAAkC,EAAE,CAAC,CAAC;IAC3E,MAAM,UAAU,GAAG,IAAA,cAAM,EAAC,YAAY,IAAA,SAAE,GAAE,EAAE,CAAC,CAAC,OAAO,CAAC;IACtD,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;IAEtD,8BAA8B;IAC9B,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,IAAI,QAAQ;YAAE,SAAS,CAAC,EAAE,CAAC,CAAC;IAC9B,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;IAEf,MAAM,QAAQ,GAAG,IAAA,uCAAmB,EAClC,CAAC,UAAU,EAAE,EAAE,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,cAAc,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAC3E,IAAI,EACJ;QACE,gBAAgB,EAAE,UAAU,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC;QACpD,UAAU;QACV,QAAQ,EAAE,QAAQ,IAAI,IAAI,KAAK,OAAO;QACtC,IAAI;KACL,CACF,CAAC;IAEF,IAAA,2CAAmB,EAAC;QAClB,QAAQ,EAAE,SAAS;QACnB,QAAQ,EAAE,GAAG;QACb,UAAU;QACV,QAAQ,EAAE,QAAQ,IAAI,IAAI,KAAK,aAAa;QAC5C,IAAI;KACL,CAAC,CAAC;IAEH,MAAM,OAAO,GAAG,IAAA,eAAO,EACrB,GAAG,EAAE,CAAC,iBACJ,yBAAyB,EAAE,OAAO,EAClC,+BAA+B,EAAE,YAAY,EAC7C,gCAAgC,EAAE,aAAa,IAC5C,KAAK,EACR,EACF,CAAC,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,KAAK,CAAC,CAC9C,CAAC;IAEF,OAAO,CACL,qDACE,GAAG,EAAE,GAAG,IACJ,IAAI,EACJ,QAAQ,IACZ,KAAK,EAAE,OAAO,EACd,SAAS,EAAE,IAAA,oBAAU,EAAC,SAAS,EAAE,UAAU,CAAC;QAG3C,QAAQ;QAKR,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC,CAC9C,8BAAC,wCAAkB,IACjB,GAAG,EAAE,GAAG,EACR,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE,cAAc,EACrB,SAAS,EAAE,SAAS,EACpB,WAAW,EAAE,WAAW,GACxB,CACH,CAAC,CACE,CACP,CAAC;AACJ,CAAC;AAnFD,8CAmFC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HybridHighlighter = void 0;
|
|
4
|
+
var hybrid_highlighter_1 = require("./hybrid-highlighter");
|
|
5
|
+
Object.defineProperty(exports, "HybridHighlighter", { enumerable: true, get: function () { return hybrid_highlighter_1.HybridHighlighter; } });
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../hybrid-highligher/index.ts"],"names":[],"mappings":";;;AAAA,2DAAyD;AAAhD,uHAAA,iBAAiB,OAAA"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export type {
|
|
1
|
+
export { HybridHighlighter as ComponentHighlighter } from './hybrid-highligher';
|
|
2
|
+
export type { HybridHighlighterProps as ComponentHighlightProps } from './hybrid-highligher';
|
|
3
|
+
export { HoverHighlighter } from './hover-highlighter';
|
|
4
|
+
export type { HoverHighlighterProps } from './hover-highlighter';
|
|
3
5
|
export { MultiHighlighter } from './multi-highlighter';
|
|
4
6
|
export type { MultiHighlighterProps } from './multi-highlighter';
|
|
5
7
|
export { ElementHighlighter } from './element-highlighter';
|
|
6
8
|
export type { ElementHighlighterProps, HighlightTarget, Placement, HighlightClasses } from './element-highlighter';
|
|
7
9
|
export { ExcludeHighlighter, excludeHighlighterAtt, excludeHighlighterSelector, excludeHighlighterAttrName, } from './ignore-highlighter';
|
|
10
|
+
export type { MatchRule } from './rule-matcher';
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.excludeHighlighterAttrName = exports.excludeHighlighterSelector = exports.excludeHighlighterAtt = exports.ExcludeHighlighter = exports.ElementHighlighter = exports.MultiHighlighter = exports.ComponentHighlighter = void 0;
|
|
4
|
-
var
|
|
5
|
-
Object.defineProperty(exports, "ComponentHighlighter", { enumerable: true, get: function () { return
|
|
3
|
+
exports.excludeHighlighterAttrName = exports.excludeHighlighterSelector = exports.excludeHighlighterAtt = exports.ExcludeHighlighter = exports.ElementHighlighter = exports.MultiHighlighter = exports.HoverHighlighter = exports.ComponentHighlighter = void 0;
|
|
4
|
+
var hybrid_highligher_1 = require("./hybrid-highligher");
|
|
5
|
+
Object.defineProperty(exports, "ComponentHighlighter", { enumerable: true, get: function () { return hybrid_highligher_1.HybridHighlighter; } });
|
|
6
|
+
var hover_highlighter_1 = require("./hover-highlighter");
|
|
7
|
+
Object.defineProperty(exports, "HoverHighlighter", { enumerable: true, get: function () { return hover_highlighter_1.HoverHighlighter; } });
|
|
6
8
|
var multi_highlighter_1 = require("./multi-highlighter");
|
|
7
9
|
Object.defineProperty(exports, "MultiHighlighter", { enumerable: true, get: function () { return multi_highlighter_1.MultiHighlighter; } });
|
|
8
10
|
var element_highlighter_1 = require("./element-highlighter");
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;AAAA,yDAAgF;AAAvE,yHAAA,iBAAiB,OAAwB;AAGlD,yDAAuD;AAA9C,qHAAA,gBAAgB,OAAA;AAGzB,yDAAuD;AAA9C,qHAAA,gBAAgB,OAAA;AAGzB,6DAA2D;AAAlD,yHAAA,kBAAkB,OAAA;AAG3B,2DAK8B;AAJ5B,wHAAA,kBAAkB,OAAA;AAClB,2HAAA,qBAAqB,OAAA;AACrB,gIAAA,0BAA0B,OAAA;AAC1B,gIAAA,0BAA0B,OAAA"}
|
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
export declare const MultiHighlighterPreview: () => JSX.Element;
|
|
2
2
|
export declare const MultiHighlighterWithCustomColors: () => JSX.Element;
|
|
3
|
+
export declare const MultiHighlighterInsideIgnore: () => JSX.Element;
|
|
4
|
+
export declare const MultiHighlighterWithRule: () => JSX.Element;
|
|
@@ -3,13 +3,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.MultiHighlighterWithCustomColors = exports.MultiHighlighterPreview = void 0;
|
|
6
|
+
exports.MultiHighlighterWithRule = exports.MultiHighlighterInsideIgnore = exports.MultiHighlighterWithCustomColors = exports.MultiHighlighterPreview = void 0;
|
|
7
7
|
const react_1 = __importDefault(require("react"));
|
|
8
8
|
// import { EnterpriseOffering } from '@teambit/evangelist.pages.enterprise-offering';
|
|
9
9
|
const react_ui_highlighter_component_metadata_bit_component_meta_1 = require("@teambit/react.ui.highlighter.component-metadata.bit-component-meta");
|
|
10
|
+
const ignore_highlighter_1 = require("../ignore-highlighter");
|
|
10
11
|
const multi_highlighter_1 = require("./multi-highlighter");
|
|
11
12
|
const MultiHighlighterPreview = () => {
|
|
12
|
-
return (react_1.default.createElement(multi_highlighter_1.MultiHighlighter, { style: { padding: 40 } },
|
|
13
|
+
return (react_1.default.createElement(multi_highlighter_1.MultiHighlighter, { style: { padding: 40, minWidth: 200 } },
|
|
13
14
|
react_1.default.createElement(react_ui_highlighter_component_metadata_bit_component_meta_1.MockedComponentWithMeta, null, "hover here"),
|
|
14
15
|
react_1.default.createElement("br", null),
|
|
15
16
|
react_1.default.createElement("br", null),
|
|
@@ -18,7 +19,7 @@ const MultiHighlighterPreview = () => {
|
|
|
18
19
|
};
|
|
19
20
|
exports.MultiHighlighterPreview = MultiHighlighterPreview;
|
|
20
21
|
const MultiHighlighterWithCustomColors = () => {
|
|
21
|
-
return (react_1.default.createElement(multi_highlighter_1.MultiHighlighter, { style: { padding: 40, color: 'yellow' }, bgColor: "cornflowerblue", bgColorHover: "blue", bgColorActive: "DarkSlateBlue" },
|
|
22
|
+
return (react_1.default.createElement(multi_highlighter_1.MultiHighlighter, { style: { padding: 40, minWidth: 200, color: 'yellow' }, bgColor: "cornflowerblue", bgColorHover: "blue", bgColorActive: "DarkSlateBlue" },
|
|
22
23
|
react_1.default.createElement(react_ui_highlighter_component_metadata_bit_component_meta_1.MockedComponentWithMeta, null, "hover here"),
|
|
23
24
|
react_1.default.createElement("br", null),
|
|
24
25
|
react_1.default.createElement("br", null),
|
|
@@ -26,6 +27,36 @@ const MultiHighlighterWithCustomColors = () => {
|
|
|
26
27
|
react_1.default.createElement(react_ui_highlighter_component_metadata_bit_component_meta_1.MockedComponentWithMeta, null, "also here")));
|
|
27
28
|
};
|
|
28
29
|
exports.MultiHighlighterWithCustomColors = MultiHighlighterWithCustomColors;
|
|
30
|
+
const MultiHighlighterInsideIgnore = () => {
|
|
31
|
+
return (react_1.default.createElement(ignore_highlighter_1.ExcludeHighlighter, null,
|
|
32
|
+
react_1.default.createElement(multi_highlighter_1.MultiHighlighter, null,
|
|
33
|
+
"Multi Highlighter should still work when inside ",
|
|
34
|
+
react_1.default.createElement("code", null, '<ExcludeHighlighter>'),
|
|
35
|
+
react_1.default.createElement("br", null),
|
|
36
|
+
"It should only skip exclusion zones inside of it.",
|
|
37
|
+
react_1.default.createElement("br", null),
|
|
38
|
+
react_1.default.createElement("br", null),
|
|
39
|
+
react_1.default.createElement("br", null),
|
|
40
|
+
react_1.default.createElement(react_ui_highlighter_component_metadata_bit_component_meta_1.MockedComponentWithMeta, null, "hover here"),
|
|
41
|
+
react_1.default.createElement("br", null),
|
|
42
|
+
react_1.default.createElement("br", null),
|
|
43
|
+
react_1.default.createElement("br", null),
|
|
44
|
+
react_1.default.createElement(react_ui_highlighter_component_metadata_bit_component_meta_1.MockedComponentWithMeta, null, "also here"))));
|
|
45
|
+
};
|
|
46
|
+
exports.MultiHighlighterInsideIgnore = MultiHighlighterInsideIgnore;
|
|
47
|
+
const MultiHighlighterWithRule = () => {
|
|
48
|
+
return (react_1.default.createElement(multi_highlighter_1.MultiHighlighter, { rule: "#someSubTree *" },
|
|
49
|
+
react_1.default.createElement("br", null),
|
|
50
|
+
react_1.default.createElement("br", null),
|
|
51
|
+
react_1.default.createElement("br", null),
|
|
52
|
+
react_1.default.createElement(react_ui_highlighter_component_metadata_bit_component_meta_1.MockedComponentWithMeta, null, "no highlighter"),
|
|
53
|
+
react_1.default.createElement("br", null),
|
|
54
|
+
react_1.default.createElement("br", null),
|
|
55
|
+
react_1.default.createElement("br", null),
|
|
56
|
+
react_1.default.createElement("div", { id: "someSubTree" },
|
|
57
|
+
react_1.default.createElement(react_ui_highlighter_component_metadata_bit_component_meta_1.MockedComponentWithMeta, null, "this will be highlighted"))));
|
|
58
|
+
};
|
|
59
|
+
exports.MultiHighlighterWithRule = MultiHighlighterWithRule;
|
|
29
60
|
// export const HighlightingAllElementsInTheEnterprisePage = () => {
|
|
30
61
|
// return (
|
|
31
62
|
// <MultiHighlighter>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"multi-highlighter.composition.js","sourceRoot":"","sources":["../../multi-highlighter/multi-highlighter.composition.tsx"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAC1B,sFAAsF;AACtF,oJAA8G;AAC9G,2DAAuD;AAEhD,MAAM,uBAAuB,GAAG,GAAG,EAAE;IAC1C,OAAO,CACL,8BAAC,oCAAgB,IAAC,KAAK,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE;
|
|
1
|
+
{"version":3,"file":"multi-highlighter.composition.js","sourceRoot":"","sources":["../../multi-highlighter/multi-highlighter.composition.tsx"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAC1B,sFAAsF;AACtF,oJAA8G;AAC9G,8DAA2D;AAC3D,2DAAuD;AAEhD,MAAM,uBAAuB,GAAG,GAAG,EAAE;IAC1C,OAAO,CACL,8BAAC,oCAAgB,IAAC,KAAK,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE,GAAG,EAAE;QACrD,8BAAC,oFAAuB,qBAAqC;QAC7D,yCAAM;QACN,yCAAM;QACN,yCAAM;QACN,8BAAC,oFAAuB,oBAAoC,CAC3C,CACpB,CAAC;AACJ,CAAC,CAAC;AAVW,QAAA,uBAAuB,2BAUlC;AAEK,MAAM,gCAAgC,GAAG,GAAG,EAAE;IACnD,OAAO,CACL,8BAAC,oCAAgB,IACf,KAAK,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE,GAAG,EAAE,KAAK,EAAE,QAAQ,EAAE,EACtD,OAAO,EAAC,gBAAgB,EACxB,YAAY,EAAC,MAAM,EACnB,aAAa,EAAC,eAAe;QAE7B,8BAAC,oFAAuB,qBAAqC;QAC7D,yCAAM;QACN,yCAAM;QACN,yCAAM;QACN,8BAAC,oFAAuB,oBAAoC,CAC3C,CACpB,CAAC;AACJ,CAAC,CAAC;AAfW,QAAA,gCAAgC,oCAe3C;AAEK,MAAM,4BAA4B,GAAG,GAAG,EAAE;IAC/C,OAAO,CACL,8BAAC,uCAAkB;QACjB,8BAAC,oCAAgB;;YACiC,4CAAO,sBAAsB,CAAQ;YACrF,yCAAM;;YAEN,yCAAM;YACN,yCAAM;YACN,yCAAM;YACN,8BAAC,oFAAuB,qBAAqC;YAC7D,yCAAM;YACN,yCAAM;YACN,yCAAM;YACN,8BAAC,oFAAuB,oBAAoC,CAC3C,CACA,CACtB,CAAC;AACJ,CAAC,CAAC;AAlBW,QAAA,4BAA4B,gCAkBvC;AAEK,MAAM,wBAAwB,GAAG,GAAG,EAAE;IAC3C,OAAO,CACL,8BAAC,oCAAgB,IAAC,IAAI,EAAC,gBAAgB;QACrC,yCAAM;QACN,yCAAM;QACN,yCAAM;QACN,8BAAC,oFAAuB,yBAAyC;QACjE,yCAAM;QACN,yCAAM;QACN,yCAAM;QACN,uCAAK,EAAE,EAAC,aAAa;YACnB,8BAAC,oFAAuB,mCAAmD,CACvE,CACW,CACpB,CAAC;AACJ,CAAC,CAAC;AAfW,QAAA,wBAAwB,4BAenC;AAEF,oEAAoE;AACpE,aAAa;AACb,yBAAyB;AACzB,uDAAuD;AACvD,0BAA0B;AAC1B,OAAO;AACP,KAAK"}
|
|
@@ -1,15 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
disabled?: boolean;
|
|
5
|
-
/**
|
|
6
|
-
* continually update highlighter position to match dom elements as they move. Use with caution, might be slow
|
|
7
|
-
* @default false
|
|
8
|
-
*/
|
|
9
|
-
watchMotion?: boolean;
|
|
10
|
-
bgColor?: string;
|
|
11
|
-
bgColorHover?: string;
|
|
12
|
-
bgColorActive?: string;
|
|
13
|
-
highlighterOptions?: ElementHighlighterProps;
|
|
14
|
-
}
|
|
15
|
-
export declare function MultiHighlighter({ children, disabled, watchMotion, style, bgColor, bgColorActive, bgColorHover, highlighterOptions, ...rest }: MultiHighlighterProps): JSX.Element;
|
|
1
|
+
import { HybridHighlighterProps } from '../hybrid-highligher';
|
|
2
|
+
export declare type MultiHighlighterProps = Omit<HybridHighlighterProps, 'mode'>;
|
|
3
|
+
export declare function MultiHighlighter({ watchMotion, ...props }: MultiHighlighterProps): JSX.Element;
|
|
@@ -1,23 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
-
}) : function(o, v) {
|
|
12
|
-
o["default"] = v;
|
|
13
|
-
});
|
|
14
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
-
if (mod && mod.__esModule) return mod;
|
|
16
|
-
var result = {};
|
|
17
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
-
__setModuleDefault(result, mod);
|
|
19
|
-
return result;
|
|
20
|
-
};
|
|
21
2
|
var __rest = (this && this.__rest) || function (s, e) {
|
|
22
3
|
var t = {};
|
|
23
4
|
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
@@ -34,51 +15,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
34
15
|
};
|
|
35
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
17
|
exports.MultiHighlighter = void 0;
|
|
37
|
-
const react_1 =
|
|
38
|
-
const
|
|
39
|
-
const react_ui_component_highlighter_1 = require("@teambit/react.ui.component-highlighter");
|
|
40
|
-
const react_modules_dom_to_react_1 = require("@teambit/react.modules.dom-to-react");
|
|
41
|
-
const react_ui_highlighter_component_metadata_bit_component_meta_1 = require("@teambit/react.ui.highlighter.component-metadata.bit-component-meta");
|
|
42
|
-
const ignore_highlighter_1 = require("../ignore-highlighter");
|
|
43
|
-
// TODO - reuse selector from @teambit/react.ui.component-highlighter
|
|
44
|
-
const allExceptHighlighterQuery = `:not(${ignore_highlighter_1.excludeHighlighterSelector}, ${ignore_highlighter_1.excludeHighlighterSelector} *)`;
|
|
18
|
+
const react_1 = __importDefault(require("react"));
|
|
19
|
+
const hybrid_highligher_1 = require("../hybrid-highligher");
|
|
45
20
|
function MultiHighlighter(_a) {
|
|
46
|
-
var {
|
|
47
|
-
|
|
48
|
-
const [targets, setTargets] = (0, react_1.useState)({});
|
|
49
|
-
(0, react_1.useEffect)(() => {
|
|
50
|
-
if (disabled) {
|
|
51
|
-
setTargets({});
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
const { current } = ref;
|
|
55
|
-
if (!current)
|
|
56
|
-
return;
|
|
57
|
-
// select all non-highlighter elements
|
|
58
|
-
const allElements = Array.from(current.querySelectorAll(allExceptHighlighterQuery));
|
|
59
|
-
// converge on the root element of components
|
|
60
|
-
const rootElements = allElements.map(react_modules_dom_to_react_1.toRootElement).filter((x) => !!x);
|
|
61
|
-
// deduplicate
|
|
62
|
-
const uniqueRoots = new Set(rootElements);
|
|
63
|
-
const nextTargets = {};
|
|
64
|
-
uniqueRoots.forEach((element) => {
|
|
65
|
-
const comp = (0, react_modules_dom_to_react_1.domToReact)(element);
|
|
66
|
-
if (!element || !(0, react_ui_highlighter_component_metadata_bit_component_meta_1.hasComponentMeta)(comp))
|
|
67
|
-
return;
|
|
68
|
-
const key = (0, get_xpath_1.default)(element);
|
|
69
|
-
// eslint-disable-next-line no-underscore-dangle
|
|
70
|
-
nextTargets[key] = { element, id: comp.__bit_component.id };
|
|
71
|
-
});
|
|
72
|
-
setTargets(nextTargets);
|
|
73
|
-
}, [disabled]);
|
|
74
|
-
const colors = {
|
|
75
|
-
'--bit-highlighter-color': bgColor,
|
|
76
|
-
'--bit-highlighter-color-hover': bgColorHover,
|
|
77
|
-
'--bit-highlighter-color-active': bgColorActive,
|
|
78
|
-
};
|
|
79
|
-
return (react_1.default.createElement("div", Object.assign({ ref: ref }, rest, { style: Object.assign(Object.assign({}, colors), style) }),
|
|
80
|
-
children,
|
|
81
|
-
Object.entries(targets).map(([key, target]) => (react_1.default.createElement(react_ui_component_highlighter_1.ElementHighlighter, Object.assign({ key: key, target: target, watchMotion: watchMotion }, highlighterOptions))))));
|
|
21
|
+
var { watchMotion = false } = _a, props = __rest(_a, ["watchMotion"]);
|
|
22
|
+
return react_1.default.createElement(hybrid_highligher_1.HybridHighlighter, Object.assign({}, props, { mode: 'allChildren', watchMotion: watchMotion }));
|
|
82
23
|
}
|
|
83
24
|
exports.MultiHighlighter = MultiHighlighter;
|
|
84
25
|
//# sourceMappingURL=multi-highlighter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"multi-highlighter.js","sourceRoot":"","sources":["../../multi-highlighter/multi-highlighter.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"multi-highlighter.js","sourceRoot":"","sources":["../../multi-highlighter/multi-highlighter.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,kDAA0B;AAE1B,4DAAiF;AAIjF,SAAgB,gBAAgB,CAAC,EAAwD;QAAxD,EAAE,WAAW,GAAG,KAAK,OAAmC,EAA9B,KAAK,cAA/B,eAAiC,CAAF;IAC9D,OAAO,8BAAC,qCAAiB,oBAAK,KAAK,IAAE,IAAI,EAAE,aAAa,EAAE,WAAW,EAAE,WAAW,IAAI,CAAC;AACzF,CAAC;AAFD,4CAEC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { RefObject } from 'react';
|
|
2
|
+
import { HighlightTarget } from '../element-highlighter';
|
|
3
|
+
import { MatchRule } from '../rule-matcher';
|
|
4
|
+
declare type useMultiHighlighterProps = {
|
|
5
|
+
onChange: (highlighterTargets: Record<string, HighlightTarget>) => void;
|
|
6
|
+
disabled?: boolean;
|
|
7
|
+
scopeRef: RefObject<HTMLElement>;
|
|
8
|
+
scopeClass?: string;
|
|
9
|
+
/** filter highlighter targets by this query selector. (May be a more complex object in the future) */
|
|
10
|
+
rule?: MatchRule;
|
|
11
|
+
};
|
|
12
|
+
export declare function useMultiHighlighter({ onChange, disabled, scopeRef, scopeClass: scopeSelector, rule, }: useMultiHighlighterProps): void;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.useMultiHighlighter = void 0;
|
|
7
|
+
const react_1 = require("react");
|
|
8
|
+
const get_xpath_1 = __importDefault(require("get-xpath"));
|
|
9
|
+
const react_modules_dom_to_react_1 = require("@teambit/react.modules.dom-to-react");
|
|
10
|
+
const react_ui_highlighter_component_metadata_bit_component_meta_1 = require("@teambit/react.ui.highlighter.component-metadata.bit-component-meta");
|
|
11
|
+
const ignore_highlighter_1 = require("../ignore-highlighter");
|
|
12
|
+
const rule_matcher_1 = require("../rule-matcher");
|
|
13
|
+
function useMultiHighlighter({ onChange, disabled, scopeRef, scopeClass: scopeSelector = '', rule, }) {
|
|
14
|
+
(0, react_1.useEffect)(() => {
|
|
15
|
+
const nextTargets = {};
|
|
16
|
+
const scopeElement = scopeRef.current;
|
|
17
|
+
if (!scopeElement || disabled)
|
|
18
|
+
return;
|
|
19
|
+
// select all elements (except excluded)
|
|
20
|
+
let allElements = Array.from(scopeElement.querySelectorAll(targetsSelector(`.${scopeSelector}`)));
|
|
21
|
+
// apply rule filtering
|
|
22
|
+
if (rule)
|
|
23
|
+
allElements = allElements.filter((elem) => (0, rule_matcher_1.ruleMatcher)(elem, rule));
|
|
24
|
+
// seek the root element:
|
|
25
|
+
const rootElements = allElements.map(react_modules_dom_to_react_1.toRootElement).filter((x) => !!x);
|
|
26
|
+
// deduplicate
|
|
27
|
+
const uniqueRoots = new Set(rootElements);
|
|
28
|
+
uniqueRoots.forEach((element) => {
|
|
29
|
+
const comp = (0, react_modules_dom_to_react_1.domToReact)(element);
|
|
30
|
+
if (!element || !(0, react_ui_highlighter_component_metadata_bit_component_meta_1.hasComponentMeta)(comp))
|
|
31
|
+
return;
|
|
32
|
+
const key = (0, get_xpath_1.default)(element);
|
|
33
|
+
const meta = comp[react_ui_highlighter_component_metadata_bit_component_meta_1.componentMetaField];
|
|
34
|
+
const compId = meta[react_ui_highlighter_component_metadata_bit_component_meta_1.componentMetaProperties.componentId];
|
|
35
|
+
const link = meta[react_ui_highlighter_component_metadata_bit_component_meta_1.componentMetaProperties.homepageUrl];
|
|
36
|
+
const local = meta[react_ui_highlighter_component_metadata_bit_component_meta_1.componentMetaProperties.isExported] === false;
|
|
37
|
+
nextTargets[key] = { element, id: compId, link, local };
|
|
38
|
+
});
|
|
39
|
+
onChange(nextTargets);
|
|
40
|
+
}, [disabled, scopeSelector]);
|
|
41
|
+
}
|
|
42
|
+
exports.useMultiHighlighter = useMultiHighlighter;
|
|
43
|
+
function targetsSelector(
|
|
44
|
+
/**
|
|
45
|
+
* the scope in which to consider the exclude selector.
|
|
46
|
+
* The `:scope` modifier is appropriate, but is not supported in older browsers.
|
|
47
|
+
*/
|
|
48
|
+
scopeSelector = ':scope') {
|
|
49
|
+
return `:not(${scopeSelector} ${ignore_highlighter_1.excludeHighlighterSelector}, ${scopeSelector} ${ignore_highlighter_1.excludeHighlighterSelector} *)`;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=use-multi-highlighter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-multi-highlighter.js","sourceRoot":"","sources":["../../multi-highlighter/use-multi-highlighter.tsx"],"names":[],"mappings":";;;;;;AAAA,iCAA6C;AAC7C,0DAAiC;AACjC,oFAAgF;AAChF,oJAI6E;AAE7E,8DAAmE;AACnE,kDAAyD;AAczD,SAAgB,mBAAmB,CAAC,EAClC,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,UAAU,EAAE,aAAa,GAAG,EAAE,EAC9B,IAAI,GACqB;IACzB,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,MAAM,WAAW,GAAoC,EAAE,CAAC;QACxD,MAAM,YAAY,GAAG,QAAQ,CAAC,OAAO,CAAC;QACtC,IAAI,CAAC,YAAY,IAAI,QAAQ;YAAE,OAAO;QAEtC,wCAAwC;QACxC,IAAI,WAAW,GAAG,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,gBAAgB,CAAc,eAAe,CAAC,IAAI,aAAa,EAAE,CAAC,CAAC,CAAC,CAAC;QAC/G,uBAAuB;QACvB,IAAI,IAAI;YAAE,WAAW,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAA,0BAAW,EAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;QAC9E,yBAAyB;QACzB,MAAM,YAAY,GAAG,WAAW,CAAC,GAAG,CAAC,0CAAa,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACvE,cAAc;QACd,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC,YAAY,CAAC,CAAC;QAE1C,WAAW,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;YAC9B,MAAM,IAAI,GAAG,IAAA,uCAAU,EAAC,OAAO,CAAC,CAAC;YACjC,IAAI,CAAC,OAAO,IAAI,CAAC,IAAA,6EAAgB,EAAC,IAAI,CAAC;gBAAE,OAAO;YAEhD,MAAM,GAAG,GAAG,IAAA,mBAAQ,EAAC,OAAO,CAAC,CAAC;YAC9B,MAAM,IAAI,GAAG,IAAI,CAAC,+EAAkB,CAAC,CAAC;YACtC,MAAM,MAAM,GAAG,IAAI,CAAC,oFAAuB,CAAC,WAAW,CAAC,CAAC;YACzD,MAAM,IAAI,GAAG,IAAI,CAAC,oFAAuB,CAAC,WAAW,CAAC,CAAC;YACvD,MAAM,KAAK,GAAG,IAAI,CAAC,oFAAuB,CAAC,UAAU,CAAC,KAAK,KAAK,CAAC;YACjE,WAAW,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;QAC1D,CAAC,CAAC,CAAC;QAEH,QAAQ,CAAC,WAAW,CAAC,CAAC;IACxB,CAAC,EAAE,CAAC,QAAQ,EAAE,aAAa,CAAC,CAAC,CAAC;AAChC,CAAC;AAnCD,kDAmCC;AAED,SAAS,eAAe;AACtB;;;GAGG;AACH,aAAa,GAAG,QAAQ;IAExB,OAAO,QAAQ,aAAa,IAAI,+CAA0B,KAAK,aAAa,IAAI,+CAA0B,KAAK,CAAC;AAClH,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// in the future, we will add more options here, like include / exclude objects.
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.ruleMatcher = void 0;
|
|
5
|
+
function ruleMatcher(element, rule) {
|
|
6
|
+
if (typeof rule === 'string') {
|
|
7
|
+
return element.matches(rule);
|
|
8
|
+
}
|
|
9
|
+
if (typeof rule === 'function') {
|
|
10
|
+
return rule(element);
|
|
11
|
+
}
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
exports.ruleMatcher = ruleMatcher;
|
|
15
|
+
//# sourceMappingURL=rule-matcher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rule-matcher.js","sourceRoot":"","sources":["../rule-matcher.tsx"],"names":[],"mappings":";AAAA,gFAAgF;;;AAIhF,SAAgB,WAAW,CAAC,OAAoB,EAAE,IAAe;IAC/D,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;QAC5B,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;KAC9B;IAED,IAAI,OAAO,IAAI,KAAK,UAAU,EAAE;QAC9B,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC;KACtB;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAVD,kCAUC"}
|
|
@@ -6,14 +6,16 @@ export const ShowWhenHovering = () => {
|
|
|
6
6
|
const [disabled, setDisabled] = useState<boolean>(false);
|
|
7
7
|
|
|
8
8
|
return (
|
|
9
|
-
<div style={{ padding: '16px
|
|
9
|
+
<div style={{ padding: '16px 50px 32px 16px', minWidth: 300 }}>
|
|
10
10
|
<HoverHighlighter style={{ padding: 16 }} disabled={disabled}>
|
|
11
11
|
<div>
|
|
12
|
-
some div
|
|
13
12
|
<br />
|
|
14
13
|
<div>
|
|
15
14
|
<IconButton onClick={() => setDisabled((x) => !x)}>Hover here</IconButton>
|
|
16
15
|
</div>
|
|
16
|
+
<div>
|
|
17
|
+
{disabled ? 'X' : '✓'} highlighter is {disabled ? 'disabled' : 'enabled'}
|
|
18
|
+
</div>
|
|
17
19
|
</div>
|
|
18
20
|
</HoverHighlighter>
|
|
19
21
|
</div>
|
package/{component-highlighter/hover-highlighter → hover-highlighter}/hover-highlighter.spec.tsx
RENAMED
|
File without changes
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { HybridHighlighter, HybridHighlighterProps } from '../hybrid-highligher';
|
|
3
|
+
|
|
4
|
+
export type HoverHighlighterProps = Omit<HybridHighlighterProps, 'mode'>;
|
|
5
|
+
|
|
6
|
+
export function HoverHighlighter({ ...props }: HoverHighlighterProps) {
|
|
7
|
+
return <HybridHighlighter {...props} mode={'hover'} />;
|
|
8
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import React, { useEffect } from 'react';
|
|
2
|
+
import { useDebouncedCallback } from 'use-debounce';
|
|
3
|
+
import { domToReact, toRootElement } from '@teambit/react.modules.dom-to-react';
|
|
4
|
+
import { useHoverSelection } from '@teambit/react.ui.hover-selector';
|
|
5
|
+
import { hasComponentMeta } from '@teambit/react.ui.highlighter.component-metadata.bit-component-meta';
|
|
6
|
+
|
|
7
|
+
import { excludeHighlighterSelector } from '../ignore-highlighter';
|
|
8
|
+
import { HighlightTarget } from '../element-highlighter';
|
|
9
|
+
import { ruleMatcher, MatchRule } from '../rule-matcher';
|
|
10
|
+
|
|
11
|
+
export type useHoverHighlighterOptions = {
|
|
12
|
+
debounceDuration: number;
|
|
13
|
+
scopeClass: string;
|
|
14
|
+
disabled?: boolean;
|
|
15
|
+
rule?: MatchRule;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/** fires onChange when targeting a new component */
|
|
19
|
+
export function useHoverHighlighter<T extends HTMLElement = HTMLElement>(
|
|
20
|
+
onChange: (target?: HighlightTarget) => void,
|
|
21
|
+
props: React.HTMLAttributes<T> = {},
|
|
22
|
+
{ debounceDuration, scopeClass, disabled, rule }: useHoverHighlighterOptions
|
|
23
|
+
) {
|
|
24
|
+
const { handleElement } = useHoverHandler({ onChange, scopeClass, debounceDuration, disabled, rule });
|
|
25
|
+
|
|
26
|
+
const handlers = useHoverSelection(disabled ? undefined : handleElement, props);
|
|
27
|
+
|
|
28
|
+
return handlers;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
type useHoverHighlighterProps = {
|
|
32
|
+
onChange: (target?: HighlightTarget) => void;
|
|
33
|
+
scopeClass?: string;
|
|
34
|
+
debounceDuration?: number;
|
|
35
|
+
disabled?: boolean;
|
|
36
|
+
rule?: MatchRule;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
function useHoverHandler({ onChange, scopeClass = '', debounceDuration, disabled, rule }: useHoverHighlighterProps) {
|
|
40
|
+
// debounced method is ref'ed, so no need for useCallback
|
|
41
|
+
const _handleElement = (element: HTMLElement | null) => {
|
|
42
|
+
// clear highlighter at the edges:
|
|
43
|
+
if (!element || element.hasAttribute('data-nullify-component-highlight')) {
|
|
44
|
+
onChange(undefined);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// skip DOM trees having 'data-ignore-component-highlight'
|
|
49
|
+
if (element.closest(`.${scopeClass} ${excludeHighlighterSelector}`)) return;
|
|
50
|
+
|
|
51
|
+
const result = bubbleToBitComponent(element, rule ? (current) => ruleMatcher(current, rule) : undefined);
|
|
52
|
+
if (!result) return;
|
|
53
|
+
|
|
54
|
+
onChange({
|
|
55
|
+
element: result.element,
|
|
56
|
+
id: result.meta.id,
|
|
57
|
+
scopeLink: undefined,
|
|
58
|
+
link: result.meta.homepage,
|
|
59
|
+
local: result.meta.exported === false,
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const handleElement = useDebouncedCallback(_handleElement, debounceDuration);
|
|
64
|
+
|
|
65
|
+
// clear when disabling
|
|
66
|
+
useEffect(() => {
|
|
67
|
+
if (disabled) handleElement.cancel();
|
|
68
|
+
}, [disabled, handleElement]);
|
|
69
|
+
|
|
70
|
+
return { handleElement };
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** go up the dom tree until reaching a react bit component */
|
|
74
|
+
function bubbleToBitComponent(element: HTMLElement | null, filter?: (elem: HTMLElement) => boolean) {
|
|
75
|
+
for (let current = element; current; current = current.parentElement) {
|
|
76
|
+
current = toRootElement(current);
|
|
77
|
+
if (!current || filter?.(current) === false) return undefined;
|
|
78
|
+
|
|
79
|
+
const component = domToReact(current);
|
|
80
|
+
|
|
81
|
+
if (hasComponentMeta(component)) {
|
|
82
|
+
const meta = component.__bit_component;
|
|
83
|
+
|
|
84
|
+
return {
|
|
85
|
+
element: current,
|
|
86
|
+
component,
|
|
87
|
+
meta,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return undefined;
|
|
93
|
+
}
|