@teambit/react.ui.component-highlighter 0.0.0-3456ec42c20f5ecbc6cb251096040bd1c79ecc95
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/children-highlighter/children-highlighter.composition.tsx +103 -0
- package/children-highlighter/children-highlighter.spec.tsx +22 -0
- package/children-highlighter/children-highlighter.tsx +9 -0
- package/children-highlighter/index.ts +5 -0
- package/children-highlighter/use-children-highlighter.tsx +79 -0
- package/component-highlighter.docs.md +191 -0
- package/dist/children-highlighter/children-highlighter.composition.d.ts +6 -0
- package/dist/children-highlighter/children-highlighter.composition.js +93 -0
- package/dist/children-highlighter/children-highlighter.composition.js.map +1 -0
- package/dist/children-highlighter/children-highlighter.d.ts +4 -0
- package/dist/children-highlighter/children-highlighter.js +24 -0
- package/dist/children-highlighter/children-highlighter.js.map +1 -0
- package/dist/children-highlighter/children-highlighter.spec.d.ts +1 -0
- package/dist/children-highlighter/children-highlighter.spec.js +22 -0
- package/dist/children-highlighter/children-highlighter.spec.js.map +1 -0
- package/dist/children-highlighter/index.d.ts +4 -0
- package/dist/children-highlighter/index.js +8 -0
- package/dist/children-highlighter/index.js.map +1 -0
- package/dist/children-highlighter/use-children-highlighter.d.ts +18 -0
- package/dist/children-highlighter/use-children-highlighter.js +51 -0
- package/dist/children-highlighter/use-children-highlighter.js.map +1 -0
- package/dist/component-highlighter.docs.md +191 -0
- package/dist/element-highlighter/element-highlighter.compositions.d.ts +14 -0
- package/dist/element-highlighter/element-highlighter.compositions.js +103 -0
- package/dist/element-highlighter/element-highlighter.compositions.js.map +1 -0
- package/dist/element-highlighter/element-highlighter.d.ts +22 -0
- package/dist/element-highlighter/element-highlighter.js +31 -0
- package/dist/element-highlighter/element-highlighter.js.map +1 -0
- package/dist/element-highlighter/element-highlighter.module.scss +10 -0
- package/dist/element-highlighter/index.d.ts +2 -0
- package/dist/element-highlighter/index.js +6 -0
- package/dist/element-highlighter/index.js.map +1 -0
- package/dist/frame/frame.d.ts +14 -0
- package/dist/frame/frame.js +128 -0
- package/dist/frame/frame.js.map +1 -0
- package/dist/frame/frame.module.scss +23 -0
- package/dist/frame/index.d.ts +2 -0
- package/dist/frame/index.js +6 -0
- package/dist/frame/index.js.map +1 -0
- package/dist/hover-highlighter/bubble-to-component.d.ts +24 -0
- package/dist/hover-highlighter/bubble-to-component.js +55 -0
- package/dist/hover-highlighter/bubble-to-component.js.map +1 -0
- package/dist/hover-highlighter/bubble-to-component.spec.d.ts +1 -0
- package/dist/hover-highlighter/bubble-to-component.spec.js +38 -0
- package/dist/hover-highlighter/bubble-to-component.spec.js.map +1 -0
- package/dist/hover-highlighter/hover-highlighter.compositions.d.ts +4 -0
- package/dist/hover-highlighter/hover-highlighter.compositions.js +73 -0
- package/dist/hover-highlighter/hover-highlighter.compositions.js.map +1 -0
- package/dist/hover-highlighter/hover-highlighter.d.ts +4 -0
- package/dist/hover-highlighter/hover-highlighter.js +24 -0
- package/dist/hover-highlighter/hover-highlighter.js.map +1 -0
- package/dist/hover-highlighter/hover-highlighter.spec.d.ts +1 -0
- package/dist/hover-highlighter/hover-highlighter.spec.js +95 -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 +25 -0
- package/dist/hover-highlighter/use-hover-highlighter.js +47 -0
- package/dist/hover-highlighter/use-hover-highlighter.js.map +1 -0
- package/dist/hybrid-highlighter/hybrid-highlighter.d.ts +36 -0
- package/dist/hybrid-highlighter/hybrid-highlighter.js +83 -0
- package/dist/hybrid-highlighter/hybrid-highlighter.js.map +1 -0
- package/dist/hybrid-highlighter/index.d.ts +2 -0
- package/dist/hybrid-highlighter/index.js +6 -0
- package/dist/hybrid-highlighter/index.js.map +1 -0
- package/dist/ignore-highlighter.d.ts +19 -0
- package/dist/ignore-highlighter.js +25 -0
- package/dist/ignore-highlighter.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/dist/label/component-strip.compositions.d.ts +2 -0
- package/dist/label/component-strip.compositions.js +17 -0
- package/dist/label/component-strip.compositions.js.map +1 -0
- package/dist/label/component-strip.d.ts +7 -0
- package/dist/label/component-strip.js +61 -0
- package/dist/label/component-strip.js.map +1 -0
- package/dist/label/component-strip.module.scss +68 -0
- package/dist/label/index.d.ts +4 -0
- package/dist/label/index.js +8 -0
- package/dist/label/index.js.map +1 -0
- package/dist/label/label-container.d.ts +13 -0
- package/dist/label/label-container.js +77 -0
- package/dist/label/label-container.js.map +1 -0
- package/dist/label/label.d.ts +6 -0
- package/dist/label/label.js +60 -0
- package/dist/label/label.js.map +1 -0
- package/dist/label/label.module.scss +32 -0
- package/dist/label/links.d.ts +2 -0
- package/dist/label/links.js +16 -0
- package/dist/label/links.js.map +1 -0
- package/dist/label/other-components.d.ts +9 -0
- package/dist/label/other-components.js +34 -0
- package/dist/label/other-components.js.map +1 -0
- package/dist/mock-component.d.ts +14 -0
- package/dist/mock-component.js +43 -0
- package/dist/mock-component.js.map +1 -0
- package/dist/preview-1766004072990.js +10 -0
- package/dist/rule-matcher.d.ts +8 -0
- package/dist/rule-matcher.js +32 -0
- package/dist/rule-matcher.js.map +1 -0
- package/element-highlighter/element-highlighter.compositions.tsx +130 -0
- package/element-highlighter/element-highlighter.module.scss +10 -0
- package/element-highlighter/element-highlighter.tsx +51 -0
- package/element-highlighter/index.ts +2 -0
- package/frame/frame.module.scss +23 -0
- package/frame/frame.tsx +142 -0
- package/frame/index.ts +2 -0
- package/hover-highlighter/bubble-to-component.spec.tsx +57 -0
- package/hover-highlighter/bubble-to-component.tsx +82 -0
- package/hover-highlighter/hover-highlighter.compositions.tsx +65 -0
- package/hover-highlighter/hover-highlighter.spec.tsx +115 -0
- package/hover-highlighter/hover-highlighter.tsx +8 -0
- package/hover-highlighter/index.ts +5 -0
- package/hover-highlighter/use-hover-highlighter.tsx +85 -0
- package/hybrid-highlighter/hybrid-highlighter.tsx +142 -0
- package/hybrid-highlighter/index.ts +2 -0
- package/ignore-highlighter.tsx +22 -0
- package/index.ts +21 -0
- package/label/component-strip.compositions.tsx +13 -0
- package/label/component-strip.module.scss +68 -0
- package/label/component-strip.tsx +57 -0
- package/label/index.ts +5 -0
- package/label/label-container.tsx +74 -0
- package/label/label.module.scss +32 -0
- package/label/label.tsx +37 -0
- package/label/links.tsx +9 -0
- package/label/other-components.tsx +51 -0
- package/mock-component.tsx +23 -0
- package/package.json +60 -0
- package/rule-matcher.tsx +42 -0
- package/types/asset.d.ts +29 -0
- package/types/style.d.ts +42 -0
package/label/label.tsx
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import React, { useEffect, useState } from 'react';
|
|
2
|
+
import classNames from 'classnames';
|
|
3
|
+
import { ComponentMetaHolder } from '@teambit/react.ui.highlighter.component-metadata.bit-component-meta';
|
|
4
|
+
|
|
5
|
+
import styles from './label.module.scss';
|
|
6
|
+
import { ComponentStrip } from './component-strip';
|
|
7
|
+
import { OtherComponentsPopper } from './other-components';
|
|
8
|
+
|
|
9
|
+
export interface LabelProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
10
|
+
components: (ComponentMetaHolder | string)[];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function Label({ components, ...props }: LabelProps) {
|
|
14
|
+
const [showMore, setShowMore] = useState(false);
|
|
15
|
+
const last = components.slice(-1).pop();
|
|
16
|
+
if (!last) return null;
|
|
17
|
+
|
|
18
|
+
const hasMore = components.length > 1;
|
|
19
|
+
|
|
20
|
+
// reset when switching targets
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
setShowMore(false);
|
|
23
|
+
}, [components]);
|
|
24
|
+
|
|
25
|
+
return (
|
|
26
|
+
<OtherComponentsPopper components={components} visible={showMore} placement="bottom-start">
|
|
27
|
+
<ComponentStrip {...props} component={last}>
|
|
28
|
+
{hasMore && (
|
|
29
|
+
<span
|
|
30
|
+
className={classNames(styles.othersTooltip, showMore && styles.active)}
|
|
31
|
+
onClick={() => setShowMore((x) => !x)}
|
|
32
|
+
/>
|
|
33
|
+
)}
|
|
34
|
+
</ComponentStrip>
|
|
35
|
+
</OtherComponentsPopper>
|
|
36
|
+
);
|
|
37
|
+
}
|
package/label/links.tsx
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import urlJoin from 'url-join';
|
|
2
|
+
import type { ComponentID } from '@teambit/component-id';
|
|
3
|
+
import { ComponentUrl } from '@teambit/component.modules.component-url';
|
|
4
|
+
|
|
5
|
+
export function calcComponentLink(id: ComponentID | undefined, exported: boolean | undefined) {
|
|
6
|
+
if (!id) return undefined;
|
|
7
|
+
if (exported) return ComponentUrl.toUrl(id);
|
|
8
|
+
return urlJoin('/', id.fullName);
|
|
9
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import Tippy, { TippyProps } from '@tippyjs/react/headless';
|
|
3
|
+
import { ComponentMetaHolder } from '@teambit/react.ui.highlighter.component-metadata.bit-component-meta';
|
|
4
|
+
|
|
5
|
+
import { ComponentStrip } from './component-strip';
|
|
6
|
+
import styles from './label.module.scss';
|
|
7
|
+
|
|
8
|
+
export type OtherComponentsProps = {
|
|
9
|
+
components: (ComponentMetaHolder | string)[];
|
|
10
|
+
start?: number;
|
|
11
|
+
end?: number;
|
|
12
|
+
} & TippyProps;
|
|
13
|
+
|
|
14
|
+
// a popper ("tooltip") that shows the additional React Components related to this dom element
|
|
15
|
+
export function OtherComponentsPopper({
|
|
16
|
+
components,
|
|
17
|
+
children,
|
|
18
|
+
start,
|
|
19
|
+
end = -1,
|
|
20
|
+
placement = 'bottom',
|
|
21
|
+
interactive = true,
|
|
22
|
+
...tippyProps
|
|
23
|
+
}: OtherComponentsProps) {
|
|
24
|
+
const content = (
|
|
25
|
+
<>
|
|
26
|
+
{components
|
|
27
|
+
.slice(start, end)
|
|
28
|
+
.reverse()
|
|
29
|
+
.map((comp, idx) => (
|
|
30
|
+
<ComponentStrip key={idx} component={comp} />
|
|
31
|
+
))}
|
|
32
|
+
</>
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
return (
|
|
36
|
+
<Tippy
|
|
37
|
+
placement={placement}
|
|
38
|
+
interactive={interactive}
|
|
39
|
+
{...tippyProps}
|
|
40
|
+
// second parameter "content" is always undefined, use content inline
|
|
41
|
+
// https://github.com/atomiks/tippyjs-react/issues/341
|
|
42
|
+
render={(attrs) => (
|
|
43
|
+
<div {...attrs} className={styles.othersContainer}>
|
|
44
|
+
{content}
|
|
45
|
+
</div>
|
|
46
|
+
)}
|
|
47
|
+
>
|
|
48
|
+
{children}
|
|
49
|
+
</Tippy>
|
|
50
|
+
);
|
|
51
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import React, { ButtonHTMLAttributes, HTMLAttributes } from 'react';
|
|
2
|
+
import { componentMetaField, ComponentMeta } from '@teambit/react.ui.highlighter.component-metadata.bit-component-meta';
|
|
3
|
+
|
|
4
|
+
export function MockTarget({ children, ...rest }: HTMLAttributes<HTMLDivElement>) {
|
|
5
|
+
return <div {...rest}>{children}</div>;
|
|
6
|
+
}
|
|
7
|
+
MockTarget[componentMetaField] = {
|
|
8
|
+
id: 'teambit.design/ui/mock-target@1.6.2',
|
|
9
|
+
} as ComponentMeta;
|
|
10
|
+
|
|
11
|
+
export function MockButton({ children, ...rest }: ButtonHTMLAttributes<HTMLButtonElement>) {
|
|
12
|
+
return <button {...rest}>{children}</button>;
|
|
13
|
+
}
|
|
14
|
+
MockButton[componentMetaField] = {
|
|
15
|
+
id: 'teambit.design/ui/icon-button@1.6.2',
|
|
16
|
+
} as ComponentMeta;
|
|
17
|
+
|
|
18
|
+
export function MockSnap({ children, ...rest }: ButtonHTMLAttributes<HTMLButtonElement>) {
|
|
19
|
+
return <button {...rest}>{children}</button>;
|
|
20
|
+
}
|
|
21
|
+
MockSnap[componentMetaField] = {
|
|
22
|
+
id: 'teambit.design/ui/icon-button@a21594d5cc63fd24d2b4763fa7d817b131f0edbb',
|
|
23
|
+
} as ComponentMeta;
|
package/package.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@teambit/react.ui.component-highlighter",
|
|
3
|
+
"version": "0.0.0-3456ec42c20f5ecbc6cb251096040bd1c79ecc95",
|
|
4
|
+
"homepage": "https://bit.cloud/teambit/react/ui/component-highlighter",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"componentId": {
|
|
7
|
+
"scope": "teambit.react",
|
|
8
|
+
"name": "ui/component-highlighter",
|
|
9
|
+
"version": "3456ec42c20f5ecbc6cb251096040bd1c79ecc95"
|
|
10
|
+
},
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"get-xpath": "^3.0.1",
|
|
13
|
+
"classnames": "^2.3.1",
|
|
14
|
+
"uuid": "^10.0.0",
|
|
15
|
+
"lodash.compact": "^3.0.1",
|
|
16
|
+
"@floating-ui/react-dom": "0.7.2",
|
|
17
|
+
"url-join": "^4.0.1",
|
|
18
|
+
"@tippyjs/react": "4.2.0",
|
|
19
|
+
"use-debounce": "^8.0.1",
|
|
20
|
+
"core-js": "^3.0.0",
|
|
21
|
+
"@teambit/react.ui.highlighter.component-metadata.bit-component-meta": "0.0.21",
|
|
22
|
+
"@teambit/component-id": "1.2.2",
|
|
23
|
+
"@teambit/react.modules.dom-to-react": "0.2.0",
|
|
24
|
+
"@teambit/base-ui.routing.native-link": "1.0.0",
|
|
25
|
+
"@teambit/component.modules.component-url": "0.0.169",
|
|
26
|
+
"@teambit/react.ui.hover-selector": "0.2.0"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@types/react": "^17.0.8",
|
|
30
|
+
"@testing-library/react": "^12.1.5",
|
|
31
|
+
"@types/uuid": "3.4.9",
|
|
32
|
+
"@types/lodash.compact": "3.0.6",
|
|
33
|
+
"@types/url-join": "^4.0.0",
|
|
34
|
+
"@types/react-dom": "^17.0.5",
|
|
35
|
+
"@types/node": "12.20.4",
|
|
36
|
+
"@types/jest": "^26.0.0",
|
|
37
|
+
"@babel/runtime": "7.20.0",
|
|
38
|
+
"@types/testing-library__jest-dom": "5.9.5"
|
|
39
|
+
},
|
|
40
|
+
"peerDependencies": {
|
|
41
|
+
"react": "^16.8.0 || ^17.0.0",
|
|
42
|
+
"react-dom": "^16.8.0 || ^17.0.0"
|
|
43
|
+
},
|
|
44
|
+
"license": "Apache-2.0",
|
|
45
|
+
"optionalDependencies": {},
|
|
46
|
+
"peerDependenciesMeta": {},
|
|
47
|
+
"private": false,
|
|
48
|
+
"repository": {
|
|
49
|
+
"type": "git",
|
|
50
|
+
"url": "https://github.com/teambit/bit"
|
|
51
|
+
},
|
|
52
|
+
"keywords": [
|
|
53
|
+
"bit",
|
|
54
|
+
"components",
|
|
55
|
+
"collaboration",
|
|
56
|
+
"web",
|
|
57
|
+
"react",
|
|
58
|
+
"react-components"
|
|
59
|
+
]
|
|
60
|
+
}
|
package/rule-matcher.tsx
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// in the future, we will add more options here, like include / exclude objects.
|
|
2
|
+
import { ComponentID } from '@teambit/component-id';
|
|
3
|
+
import { ComponentMeta } from '@teambit/react.ui.highlighter.component-metadata.bit-component-meta';
|
|
4
|
+
|
|
5
|
+
export type MatchRule = undefined | string | ((element: HTMLElement) => boolean);
|
|
6
|
+
export type ComponentMatchRule = undefined | string | string[] | ((target: ComponentMatchTarget) => boolean);
|
|
7
|
+
|
|
8
|
+
export function ruleMatcher(element: HTMLElement, rule: MatchRule) {
|
|
9
|
+
if (typeof rule === 'string') {
|
|
10
|
+
return element.matches(rule);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
if (typeof rule === 'function') {
|
|
14
|
+
return rule(element);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export type ComponentMatchTarget = { meta: ComponentMeta };
|
|
21
|
+
|
|
22
|
+
export function componentRuleMatcher(target: ComponentMatchTarget, rule: ComponentMatchRule): boolean {
|
|
23
|
+
if (typeof rule === 'string') {
|
|
24
|
+
const targetCmpId = ComponentID.tryFromString(target.meta.id);
|
|
25
|
+
const ruleCmpId = ComponentID.tryFromString(rule);
|
|
26
|
+
|
|
27
|
+
return ComponentID.isEqual(ruleCmpId, targetCmpId, { ignoreVersion: true });
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (Array.isArray(rule)) {
|
|
31
|
+
const targetCmpId = ComponentID.tryFromString(target.meta.id);
|
|
32
|
+
const ruleCmpIds = rule.map((x) => ComponentID.tryFromString(x));
|
|
33
|
+
|
|
34
|
+
return ruleCmpIds.some((cmdId) => ComponentID.isEqual(targetCmpId, cmdId, { ignoreVersion: true }));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (typeof rule === 'function') {
|
|
38
|
+
return rule(target);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return true;
|
|
42
|
+
}
|
package/types/asset.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
declare module '*.png' {
|
|
2
|
+
const value: any;
|
|
3
|
+
export = value;
|
|
4
|
+
}
|
|
5
|
+
declare module '*.svg' {
|
|
6
|
+
import type { FunctionComponent, SVGProps } from 'react';
|
|
7
|
+
|
|
8
|
+
export const ReactComponent: FunctionComponent<SVGProps<SVGSVGElement> & { title?: string }>;
|
|
9
|
+
const src: string;
|
|
10
|
+
export default src;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// @TODO Gilad
|
|
14
|
+
declare module '*.jpg' {
|
|
15
|
+
const value: any;
|
|
16
|
+
export = value;
|
|
17
|
+
}
|
|
18
|
+
declare module '*.jpeg' {
|
|
19
|
+
const value: any;
|
|
20
|
+
export = value;
|
|
21
|
+
}
|
|
22
|
+
declare module '*.gif' {
|
|
23
|
+
const value: any;
|
|
24
|
+
export = value;
|
|
25
|
+
}
|
|
26
|
+
declare module '*.bmp' {
|
|
27
|
+
const value: any;
|
|
28
|
+
export = value;
|
|
29
|
+
}
|
package/types/style.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
declare module '*.module.css' {
|
|
2
|
+
const classes: { readonly [key: string]: string };
|
|
3
|
+
export default classes;
|
|
4
|
+
}
|
|
5
|
+
declare module '*.module.scss' {
|
|
6
|
+
const classes: { readonly [key: string]: string };
|
|
7
|
+
export default classes;
|
|
8
|
+
}
|
|
9
|
+
declare module '*.module.sass' {
|
|
10
|
+
const classes: { readonly [key: string]: string };
|
|
11
|
+
export default classes;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
declare module '*.module.less' {
|
|
15
|
+
const classes: { readonly [key: string]: string };
|
|
16
|
+
export default classes;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
declare module '*.less' {
|
|
20
|
+
const classes: { readonly [key: string]: string };
|
|
21
|
+
export default classes;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
declare module '*.css' {
|
|
25
|
+
const classes: { readonly [key: string]: string };
|
|
26
|
+
export default classes;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
declare module '*.sass' {
|
|
30
|
+
const classes: { readonly [key: string]: string };
|
|
31
|
+
export default classes;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
declare module '*.scss' {
|
|
35
|
+
const classes: { readonly [key: string]: string };
|
|
36
|
+
export default classes;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
declare module '*.mdx' {
|
|
40
|
+
const component: any;
|
|
41
|
+
export default component;
|
|
42
|
+
}
|