@teambit/react.ui.component-highlighter 0.0.491 → 0.0.492
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 +1 -10
- package/dist/component-highlighter.docs.md +1 -10
- package/dist/hover-highlighter/use-hover-highlighter.d.ts +2 -5
- package/dist/hover-highlighter/use-hover-highlighter.js +14 -17
- package/dist/hover-highlighter/use-hover-highlighter.js.map +1 -1
- package/dist/hybrid-highligher/hybrid-highlighter.d.ts +2 -3
- package/dist/hybrid-highligher/hybrid-highlighter.js +1 -3
- package/dist/hybrid-highligher/hybrid-highlighter.js.map +1 -1
- package/dist/multi-highlighter/multi-highlighter.composition.d.ts +0 -1
- package/dist/multi-highlighter/multi-highlighter.composition.js +3 -16
- package/dist/multi-highlighter/multi-highlighter.composition.js.map +1 -1
- package/dist/multi-highlighter/use-multi-highlighter.d.ts +2 -4
- package/dist/multi-highlighter/use-multi-highlighter.js +2 -4
- package/dist/multi-highlighter/use-multi-highlighter.js.map +1 -1
- package/dist/rule-matcher.d.ts +0 -6
- package/dist/rule-matcher.js +2 -19
- package/dist/rule-matcher.js.map +1 -1
- package/hover-highlighter/use-hover-highlighter.tsx +19 -36
- package/hybrid-highligher/hybrid-highlighter.tsx +2 -6
- package/multi-highlighter/multi-highlighter.composition.tsx +3 -19
- package/multi-highlighter/use-multi-highlighter.tsx +3 -7
- package/package-tar/teambit-react.ui.component-highlighter-0.0.492.tgz +0 -0
- package/package.json +6 -6
- package/rule-matcher.tsx +1 -27
- package/package-tar/teambit-react.ui.component-highlighter-0.0.491.tgz +0 -0
|
@@ -153,15 +153,6 @@ For example:
|
|
|
153
153
|
</ComponentHighlighter>
|
|
154
154
|
```
|
|
155
155
|
|
|
156
|
-
You can also filter by component id, using the `componentRule` prop:
|
|
157
|
-
|
|
158
|
-
```tsx
|
|
159
|
-
<ComponentHighlighter componentRule="teambit.design/ui/icon-button">
|
|
160
|
-
<Paragraph>will not be highlighted</Paragraph>
|
|
161
|
-
<Button>this will be highlighted</Button>
|
|
162
|
-
</ComponentHighlighter>
|
|
163
|
-
```
|
|
164
|
-
|
|
165
156
|
## Customization
|
|
166
157
|
|
|
167
158
|
Use these CSS variables to edit the highlighter color
|
|
@@ -198,4 +189,4 @@ const classes = {
|
|
|
198
189
|
```
|
|
199
190
|
|
|
200
191
|
You can control the size using regular `font-size`.
|
|
201
|
-
Keep in mind that the label can be either two elements (when using component id), and a single element (for other texts)
|
|
192
|
+
Keep in mind that the label can be either two elements (when using component id), and a single element (for other texts)
|
|
@@ -153,15 +153,6 @@ For example:
|
|
|
153
153
|
</ComponentHighlighter>
|
|
154
154
|
```
|
|
155
155
|
|
|
156
|
-
You can also filter by component id, using the `componentRule` prop:
|
|
157
|
-
|
|
158
|
-
```tsx
|
|
159
|
-
<ComponentHighlighter componentRule="teambit.design/ui/icon-button">
|
|
160
|
-
<Paragraph>will not be highlighted</Paragraph>
|
|
161
|
-
<Button>this will be highlighted</Button>
|
|
162
|
-
</ComponentHighlighter>
|
|
163
|
-
```
|
|
164
|
-
|
|
165
156
|
## Customization
|
|
166
157
|
|
|
167
158
|
Use these CSS variables to edit the highlighter color
|
|
@@ -198,4 +189,4 @@ const classes = {
|
|
|
198
189
|
```
|
|
199
190
|
|
|
200
191
|
You can control the size using regular `font-size`.
|
|
201
|
-
Keep in mind that the label can be either two elements (when using component id), and a single element (for other texts)
|
|
192
|
+
Keep in mind that the label can be either two elements (when using component id), and a single element (for other texts)
|
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { HighlightTarget } from '../element-highlighter';
|
|
3
|
-
import { MatchRule
|
|
3
|
+
import { MatchRule } from '../rule-matcher';
|
|
4
4
|
export declare type useHoverHighlighterOptions = {
|
|
5
5
|
debounceDuration: number;
|
|
6
6
|
scopeClass: string;
|
|
7
7
|
disabled?: boolean;
|
|
8
|
-
/** filter highlighter targets by this query selector. (May be a more complex object in the future) */
|
|
9
8
|
rule?: MatchRule;
|
|
10
|
-
/** filter targets by this component match rule */
|
|
11
|
-
componentRule?: ComponentMatchRule;
|
|
12
9
|
};
|
|
13
10
|
/** fires onChange when targeting a new component */
|
|
14
|
-
export declare function useHoverHighlighter<T extends HTMLElement = HTMLElement>(onChange: (target?: HighlightTarget) => void, props: React.HTMLAttributes<T>, { debounceDuration, scopeClass, disabled, rule
|
|
11
|
+
export declare function useHoverHighlighter<T extends HTMLElement = HTMLElement>(onChange: (target?: HighlightTarget) => void, props: React.HTMLAttributes<T>, { debounceDuration, scopeClass, disabled, rule }: useHoverHighlighterOptions): {
|
|
15
12
|
onMouseOver: (event: React.MouseEvent<T, MouseEvent>) => void;
|
|
16
13
|
onMouseLeave: (event: React.MouseEvent<T, MouseEvent>) => void;
|
|
17
14
|
} | {
|
|
@@ -9,13 +9,13 @@ const react_ui_highlighter_component_metadata_bit_component_meta_1 = require("@t
|
|
|
9
9
|
const ignore_highlighter_1 = require("../ignore-highlighter");
|
|
10
10
|
const rule_matcher_1 = require("../rule-matcher");
|
|
11
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
|
|
12
|
+
function useHoverHighlighter(onChange, props = {}, { debounceDuration, scopeClass, disabled, rule }) {
|
|
13
|
+
const { handleElement } = useHoverHandler({ onChange, scopeClass, debounceDuration, disabled, rule });
|
|
14
14
|
const handlers = (0, react_ui_hover_selector_1.useHoverSelection)(disabled ? undefined : handleElement, props);
|
|
15
15
|
return handlers;
|
|
16
16
|
}
|
|
17
17
|
exports.useHoverHighlighter = useHoverHighlighter;
|
|
18
|
-
function useHoverHandler({ onChange, scopeClass = '', debounceDuration, disabled, rule
|
|
18
|
+
function useHoverHandler({ onChange, scopeClass = '', debounceDuration, disabled, rule }) {
|
|
19
19
|
// debounced method is ref'ed, so no need for useCallback
|
|
20
20
|
const _handleElement = (element) => {
|
|
21
21
|
// clear highlighter at the edges:
|
|
@@ -26,7 +26,7 @@ function useHoverHandler({ onChange, scopeClass = '', debounceDuration, disabled
|
|
|
26
26
|
// skip DOM trees having 'data-ignore-component-highlight'
|
|
27
27
|
if (element.closest(`.${scopeClass} ${ignore_highlighter_1.excludeHighlighterSelector}`))
|
|
28
28
|
return;
|
|
29
|
-
const result = bubbleToBitComponent(element, rule,
|
|
29
|
+
const result = bubbleToBitComponent(element, rule ? (current) => (0, rule_matcher_1.ruleMatcher)(current, rule) : undefined);
|
|
30
30
|
if (!result)
|
|
31
31
|
return;
|
|
32
32
|
onChange({
|
|
@@ -46,22 +46,19 @@ function useHoverHandler({ onChange, scopeClass = '', debounceDuration, disabled
|
|
|
46
46
|
return { handleElement };
|
|
47
47
|
}
|
|
48
48
|
/** go up the dom tree until reaching a react bit component */
|
|
49
|
-
function bubbleToBitComponent(element,
|
|
49
|
+
function bubbleToBitComponent(element, filter) {
|
|
50
50
|
for (let current = element; current; current = current.parentElement) {
|
|
51
51
|
current = (0, react_modules_dom_to_react_1.toRootElement)(current);
|
|
52
|
-
if (!current)
|
|
52
|
+
if (!current || (filter === null || filter === void 0 ? void 0 : filter(current)) === false)
|
|
53
53
|
return undefined;
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
meta,
|
|
63
|
-
};
|
|
64
|
-
}
|
|
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
|
+
};
|
|
65
62
|
}
|
|
66
63
|
}
|
|
67
64
|
return undefined;
|
|
@@ -1 +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;AACrE,oJAAuG;AAEvG,8DAAmE;AAEnE,
|
|
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;AACrE,oJAAuG;AAEvG,8DAAmE;AAEnE,kDAAyD;AASzD,oDAAoD;AACpD,SAAgB,mBAAmB,CACjC,QAA4C,EAC5C,QAAiC,EAAE,EACnC,EAAE,gBAAgB,EAAE,UAAU,EAAE,QAAQ,EAAE,IAAI,EAA8B;IAE5E,MAAM,EAAE,aAAa,EAAE,GAAG,eAAe,CAAC,EAAE,QAAQ,EAAE,UAAU,EAAE,gBAAgB,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;IAEtG,MAAM,QAAQ,GAAG,IAAA,2CAAiB,EAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,aAAa,EAAE,KAAK,CAAC,CAAC;IAEhF,OAAO,QAAQ,CAAC;AAClB,CAAC;AAVD,kDAUC;AAUD,SAAS,eAAe,CAAC,EAAE,QAAQ,EAAE,UAAU,GAAG,EAAE,EAAE,gBAAgB,EAAE,QAAQ,EAAE,IAAI,EAA4B;IAChH,yDAAyD;IACzD,MAAM,cAAc,GAAG,CAAC,OAA2B,EAAE,EAAE;QACrD,kCAAkC;QAClC,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,YAAY,CAAC,kCAAkC,CAAC,EAAE;YACxE,QAAQ,CAAC,SAAS,CAAC,CAAC;YACpB,OAAO;SACR;QAED,0DAA0D;QAC1D,IAAI,OAAO,CAAC,OAAO,CAAC,IAAI,UAAU,IAAI,+CAA0B,EAAE,CAA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AAS,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"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { CSSProperties } from 'react';
|
|
2
2
|
import { Placement, HighlightClasses } from '../element-highlighter';
|
|
3
|
-
import type { MatchRule
|
|
3
|
+
import type { MatchRule } from '../rule-matcher';
|
|
4
4
|
export interface HybridHighlighterProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
5
5
|
/** stop all highlighting and drop listeners */
|
|
6
6
|
disabled?: boolean;
|
|
@@ -20,7 +20,6 @@ export interface HybridHighlighterProps extends React.HTMLAttributes<HTMLDivElem
|
|
|
20
20
|
watchMotion?: boolean;
|
|
21
21
|
/** filter highlighter targets by this query selector. (May be a more complex object in the future) */
|
|
22
22
|
rule?: MatchRule;
|
|
23
|
-
componentRule?: ComponentMatchRule;
|
|
24
23
|
/** set the behavior of the highlighter.
|
|
25
24
|
* `disabled` - stops highlighting.
|
|
26
25
|
* `allChildren` - highlights all components rendered under children
|
|
@@ -32,4 +31,4 @@ export interface HybridHighlighterProps extends React.HTMLAttributes<HTMLDivElem
|
|
|
32
31
|
bgColorActive?: string;
|
|
33
32
|
}
|
|
34
33
|
/** automatically highlight components on hover */
|
|
35
|
-
export declare function HybridHighlighter({ disabled, mode, debounceSelection, watchMotion, placement, rule,
|
|
34
|
+
export declare function HybridHighlighter({ disabled, mode, debounceSelection, watchMotion, placement, rule, classes, highlightStyle, className, style, bgColor, bgColorHover, bgColorActive, children, ...rest }: HybridHighlighterProps): JSX.Element;
|
|
@@ -42,7 +42,7 @@ const element_highlighter_1 = require("../element-highlighter");
|
|
|
42
42
|
const use_multi_highlighter_1 = require("../multi-highlighter/use-multi-highlighter");
|
|
43
43
|
/** automatically highlight components on hover */
|
|
44
44
|
function HybridHighlighter(_a) {
|
|
45
|
-
var { disabled, mode = 'hover', debounceSelection = 80, watchMotion = true, placement, rule,
|
|
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
46
|
const ref = (0, react_1.createRef)();
|
|
47
47
|
const [targets, setTarget] = (0, react_1.useState)({});
|
|
48
48
|
const scopeClass = (0, react_1.useRef)(`hl-scope-${(0, uuid_1.v4)()}`).current;
|
|
@@ -57,7 +57,6 @@ function HybridHighlighter(_a) {
|
|
|
57
57
|
scopeClass,
|
|
58
58
|
disabled: disabled || mode !== 'hover',
|
|
59
59
|
rule,
|
|
60
|
-
componentRule
|
|
61
60
|
});
|
|
62
61
|
(0, use_multi_highlighter_1.useMultiHighlighter)({
|
|
63
62
|
onChange: setTarget,
|
|
@@ -65,7 +64,6 @@ function HybridHighlighter(_a) {
|
|
|
65
64
|
scopeClass,
|
|
66
65
|
disabled: disabled || mode !== 'allChildren',
|
|
67
66
|
rule,
|
|
68
|
-
componentRule
|
|
69
67
|
});
|
|
70
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]);
|
|
71
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 }),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hybrid-highlighter.js","sourceRoot":"","sources":["../../hybrid-highligher/hybrid-highlighter.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+C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Element;
|
|
3
3
|
export declare const MultiHighlighterInsideIgnore: () => JSX.Element;
|
|
4
4
|
export declare const MultiHighlighterWithRule: () => JSX.Element;
|
|
5
|
-
export declare const MultiHighlighterWithComponentRule: () => JSX.Element;
|
|
@@ -3,11 +3,10 @@ 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.
|
|
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 design_ui_icon_button_1 = require("@teambit/design.ui.icon-button");
|
|
11
10
|
const ignore_highlighter_1 = require("../ignore-highlighter");
|
|
12
11
|
const multi_highlighter_1 = require("./multi-highlighter");
|
|
13
12
|
const MultiHighlighterPreview = () => {
|
|
@@ -46,7 +45,7 @@ const MultiHighlighterInsideIgnore = () => {
|
|
|
46
45
|
};
|
|
47
46
|
exports.MultiHighlighterInsideIgnore = MultiHighlighterInsideIgnore;
|
|
48
47
|
const MultiHighlighterWithRule = () => {
|
|
49
|
-
return (react_1.default.createElement(multi_highlighter_1.MultiHighlighter, { rule: "#someSubTree *"
|
|
48
|
+
return (react_1.default.createElement(multi_highlighter_1.MultiHighlighter, { rule: "#someSubTree *" },
|
|
50
49
|
react_1.default.createElement("br", null),
|
|
51
50
|
react_1.default.createElement("br", null),
|
|
52
51
|
react_1.default.createElement("br", null),
|
|
@@ -55,21 +54,9 @@ const MultiHighlighterWithRule = () => {
|
|
|
55
54
|
react_1.default.createElement("br", null),
|
|
56
55
|
react_1.default.createElement("br", null),
|
|
57
56
|
react_1.default.createElement("div", { id: "someSubTree" },
|
|
58
|
-
react_1.default.createElement(react_ui_highlighter_component_metadata_bit_component_meta_1.MockedComponentWithMeta, null, "
|
|
57
|
+
react_1.default.createElement(react_ui_highlighter_component_metadata_bit_component_meta_1.MockedComponentWithMeta, null, "this will be highlighted"))));
|
|
59
58
|
};
|
|
60
59
|
exports.MultiHighlighterWithRule = MultiHighlighterWithRule;
|
|
61
|
-
const MultiHighlighterWithComponentRule = () => {
|
|
62
|
-
return (react_1.default.createElement(multi_highlighter_1.MultiHighlighter, { componentRule: "teambit.design/ui/icon-button" },
|
|
63
|
-
react_1.default.createElement("br", null),
|
|
64
|
-
react_1.default.createElement("br", null),
|
|
65
|
-
react_1.default.createElement("br", null),
|
|
66
|
-
react_1.default.createElement(react_ui_highlighter_component_metadata_bit_component_meta_1.MockedComponentWithMeta, null, "no highlighter"),
|
|
67
|
-
react_1.default.createElement("br", null),
|
|
68
|
-
react_1.default.createElement("br", null),
|
|
69
|
-
react_1.default.createElement("br", null),
|
|
70
|
-
react_1.default.createElement(design_ui_icon_button_1.IconButton, null, "highlighted because of component rule")));
|
|
71
|
-
};
|
|
72
|
-
exports.MultiHighlighterWithComponentRule = MultiHighlighterWithComponentRule;
|
|
73
60
|
// export const HighlightingAllElementsInTheEnterprisePage = () => {
|
|
74
61
|
// return (
|
|
75
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,
|
|
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;AAC3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BAAyC;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,6 +1,6 @@
|
|
|
1
1
|
import { RefObject } from 'react';
|
|
2
2
|
import { HighlightTarget } from '../element-highlighter';
|
|
3
|
-
import { MatchRule
|
|
3
|
+
import { MatchRule } from '../rule-matcher';
|
|
4
4
|
declare type useMultiHighlighterProps = {
|
|
5
5
|
onChange: (highlighterTargets: Record<string, HighlightTarget>) => void;
|
|
6
6
|
disabled?: boolean;
|
|
@@ -8,8 +8,6 @@ declare type useMultiHighlighterProps = {
|
|
|
8
8
|
scopeClass?: string;
|
|
9
9
|
/** filter highlighter targets by this query selector. (May be a more complex object in the future) */
|
|
10
10
|
rule?: MatchRule;
|
|
11
|
-
/** filter targets by this component match rule */
|
|
12
|
-
componentRule?: ComponentMatchRule;
|
|
13
11
|
};
|
|
14
|
-
export declare function useMultiHighlighter({ onChange, disabled, scopeRef, scopeClass: scopeSelector, rule,
|
|
12
|
+
export declare function useMultiHighlighter({ onChange, disabled, scopeRef, scopeClass: scopeSelector, rule, }: useMultiHighlighterProps): void;
|
|
15
13
|
export {};
|
|
@@ -10,7 +10,7 @@ const react_modules_dom_to_react_1 = require("@teambit/react.modules.dom-to-reac
|
|
|
10
10
|
const react_ui_highlighter_component_metadata_bit_component_meta_1 = require("@teambit/react.ui.highlighter.component-metadata.bit-component-meta");
|
|
11
11
|
const ignore_highlighter_1 = require("../ignore-highlighter");
|
|
12
12
|
const rule_matcher_1 = require("../rule-matcher");
|
|
13
|
-
function useMultiHighlighter({ onChange, disabled, scopeRef, scopeClass: scopeSelector = '', rule,
|
|
13
|
+
function useMultiHighlighter({ onChange, disabled, scopeRef, scopeClass: scopeSelector = '', rule, }) {
|
|
14
14
|
(0, react_1.useEffect)(() => {
|
|
15
15
|
const nextTargets = {};
|
|
16
16
|
const scopeElement = scopeRef.current;
|
|
@@ -29,10 +29,8 @@ function useMultiHighlighter({ onChange, disabled, scopeRef, scopeClass: scopeSe
|
|
|
29
29
|
const comp = (0, react_modules_dom_to_react_1.domToReact)(element);
|
|
30
30
|
if (!element || !(0, react_ui_highlighter_component_metadata_bit_component_meta_1.hasComponentMeta)(comp))
|
|
31
31
|
return;
|
|
32
|
-
const meta = comp[react_ui_highlighter_component_metadata_bit_component_meta_1.componentMetaField];
|
|
33
|
-
if (!(0, rule_matcher_1.componentRuleMatcher)({ meta }, componentRule))
|
|
34
|
-
return;
|
|
35
32
|
const key = (0, get_xpath_1.default)(element);
|
|
33
|
+
const meta = comp[react_ui_highlighter_component_metadata_bit_component_meta_1.componentMetaField];
|
|
36
34
|
const compId = meta[react_ui_highlighter_component_metadata_bit_component_meta_1.componentMetaProperties.componentId];
|
|
37
35
|
const link = meta[react_ui_highlighter_component_metadata_bit_component_meta_1.componentMetaProperties.homepageUrl];
|
|
38
36
|
const local = meta[react_ui_highlighter_component_metadata_bit_component_meta_1.componentMetaProperties.isExported] === false;
|
|
@@ -1 +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,
|
|
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,EAC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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"}
|
package/dist/rule-matcher.d.ts
CHANGED
|
@@ -1,8 +1,2 @@
|
|
|
1
|
-
import { ComponentMeta } from '@teambit/react.ui.highlighter.component-metadata.bit-component-meta';
|
|
2
|
-
export declare type ComponentMatchTarget = {
|
|
3
|
-
meta: ComponentMeta;
|
|
4
|
-
};
|
|
5
1
|
export declare type MatchRule = undefined | string | ((element: HTMLElement) => boolean);
|
|
6
|
-
export declare type ComponentMatchRule = undefined | string | string[] | ((target: ComponentMatchTarget) => boolean);
|
|
7
2
|
export declare function ruleMatcher(element: HTMLElement, rule: MatchRule): boolean;
|
|
8
|
-
export declare function componentRuleMatcher(target: ComponentMatchTarget, rule: ComponentMatchRule): boolean;
|
package/dist/rule-matcher.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
// in the future, we will add more options here, like include / exclude objects.
|
|
2
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const component_id_1 = require("@teambit/component-id");
|
|
4
|
+
exports.ruleMatcher = void 0;
|
|
5
5
|
function ruleMatcher(element, rule) {
|
|
6
6
|
if (typeof rule === 'string') {
|
|
7
7
|
return element.matches(rule);
|
|
@@ -12,21 +12,4 @@ function ruleMatcher(element, rule) {
|
|
|
12
12
|
return true;
|
|
13
13
|
}
|
|
14
14
|
exports.ruleMatcher = ruleMatcher;
|
|
15
|
-
function componentRuleMatcher(target, rule) {
|
|
16
|
-
if (typeof rule === 'string') {
|
|
17
|
-
const targetCmpId = component_id_1.ComponentID.tryFromString(target.meta.id);
|
|
18
|
-
const ruleCmpId = component_id_1.ComponentID.tryFromString(rule);
|
|
19
|
-
return component_id_1.ComponentID.isEqual(ruleCmpId, targetCmpId, { ignoreVersion: true });
|
|
20
|
-
}
|
|
21
|
-
if (Array.isArray(rule)) {
|
|
22
|
-
const targetCmpId = component_id_1.ComponentID.tryFromString(target.meta.id);
|
|
23
|
-
const ruleCmpIds = rule.map((x) => component_id_1.ComponentID.tryFromString(x));
|
|
24
|
-
return ruleCmpIds.some((cmdId) => component_id_1.ComponentID.isEqual(targetCmpId, cmdId, { ignoreVersion: true }));
|
|
25
|
-
}
|
|
26
|
-
if (typeof rule === 'function') {
|
|
27
|
-
return rule(target);
|
|
28
|
-
}
|
|
29
|
-
return true;
|
|
30
|
-
}
|
|
31
|
-
exports.componentRuleMatcher = componentRuleMatcher;
|
|
32
15
|
//# sourceMappingURL=rule-matcher.js.map
|
package/dist/rule-matcher.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rule-matcher.js","sourceRoot":"","sources":["../rule-matcher.tsx"],"names":[],"mappings":"
|
|
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,25 +6,22 @@ import { hasComponentMeta } from '@teambit/react.ui.highlighter.component-metada
|
|
|
6
6
|
|
|
7
7
|
import { excludeHighlighterSelector } from '../ignore-highlighter';
|
|
8
8
|
import { HighlightTarget } from '../element-highlighter';
|
|
9
|
-
import { ruleMatcher, MatchRule
|
|
9
|
+
import { ruleMatcher, MatchRule } from '../rule-matcher';
|
|
10
10
|
|
|
11
11
|
export type useHoverHighlighterOptions = {
|
|
12
12
|
debounceDuration: number;
|
|
13
13
|
scopeClass: string;
|
|
14
14
|
disabled?: boolean;
|
|
15
|
-
/** filter highlighter targets by this query selector. (May be a more complex object in the future) */
|
|
16
15
|
rule?: MatchRule;
|
|
17
|
-
/** filter targets by this component match rule */
|
|
18
|
-
componentRule?: ComponentMatchRule;
|
|
19
16
|
};
|
|
20
17
|
|
|
21
18
|
/** fires onChange when targeting a new component */
|
|
22
19
|
export function useHoverHighlighter<T extends HTMLElement = HTMLElement>(
|
|
23
20
|
onChange: (target?: HighlightTarget) => void,
|
|
24
21
|
props: React.HTMLAttributes<T> = {},
|
|
25
|
-
{ debounceDuration, scopeClass, disabled, rule
|
|
22
|
+
{ debounceDuration, scopeClass, disabled, rule }: useHoverHighlighterOptions
|
|
26
23
|
) {
|
|
27
|
-
const { handleElement } = useHoverHandler({ onChange, scopeClass, debounceDuration, disabled, rule
|
|
24
|
+
const { handleElement } = useHoverHandler({ onChange, scopeClass, debounceDuration, disabled, rule });
|
|
28
25
|
|
|
29
26
|
const handlers = useHoverSelection(disabled ? undefined : handleElement, props);
|
|
30
27
|
|
|
@@ -37,17 +34,9 @@ type useHoverHighlighterProps = {
|
|
|
37
34
|
debounceDuration?: number;
|
|
38
35
|
disabled?: boolean;
|
|
39
36
|
rule?: MatchRule;
|
|
40
|
-
componentRule?: ComponentMatchRule;
|
|
41
37
|
};
|
|
42
38
|
|
|
43
|
-
function useHoverHandler({
|
|
44
|
-
onChange,
|
|
45
|
-
scopeClass = '',
|
|
46
|
-
debounceDuration,
|
|
47
|
-
disabled,
|
|
48
|
-
rule,
|
|
49
|
-
componentRule,
|
|
50
|
-
}: useHoverHighlighterProps) {
|
|
39
|
+
function useHoverHandler({ onChange, scopeClass = '', debounceDuration, disabled, rule }: useHoverHighlighterProps) {
|
|
51
40
|
// debounced method is ref'ed, so no need for useCallback
|
|
52
41
|
const _handleElement = (element: HTMLElement | null) => {
|
|
53
42
|
// clear highlighter at the edges:
|
|
@@ -59,7 +48,7 @@ function useHoverHandler({
|
|
|
59
48
|
// skip DOM trees having 'data-ignore-component-highlight'
|
|
60
49
|
if (element.closest(`.${scopeClass} ${excludeHighlighterSelector}`)) return;
|
|
61
50
|
|
|
62
|
-
const result = bubbleToBitComponent(element, rule,
|
|
51
|
+
const result = bubbleToBitComponent(element, rule ? (current) => ruleMatcher(current, rule) : undefined);
|
|
63
52
|
if (!result) return;
|
|
64
53
|
|
|
65
54
|
onChange({
|
|
@@ -82,29 +71,23 @@ function useHoverHandler({
|
|
|
82
71
|
}
|
|
83
72
|
|
|
84
73
|
/** go up the dom tree until reaching a react bit component */
|
|
85
|
-
function bubbleToBitComponent(
|
|
86
|
-
element: HTMLElement | null,
|
|
87
|
-
elementRule?: MatchRule,
|
|
88
|
-
componentRule?: ComponentMatchRule
|
|
89
|
-
) {
|
|
74
|
+
function bubbleToBitComponent(element: HTMLElement | null, filter?: (elem: HTMLElement) => boolean) {
|
|
90
75
|
for (let current = element; current; current = current.parentElement) {
|
|
91
76
|
current = toRootElement(current);
|
|
92
|
-
if (!current) return undefined;
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
};
|
|
105
|
-
}
|
|
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
|
+
};
|
|
106
89
|
}
|
|
107
90
|
}
|
|
108
91
|
|
|
109
92
|
return undefined;
|
|
110
|
-
}
|
|
93
|
+
}
|
|
@@ -5,7 +5,7 @@ import { v4 } from 'uuid';
|
|
|
5
5
|
import { useHoverHighlighter } from '../hover-highlighter';
|
|
6
6
|
import { ElementHighlighter, HighlightTarget, Placement, HighlightClasses } from '../element-highlighter';
|
|
7
7
|
import { useMultiHighlighter } from '../multi-highlighter/use-multi-highlighter';
|
|
8
|
-
import type { MatchRule
|
|
8
|
+
import type { MatchRule } from '../rule-matcher';
|
|
9
9
|
|
|
10
10
|
export interface HybridHighlighterProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
11
11
|
/** stop all highlighting and drop listeners */
|
|
@@ -27,7 +27,6 @@ export interface HybridHighlighterProps extends React.HTMLAttributes<HTMLDivElem
|
|
|
27
27
|
|
|
28
28
|
/** filter highlighter targets by this query selector. (May be a more complex object in the future) */
|
|
29
29
|
rule?: MatchRule;
|
|
30
|
-
componentRule?: ComponentMatchRule;
|
|
31
30
|
|
|
32
31
|
/** set the behavior of the highlighter.
|
|
33
32
|
* `disabled` - stops highlighting.
|
|
@@ -48,7 +47,6 @@ export function HybridHighlighter({
|
|
|
48
47
|
watchMotion = true,
|
|
49
48
|
placement,
|
|
50
49
|
rule,
|
|
51
|
-
componentRule,
|
|
52
50
|
|
|
53
51
|
classes,
|
|
54
52
|
highlightStyle,
|
|
@@ -78,7 +76,6 @@ export function HybridHighlighter({
|
|
|
78
76
|
scopeClass,
|
|
79
77
|
disabled: disabled || mode !== 'hover',
|
|
80
78
|
rule,
|
|
81
|
-
componentRule
|
|
82
79
|
}
|
|
83
80
|
);
|
|
84
81
|
|
|
@@ -88,7 +85,6 @@ export function HybridHighlighter({
|
|
|
88
85
|
scopeClass,
|
|
89
86
|
disabled: disabled || mode !== 'allChildren',
|
|
90
87
|
rule,
|
|
91
|
-
componentRule
|
|
92
88
|
});
|
|
93
89
|
|
|
94
90
|
const _styles = useMemo(
|
|
@@ -127,4 +123,4 @@ export function HybridHighlighter({
|
|
|
127
123
|
))}
|
|
128
124
|
</div>
|
|
129
125
|
);
|
|
130
|
-
}
|
|
126
|
+
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
// import { EnterpriseOffering } from '@teambit/evangelist.pages.enterprise-offering';
|
|
3
3
|
import { MockedComponentWithMeta } from '@teambit/react.ui.highlighter.component-metadata.bit-component-meta';
|
|
4
|
-
import { IconButton } from '@teambit/design.ui.icon-button';
|
|
5
4
|
import { ExcludeHighlighter } from '../ignore-highlighter';
|
|
6
5
|
import { MultiHighlighter } from './multi-highlighter';
|
|
7
6
|
|
|
@@ -56,7 +55,7 @@ export const MultiHighlighterInsideIgnore = () => {
|
|
|
56
55
|
|
|
57
56
|
export const MultiHighlighterWithRule = () => {
|
|
58
57
|
return (
|
|
59
|
-
<MultiHighlighter rule="#someSubTree *"
|
|
58
|
+
<MultiHighlighter rule="#someSubTree *">
|
|
60
59
|
<br />
|
|
61
60
|
<br />
|
|
62
61
|
<br />
|
|
@@ -65,31 +64,16 @@ export const MultiHighlighterWithRule = () => {
|
|
|
65
64
|
<br />
|
|
66
65
|
<br />
|
|
67
66
|
<div id="someSubTree">
|
|
68
|
-
<MockedComponentWithMeta>
|
|
67
|
+
<MockedComponentWithMeta>this will be highlighted</MockedComponentWithMeta>
|
|
69
68
|
</div>
|
|
70
69
|
</MultiHighlighter>
|
|
71
70
|
);
|
|
72
71
|
};
|
|
73
72
|
|
|
74
|
-
export const MultiHighlighterWithComponentRule = () => {
|
|
75
|
-
return (
|
|
76
|
-
<MultiHighlighter componentRule="teambit.design/ui/icon-button">
|
|
77
|
-
<br />
|
|
78
|
-
<br />
|
|
79
|
-
<br />
|
|
80
|
-
<MockedComponentWithMeta>no highlighter</MockedComponentWithMeta>
|
|
81
|
-
<br />
|
|
82
|
-
<br />
|
|
83
|
-
<br />
|
|
84
|
-
<IconButton>highlighted because of component rule</IconButton>
|
|
85
|
-
</MultiHighlighter>
|
|
86
|
-
);
|
|
87
|
-
};
|
|
88
|
-
|
|
89
73
|
// export const HighlightingAllElementsInTheEnterprisePage = () => {
|
|
90
74
|
// return (
|
|
91
75
|
// <MultiHighlighter>
|
|
92
76
|
// <EnterpriseOffering style={{ height: 300 }} />
|
|
93
77
|
// </MultiHighlighter>
|
|
94
78
|
// );
|
|
95
|
-
// };
|
|
79
|
+
// };
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
} from '@teambit/react.ui.highlighter.component-metadata.bit-component-meta';
|
|
9
9
|
import { HighlightTarget } from '../element-highlighter';
|
|
10
10
|
import { excludeHighlighterSelector } from '../ignore-highlighter';
|
|
11
|
-
import { ruleMatcher, MatchRule
|
|
11
|
+
import { ruleMatcher, MatchRule } from '../rule-matcher';
|
|
12
12
|
|
|
13
13
|
type useMultiHighlighterProps = {
|
|
14
14
|
onChange: (highlighterTargets: Record<string, HighlightTarget>) => void;
|
|
@@ -17,8 +17,6 @@ type useMultiHighlighterProps = {
|
|
|
17
17
|
scopeClass?: string;
|
|
18
18
|
/** filter highlighter targets by this query selector. (May be a more complex object in the future) */
|
|
19
19
|
rule?: MatchRule;
|
|
20
|
-
/** filter targets by this component match rule */
|
|
21
|
-
componentRule?: ComponentMatchRule;
|
|
22
20
|
|
|
23
21
|
// /** automatically update when children update. Use with caution, might be slow */
|
|
24
22
|
// watchDom?: boolean;
|
|
@@ -30,7 +28,6 @@ export function useMultiHighlighter({
|
|
|
30
28
|
scopeRef,
|
|
31
29
|
scopeClass: scopeSelector = '',
|
|
32
30
|
rule,
|
|
33
|
-
componentRule,
|
|
34
31
|
}: useMultiHighlighterProps) {
|
|
35
32
|
useEffect(() => {
|
|
36
33
|
const nextTargets: Record<string, HighlightTarget> = {};
|
|
@@ -49,10 +46,9 @@ export function useMultiHighlighter({
|
|
|
49
46
|
uniqueRoots.forEach((element) => {
|
|
50
47
|
const comp = domToReact(element);
|
|
51
48
|
if (!element || !hasComponentMeta(comp)) return;
|
|
52
|
-
const meta = comp[componentMetaField];
|
|
53
|
-
if (!componentRuleMatcher({ meta }, componentRule)) return;
|
|
54
49
|
|
|
55
50
|
const key = getXPath(element);
|
|
51
|
+
const meta = comp[componentMetaField];
|
|
56
52
|
const compId = meta[componentMetaProperties.componentId];
|
|
57
53
|
const link = meta[componentMetaProperties.homepageUrl];
|
|
58
54
|
const local = meta[componentMetaProperties.isExported] === false;
|
|
@@ -71,4 +67,4 @@ function targetsSelector(
|
|
|
71
67
|
scopeSelector = ':scope'
|
|
72
68
|
) {
|
|
73
69
|
return `:not(${scopeSelector} ${excludeHighlighterSelector}, ${scopeSelector} ${excludeHighlighterSelector} *)`;
|
|
74
|
-
}
|
|
70
|
+
}
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teambit/react.ui.component-highlighter",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.492",
|
|
4
4
|
"homepage": "https://bit.dev/teambit/react/ui/component-highlighter",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"componentId": {
|
|
7
7
|
"scope": "teambit.react",
|
|
8
8
|
"name": "ui/component-highlighter",
|
|
9
|
-
"version": "0.0.
|
|
9
|
+
"version": "0.0.492"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"classnames": "2.2.6",
|
|
13
|
-
"uuid": "3.4.0",
|
|
14
|
-
"use-debounce": "6.0.1",
|
|
15
13
|
"@popperjs/core": "2.6.0",
|
|
16
14
|
"react-popper": "2.2.4",
|
|
15
|
+
"uuid": "3.4.0",
|
|
16
|
+
"use-debounce": "6.0.1",
|
|
17
17
|
"get-xpath": "3.0.1",
|
|
18
18
|
"url-join": "4.0.1",
|
|
19
19
|
"core-js": "^3.0.0",
|
|
@@ -21,11 +21,11 @@
|
|
|
21
21
|
"@teambit/base-ui.utils.popper-js.resize-to-match-reference": "1.0.0",
|
|
22
22
|
"@teambit/base-ui.surfaces.card": "1.0.1",
|
|
23
23
|
"@teambit/base-ui.routing.native-link": "1.0.0",
|
|
24
|
-
"@teambit/component-id": "0.0.389",
|
|
25
|
-
"@teambit/react.ui.highlighter.component-metadata.bit-component-meta": "0.0.10",
|
|
26
24
|
"@teambit/ui-foundation.ui.constants.z-indexes": "0.0.477",
|
|
27
25
|
"@teambit/react.modules.dom-to-react": "0.0.477",
|
|
26
|
+
"@teambit/react.ui.highlighter.component-metadata.bit-component-meta": "0.0.10",
|
|
28
27
|
"@teambit/react.ui.hover-selector": "0.0.155",
|
|
28
|
+
"@teambit/component-id": "0.0.389",
|
|
29
29
|
"@teambit/component.modules.component-url": "0.0.110"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
package/rule-matcher.tsx
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
import { ComponentMeta } from '@teambit/react.ui.highlighter.component-metadata.bit-component-meta';
|
|
3
|
-
|
|
4
|
-
export type ComponentMatchTarget = { meta: ComponentMeta };
|
|
1
|
+
// in the future, we will add more options here, like include / exclude objects.
|
|
5
2
|
|
|
6
3
|
export type MatchRule = undefined | string | ((element: HTMLElement) => boolean);
|
|
7
|
-
export type ComponentMatchRule = undefined | string | string[] | ((target: ComponentMatchTarget) => boolean);
|
|
8
4
|
|
|
9
5
|
export function ruleMatcher(element: HTMLElement, rule: MatchRule) {
|
|
10
6
|
if (typeof rule === 'string') {
|
|
@@ -17,25 +13,3 @@ export function ruleMatcher(element: HTMLElement, rule: MatchRule) {
|
|
|
17
13
|
|
|
18
14
|
return true;
|
|
19
15
|
}
|
|
20
|
-
|
|
21
|
-
export function componentRuleMatcher(target: ComponentMatchTarget, rule: ComponentMatchRule): boolean {
|
|
22
|
-
if (typeof rule === 'string') {
|
|
23
|
-
const targetCmpId = ComponentID.tryFromString(target.meta.id);
|
|
24
|
-
const ruleCmpId = ComponentID.tryFromString(rule);
|
|
25
|
-
|
|
26
|
-
return ComponentID.isEqual(ruleCmpId, targetCmpId, { ignoreVersion: true });
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if (Array.isArray(rule)) {
|
|
30
|
-
const targetCmpId = ComponentID.tryFromString(target.meta.id);
|
|
31
|
-
const ruleCmpIds = rule.map((x) => ComponentID.tryFromString(x));
|
|
32
|
-
|
|
33
|
-
return ruleCmpIds.some((cmdId) => ComponentID.isEqual(targetCmpId, cmdId, { ignoreVersion: true }));
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if (typeof rule === 'function') {
|
|
37
|
-
return rule(target);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return true;
|
|
41
|
-
}
|
|
Binary file
|