@teambit/react.ui.component-highlighter 0.0.0-2240a868c0f88bba4f62719e6d10d31987cae1f9
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 +113 -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 +138 -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 +83 -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 +93 -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 +71 -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 +87 -0
- package/dist/label/label-container.js.map +1 -0
- package/dist/label/label.d.ts +6 -0
- package/dist/label/label.js +70 -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-1768840768294.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
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import React, { useMemo, ReactNode, forwardRef, ForwardedRef } from 'react';
|
|
2
|
+
import { NativeLink } from '@teambit/base-ui.routing.native-link';
|
|
3
|
+
import { ComponentID } from '@teambit/component-id';
|
|
4
|
+
import { ScopeUrl } from '@teambit/component.modules.component-url';
|
|
5
|
+
import {
|
|
6
|
+
ComponentMeta,
|
|
7
|
+
componentMetaField,
|
|
8
|
+
ComponentMetaHolder,
|
|
9
|
+
} from '@teambit/react.ui.highlighter.component-metadata.bit-component-meta';
|
|
10
|
+
import styles from './component-strip.module.scss';
|
|
11
|
+
import { calcComponentLink } from './links';
|
|
12
|
+
|
|
13
|
+
interface ComponentStripProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
14
|
+
component: ComponentMetaHolder | string;
|
|
15
|
+
}
|
|
16
|
+
export const ComponentStrip = forwardRef(function ComponentStrip(
|
|
17
|
+
{ component, children }: ComponentStripProps,
|
|
18
|
+
ref: ForwardedRef<HTMLDivElement>
|
|
19
|
+
) {
|
|
20
|
+
const { id, homepage, exported } = extractMetadata(component);
|
|
21
|
+
|
|
22
|
+
const parsedId = useMemo(() => ComponentID.tryFromString(id), [id]);
|
|
23
|
+
const componentLink = homepage || calcComponentLink(parsedId, exported);
|
|
24
|
+
|
|
25
|
+
return (
|
|
26
|
+
<div className={styles.componentStrip} ref={ref}>
|
|
27
|
+
{!parsedId && <LabelBlock link={homepage}>{id}</LabelBlock>}
|
|
28
|
+
{parsedId && <LabelBlock link={ScopeUrl.toUrl(parsedId.scope)}>{parsedId.scope}</LabelBlock>}
|
|
29
|
+
{parsedId && (
|
|
30
|
+
<LabelBlock link={componentLink} className={styles.nameBlock}>
|
|
31
|
+
<span>{parsedId.fullName}</span>
|
|
32
|
+
{parsedId.version && parsedId.version !== 'latest' && (
|
|
33
|
+
<span className={styles.version}>@{parsedId.version}</span>
|
|
34
|
+
)}
|
|
35
|
+
</LabelBlock>
|
|
36
|
+
)}
|
|
37
|
+
{children}
|
|
38
|
+
</div>
|
|
39
|
+
);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
function LabelBlock({ link, children, className }: { link?: string; children: ReactNode; className?: string }) {
|
|
43
|
+
const Comp = link ? NativeLink : 'span';
|
|
44
|
+
return (
|
|
45
|
+
<Comp href={link} external={!!link} className={className}>
|
|
46
|
+
{children}
|
|
47
|
+
</Comp>
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function extractMetadata(metadata: string | ComponentMetaHolder): ComponentMeta {
|
|
52
|
+
if (typeof metadata === 'string') {
|
|
53
|
+
return { id: metadata, exported: true };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return metadata[componentMetaField];
|
|
57
|
+
}
|
package/label/index.ts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import React, { useLayoutEffect, useEffect, RefObject } from 'react';
|
|
2
|
+
import classnames from 'classnames';
|
|
3
|
+
import compact from 'lodash.compact';
|
|
4
|
+
import {
|
|
5
|
+
useFloating,
|
|
6
|
+
offset as offsetMiddleware,
|
|
7
|
+
flip as flipMiddleware,
|
|
8
|
+
shift,
|
|
9
|
+
autoUpdate,
|
|
10
|
+
hide,
|
|
11
|
+
} from '@floating-ui/react-dom';
|
|
12
|
+
import type { Placement } from '@floating-ui/react-dom';
|
|
13
|
+
import styles from './label.module.scss';
|
|
14
|
+
|
|
15
|
+
const HAS_RESIZE_OBSERVER = typeof window !== 'undefined' && !!window.ResizeObserver;
|
|
16
|
+
export const useIsomorphicLayoutEffect =
|
|
17
|
+
typeof window !== 'undefined' ? useLayoutEffect : useEffect
|
|
18
|
+
|
|
19
|
+
export interface LabelContainerProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
20
|
+
targetRef: RefObject<HTMLElement | null>;
|
|
21
|
+
offset?: [number, number];
|
|
22
|
+
placement?: Placement;
|
|
23
|
+
flip?: boolean;
|
|
24
|
+
/** continually update label position to match moving elements */
|
|
25
|
+
watchMotion?: boolean;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export type { Placement };
|
|
29
|
+
|
|
30
|
+
export function LabelContainer({
|
|
31
|
+
targetRef,
|
|
32
|
+
offset,
|
|
33
|
+
placement,
|
|
34
|
+
flip = true,
|
|
35
|
+
watchMotion,
|
|
36
|
+
className,
|
|
37
|
+
style,
|
|
38
|
+
...rest
|
|
39
|
+
}: LabelContainerProps) {
|
|
40
|
+
const { x, y, strategy, floating, reference, refs, update, middlewareData } = useFloating({
|
|
41
|
+
placement,
|
|
42
|
+
middleware: compact([
|
|
43
|
+
offset && offsetMiddleware({ mainAxis: offset[0], crossAxis: offset[1] }),
|
|
44
|
+
flip && flipMiddleware(),
|
|
45
|
+
// enabling 'shift' for 'crossAxis' will make floating-ui push the label _inside_, when it has nowhere to go
|
|
46
|
+
shift({ rootBoundary: 'document', mainAxis: true, crossAxis: true }),
|
|
47
|
+
hide({ strategy: 'referenceHidden' }),
|
|
48
|
+
]),
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
useIsomorphicLayoutEffect(() => {
|
|
52
|
+
reference(targetRef.current);
|
|
53
|
+
}, [targetRef.current, reference]);
|
|
54
|
+
|
|
55
|
+
// automatically update on scroll, resize, etc.
|
|
56
|
+
// `watchMotion` will trigger continuous updates using animation frame
|
|
57
|
+
useEffect(() => {
|
|
58
|
+
if (!refs.reference.current || !refs.floating.current || !HAS_RESIZE_OBSERVER) return () => {};
|
|
59
|
+
|
|
60
|
+
return autoUpdate(refs.reference.current, refs.floating.current, update, { animationFrame: !!watchMotion });
|
|
61
|
+
}, [refs.reference.current, refs.floating.current, update, watchMotion]);
|
|
62
|
+
|
|
63
|
+
const isReady = !middlewareData.hide?.referenceHidden;
|
|
64
|
+
|
|
65
|
+
return (
|
|
66
|
+
<div
|
|
67
|
+
{...rest}
|
|
68
|
+
ref={floating}
|
|
69
|
+
className={classnames(className, !isReady && styles.hidden)}
|
|
70
|
+
// starting at pos [0,0] will ensure the label doesn't increase the document size.
|
|
71
|
+
style={{ ...style, position: strategy, top: y ?? 0, left: x ?? 0 }}
|
|
72
|
+
/>
|
|
73
|
+
);
|
|
74
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
.othersContainer {
|
|
2
|
+
> * {
|
|
3
|
+
margin-bottom: 8px;
|
|
4
|
+
|
|
5
|
+
&:last-child {
|
|
6
|
+
margin-bottom: unset;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.othersTooltip {
|
|
12
|
+
user-select: none;
|
|
13
|
+
cursor: pointer;
|
|
14
|
+
|
|
15
|
+
&::before {
|
|
16
|
+
display: inline-block;
|
|
17
|
+
transition: transform 300ms;
|
|
18
|
+
content: '▾';
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
&.active::before {
|
|
22
|
+
transform: rotate(-180deg);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.hidden {
|
|
27
|
+
// label size is needed for position calculations,
|
|
28
|
+
// so it can't be removed by `display: none`
|
|
29
|
+
visibility: hidden;
|
|
30
|
+
pointer-events: none;
|
|
31
|
+
user-select: none;
|
|
32
|
+
}
|
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-2240a868c0f88bba4f62719e6d10d31987cae1f9",
|
|
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": "2240a868c0f88bba4f62719e6d10d31987cae1f9"
|
|
10
|
+
},
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"get-xpath": "^3.0.1",
|
|
13
|
+
"classnames": "^2.3.1",
|
|
14
|
+
"use-debounce": "^8.0.1",
|
|
15
|
+
"@floating-ui/react-dom": "0.7.2",
|
|
16
|
+
"lodash.compact": "^3.0.1",
|
|
17
|
+
"url-join": "^4.0.1",
|
|
18
|
+
"@tippyjs/react": "4.2.0",
|
|
19
|
+
"uuid": "^10.0.0",
|
|
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/react.ui.hover-selector": "0.2.0",
|
|
25
|
+
"@teambit/base-ui.routing.native-link": "1.0.0",
|
|
26
|
+
"@teambit/component.modules.component-url": "0.0.169"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@types/react": "^17.0.8",
|
|
30
|
+
"@testing-library/react": "^12.1.5",
|
|
31
|
+
"@types/react-dom": "^17.0.5",
|
|
32
|
+
"@types/lodash.compact": "3.0.6",
|
|
33
|
+
"@types/url-join": "^4.0.0",
|
|
34
|
+
"@types/uuid": "3.4.9",
|
|
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
|
+
}
|