@teambit/react.ui.component-highlighter 0.0.0-4d64e75088ad738b699f1df7db0bcd7201d589d0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (134) hide show
  1. package/children-highlighter/children-highlighter.composition.tsx +103 -0
  2. package/children-highlighter/children-highlighter.spec.tsx +22 -0
  3. package/children-highlighter/children-highlighter.tsx +9 -0
  4. package/children-highlighter/index.ts +5 -0
  5. package/children-highlighter/use-children-highlighter.tsx +79 -0
  6. package/component-highlighter.docs.md +191 -0
  7. package/dist/children-highlighter/children-highlighter.composition.d.ts +6 -0
  8. package/dist/children-highlighter/children-highlighter.composition.js +93 -0
  9. package/dist/children-highlighter/children-highlighter.composition.js.map +1 -0
  10. package/dist/children-highlighter/children-highlighter.d.ts +4 -0
  11. package/dist/children-highlighter/children-highlighter.js +24 -0
  12. package/dist/children-highlighter/children-highlighter.js.map +1 -0
  13. package/dist/children-highlighter/children-highlighter.spec.d.ts +1 -0
  14. package/dist/children-highlighter/children-highlighter.spec.js +22 -0
  15. package/dist/children-highlighter/children-highlighter.spec.js.map +1 -0
  16. package/dist/children-highlighter/index.d.ts +4 -0
  17. package/dist/children-highlighter/index.js +8 -0
  18. package/dist/children-highlighter/index.js.map +1 -0
  19. package/dist/children-highlighter/use-children-highlighter.d.ts +18 -0
  20. package/dist/children-highlighter/use-children-highlighter.js +51 -0
  21. package/dist/children-highlighter/use-children-highlighter.js.map +1 -0
  22. package/dist/component-highlighter.docs.md +191 -0
  23. package/dist/element-highlighter/element-highlighter.compositions.d.ts +14 -0
  24. package/dist/element-highlighter/element-highlighter.compositions.js +103 -0
  25. package/dist/element-highlighter/element-highlighter.compositions.js.map +1 -0
  26. package/dist/element-highlighter/element-highlighter.d.ts +22 -0
  27. package/dist/element-highlighter/element-highlighter.js +31 -0
  28. package/dist/element-highlighter/element-highlighter.js.map +1 -0
  29. package/dist/element-highlighter/element-highlighter.module.scss +10 -0
  30. package/dist/element-highlighter/index.d.ts +2 -0
  31. package/dist/element-highlighter/index.js +6 -0
  32. package/dist/element-highlighter/index.js.map +1 -0
  33. package/dist/frame/frame.d.ts +13 -0
  34. package/dist/frame/frame.js +126 -0
  35. package/dist/frame/frame.js.map +1 -0
  36. package/dist/frame/frame.module.scss +23 -0
  37. package/dist/frame/index.d.ts +2 -0
  38. package/dist/frame/index.js +6 -0
  39. package/dist/frame/index.js.map +1 -0
  40. package/dist/hover-highlighter/bubble-to-component.d.ts +24 -0
  41. package/dist/hover-highlighter/bubble-to-component.js +55 -0
  42. package/dist/hover-highlighter/bubble-to-component.js.map +1 -0
  43. package/dist/hover-highlighter/bubble-to-component.spec.d.ts +1 -0
  44. package/dist/hover-highlighter/bubble-to-component.spec.js +38 -0
  45. package/dist/hover-highlighter/bubble-to-component.spec.js.map +1 -0
  46. package/dist/hover-highlighter/hover-highlighter.compositions.d.ts +4 -0
  47. package/dist/hover-highlighter/hover-highlighter.compositions.js +73 -0
  48. package/dist/hover-highlighter/hover-highlighter.compositions.js.map +1 -0
  49. package/dist/hover-highlighter/hover-highlighter.d.ts +4 -0
  50. package/dist/hover-highlighter/hover-highlighter.js +24 -0
  51. package/dist/hover-highlighter/hover-highlighter.js.map +1 -0
  52. package/dist/hover-highlighter/hover-highlighter.spec.d.ts +1 -0
  53. package/dist/hover-highlighter/hover-highlighter.spec.js +95 -0
  54. package/dist/hover-highlighter/hover-highlighter.spec.js.map +1 -0
  55. package/dist/hover-highlighter/index.d.ts +4 -0
  56. package/dist/hover-highlighter/index.js +8 -0
  57. package/dist/hover-highlighter/index.js.map +1 -0
  58. package/dist/hover-highlighter/use-hover-highlighter.d.ts +25 -0
  59. package/dist/hover-highlighter/use-hover-highlighter.js +47 -0
  60. package/dist/hover-highlighter/use-hover-highlighter.js.map +1 -0
  61. package/dist/hybrid-highlighter/hybrid-highlighter.d.ts +36 -0
  62. package/dist/hybrid-highlighter/hybrid-highlighter.js +79 -0
  63. package/dist/hybrid-highlighter/hybrid-highlighter.js.map +1 -0
  64. package/dist/hybrid-highlighter/index.d.ts +2 -0
  65. package/dist/hybrid-highlighter/index.js +6 -0
  66. package/dist/hybrid-highlighter/index.js.map +1 -0
  67. package/dist/ignore-highlighter.d.ts +19 -0
  68. package/dist/ignore-highlighter.js +25 -0
  69. package/dist/ignore-highlighter.js.map +1 -0
  70. package/dist/index.d.ts +10 -0
  71. package/dist/index.js +18 -0
  72. package/dist/index.js.map +1 -0
  73. package/dist/label/component-strip.compositions.d.ts +2 -0
  74. package/dist/label/component-strip.compositions.js +17 -0
  75. package/dist/label/component-strip.compositions.js.map +1 -0
  76. package/dist/label/component-strip.d.ts +7 -0
  77. package/dist/label/component-strip.js +61 -0
  78. package/dist/label/component-strip.js.map +1 -0
  79. package/dist/label/component-strip.module.scss +68 -0
  80. package/dist/label/index.d.ts +4 -0
  81. package/dist/label/index.js +8 -0
  82. package/dist/label/index.js.map +1 -0
  83. package/dist/label/label-container.d.ts +12 -0
  84. package/dist/label/label-container.js +75 -0
  85. package/dist/label/label-container.js.map +1 -0
  86. package/dist/label/label.d.ts +6 -0
  87. package/dist/label/label.js +60 -0
  88. package/dist/label/label.js.map +1 -0
  89. package/dist/label/label.module.scss +32 -0
  90. package/dist/label/links.d.ts +2 -0
  91. package/dist/label/links.js +16 -0
  92. package/dist/label/links.js.map +1 -0
  93. package/dist/label/other-components.d.ts +9 -0
  94. package/dist/label/other-components.js +34 -0
  95. package/dist/label/other-components.js.map +1 -0
  96. package/dist/mock-component.d.ts +14 -0
  97. package/dist/mock-component.js +43 -0
  98. package/dist/mock-component.js.map +1 -0
  99. package/dist/preview-1751963029152.js +10 -0
  100. package/dist/rule-matcher.d.ts +8 -0
  101. package/dist/rule-matcher.js +32 -0
  102. package/dist/rule-matcher.js.map +1 -0
  103. package/element-highlighter/element-highlighter.compositions.tsx +130 -0
  104. package/element-highlighter/element-highlighter.module.scss +10 -0
  105. package/element-highlighter/element-highlighter.tsx +51 -0
  106. package/element-highlighter/index.ts +2 -0
  107. package/frame/frame.module.scss +23 -0
  108. package/frame/frame.tsx +139 -0
  109. package/frame/index.ts +2 -0
  110. package/hover-highlighter/bubble-to-component.spec.tsx +57 -0
  111. package/hover-highlighter/bubble-to-component.tsx +82 -0
  112. package/hover-highlighter/hover-highlighter.compositions.tsx +65 -0
  113. package/hover-highlighter/hover-highlighter.spec.tsx +115 -0
  114. package/hover-highlighter/hover-highlighter.tsx +8 -0
  115. package/hover-highlighter/index.ts +5 -0
  116. package/hover-highlighter/use-hover-highlighter.tsx +85 -0
  117. package/hybrid-highlighter/hybrid-highlighter.tsx +136 -0
  118. package/hybrid-highlighter/index.ts +2 -0
  119. package/ignore-highlighter.tsx +22 -0
  120. package/index.ts +21 -0
  121. package/label/component-strip.compositions.tsx +13 -0
  122. package/label/component-strip.module.scss +68 -0
  123. package/label/component-strip.tsx +57 -0
  124. package/label/index.ts +5 -0
  125. package/label/label-container.tsx +72 -0
  126. package/label/label.module.scss +32 -0
  127. package/label/label.tsx +37 -0
  128. package/label/links.tsx +9 -0
  129. package/label/other-components.tsx +51 -0
  130. package/mock-component.tsx +23 -0
  131. package/package.json +61 -0
  132. package/rule-matcher.tsx +42 -0
  133. package/types/asset.d.ts +29 -0
  134. package/types/style.d.ts +42 -0
@@ -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
+ }
@@ -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,61 @@
1
+ {
2
+ "name": "@teambit/react.ui.component-highlighter",
3
+ "version": "0.0.0-4d64e75088ad738b699f1df7db0bcd7201d589d0",
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": "4d64e75088ad738b699f1df7db0bcd7201d589d0"
10
+ },
11
+ "dependencies": {
12
+ "get-xpath": "^3.0.1",
13
+ "classnames": "^2.3.1",
14
+ "@floating-ui/react-dom": "0.7.2",
15
+ "uuid": "^10.0.0",
16
+ "use-debounce": "^8.0.1",
17
+ "lodash.compact": "^3.0.1",
18
+ "url-join": "^4.0.1",
19
+ "@tippyjs/react": "4.2.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/uuid": "3.4.9",
32
+ "@types/react-dom": "^17.0.5",
33
+ "@types/lodash.compact": "3.0.6",
34
+ "@types/url-join": "^4.0.0",
35
+ "@types/mocha": "9.1.0",
36
+ "@types/node": "12.20.4",
37
+ "@types/jest": "^26.0.0",
38
+ "@babel/runtime": "7.20.0",
39
+ "@types/testing-library__jest-dom": "5.9.5"
40
+ },
41
+ "peerDependencies": {
42
+ "react": "^16.8.0 || ^17.0.0",
43
+ "react-dom": "^16.8.0 || ^17.0.0"
44
+ },
45
+ "license": "Apache-2.0",
46
+ "optionalDependencies": {},
47
+ "peerDependenciesMeta": {},
48
+ "private": false,
49
+ "repository": {
50
+ "type": "git",
51
+ "url": "https://github.com/teambit/bit"
52
+ },
53
+ "keywords": [
54
+ "bit",
55
+ "components",
56
+ "collaboration",
57
+ "web",
58
+ "react",
59
+ "react-components"
60
+ ]
61
+ }
@@ -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
+ }
@@ -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
+ }
@@ -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
+ }