@teambit/react.ui.component-highlighter 0.0.513 → 0.2.0

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 (59) hide show
  1. package/children-highlighter/children-highlighter.composition.tsx +13 -11
  2. package/children-highlighter/children-highlighter.spec.tsx +1 -1
  3. package/children-highlighter/use-children-highlighter.tsx +6 -3
  4. package/dist/children-highlighter/children-highlighter.composition.js +17 -8
  5. package/dist/children-highlighter/children-highlighter.composition.js.map +1 -1
  6. package/dist/children-highlighter/children-highlighter.spec.js +1 -1
  7. package/dist/children-highlighter/children-highlighter.spec.js.map +1 -1
  8. package/dist/children-highlighter/use-children-highlighter.js +3 -1
  9. package/dist/children-highlighter/use-children-highlighter.js.map +1 -1
  10. package/dist/element-highlighter/element-highlighter.compositions.d.ts +2 -1
  11. package/dist/element-highlighter/element-highlighter.compositions.js +36 -6
  12. package/dist/element-highlighter/element-highlighter.compositions.js.map +1 -1
  13. package/dist/element-highlighter/element-highlighter.js +1 -1
  14. package/dist/element-highlighter/element-highlighter.js.map +1 -1
  15. package/dist/frame/frame.js +49 -25
  16. package/dist/frame/frame.js.map +1 -1
  17. package/dist/hover-highlighter/hover-highlighter.compositions.d.ts +2 -0
  18. package/dist/hover-highlighter/hover-highlighter.compositions.js +32 -3
  19. package/dist/hover-highlighter/hover-highlighter.compositions.js.map +1 -1
  20. package/dist/hover-highlighter/use-hover-highlighter.js +7 -2
  21. package/dist/hover-highlighter/use-hover-highlighter.js.map +1 -1
  22. package/dist/ignore-highlighter.d.ts +12 -3
  23. package/dist/ignore-highlighter.js +11 -4
  24. package/dist/ignore-highlighter.js.map +1 -1
  25. package/dist/index.d.ts +1 -1
  26. package/dist/index.js +3 -2
  27. package/dist/index.js.map +1 -1
  28. package/dist/label/component-strip.compositions.d.ts +2 -0
  29. package/dist/label/component-strip.compositions.js +17 -0
  30. package/dist/label/component-strip.compositions.js.map +1 -0
  31. package/dist/label/component-strip.js +7 -5
  32. package/dist/label/component-strip.js.map +1 -1
  33. package/dist/label/component-strip.module.scss +19 -0
  34. package/dist/label/label-container.js +11 -5
  35. package/dist/label/label-container.js.map +1 -1
  36. package/dist/label/label.module.scss +2 -0
  37. package/dist/mock-component.d.ts +4 -2
  38. package/dist/mock-component.js +18 -4
  39. package/dist/mock-component.js.map +1 -1
  40. package/dist/tsconfig.json +32 -0
  41. package/element-highlighter/element-highlighter.compositions.tsx +52 -4
  42. package/element-highlighter/element-highlighter.tsx +2 -2
  43. package/frame/frame.tsx +52 -24
  44. package/hover-highlighter/hover-highlighter.compositions.tsx +45 -3
  45. package/hover-highlighter/use-hover-highlighter.tsx +9 -3
  46. package/ignore-highlighter.tsx +11 -3
  47. package/index.ts +2 -1
  48. package/label/component-strip.compositions.tsx +13 -0
  49. package/label/component-strip.module.scss +19 -0
  50. package/label/component-strip.tsx +7 -5
  51. package/label/label-container.tsx +11 -5
  52. package/label/label.module.scss +2 -0
  53. package/mock-component.tsx +19 -5
  54. package/package-tar/teambit-react.ui.component-highlighter-0.2.0.tgz +0 -0
  55. package/package.json +18 -55
  56. package/preview-1657547073447.js +8 -0
  57. package/tsconfig.json +8 -2
  58. package/package-tar/teambit-react.ui.component-highlighter-0.0.513.tgz +0 -0
  59. package/preview-1649042627943.js +0 -2
@@ -1,14 +1,22 @@
1
1
  import React from 'react';
2
2
 
3
+ /** name of ignore attribute */
3
4
  export const excludeHighlighterAttrName = 'data-ignore-component-highlight';
4
5
 
5
- /** select elements matching the exclusion pattern */
6
+ /** selector for elements with the ignore attribute */
6
7
  export const excludeHighlighterSelector = `[${excludeHighlighterAttrName}]`;
7
8
 
8
- /** elements with these attributes will be ignored by the automatic highlighter */
9
+ /** highlighter will exclude elements with this attribute */
9
10
  export const excludeHighlighterAtt = { [excludeHighlighterAttrName]: true };
10
11
 
11
- /** elements under this element will be ignored by the automatic highlighter */
12
+ /** children of this element will be excluded by the automatic highlighter */
12
13
  export function ExcludeHighlighter(props: React.HTMLAttributes<HTMLDivElement>) {
13
14
  return <div {...props} {...excludeHighlighterAtt} />;
14
15
  }
16
+
17
+ /** name of skip attribute */
18
+ export const skipHighlighterAttrName = 'data-skip-component-highlight';
19
+ /** highlighter will skip (ignore) elements with these attributes */
20
+ export const skipHighlighterAttr = { [skipHighlighterAttrName]: true };
21
+ /** selector for elements with the skip attribute */
22
+ export const skipHighlighterSelector = `[${skipHighlighterAttrName}]`;
package/index.ts CHANGED
@@ -13,8 +13,9 @@ export type { ElementHighlighterProps, Placement, HighlightClasses } from './ele
13
13
  export {
14
14
  ExcludeHighlighter,
15
15
  excludeHighlighterAtt,
16
- excludeHighlighterSelector,
17
16
  excludeHighlighterAttrName,
17
+ skipHighlighterAttr,
18
+ skipHighlighterAttrName,
18
19
  } from './ignore-highlighter';
19
20
 
20
21
  export type { MatchRule } from './rule-matcher';
@@ -0,0 +1,13 @@
1
+ import React from 'react';
2
+ import { ComponentStrip } from './component-strip';
3
+ import { MockButton, MockSnap } from '../mock-component';
4
+
5
+ export const ComponentStripPreview = () => {
6
+ return (
7
+ <div style={{ fontFamily: 'sans-serif', padding: 8 }}>
8
+ <ComponentStrip component={MockSnap} />
9
+ <br />
10
+ <ComponentStrip component={MockButton} />
11
+ </div>
12
+ );
13
+ };
@@ -7,6 +7,7 @@ $gap: 0.125em;
7
7
 
8
8
  border-radius: $borderRadius;
9
9
  box-shadow: var(--bit-highlighter-shadow);
10
+ white-space: nowrap;
10
11
 
11
12
  > * {
12
13
  padding: 0 0.5em;
@@ -47,3 +48,21 @@ $gap: 0.125em;
47
48
  }
48
49
  }
49
50
  }
51
+
52
+ .nameBlock {
53
+ display: flex;
54
+
55
+ .version {
56
+ // leave room for 9 digits + 3 "."
57
+ max-width: 13ch;
58
+ overflow: hidden;
59
+ text-overflow: ellipsis;
60
+ white-space: nowrap;
61
+
62
+ transition: max-width 480ms;
63
+
64
+ &:hover {
65
+ max-width: 61ch;
66
+ }
67
+ }
68
+ }
@@ -27,9 +27,11 @@ export const ComponentStrip = forwardRef(function ComponentStrip(
27
27
  {!parsedId && <LabelBlock link={homepage}>{id}</LabelBlock>}
28
28
  {parsedId && <LabelBlock link={ScopeUrl.toUrl(parsedId.scope)}>{parsedId.scope}</LabelBlock>}
29
29
  {parsedId && (
30
- <LabelBlock link={componentLink}>
31
- {parsedId.fullName}
32
- {parsedId.version && parsedId.version !== 'latest' && `@${parsedId.version}`}
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
+ )}
33
35
  </LabelBlock>
34
36
  )}
35
37
  {children}
@@ -37,10 +39,10 @@ export const ComponentStrip = forwardRef(function ComponentStrip(
37
39
  );
38
40
  });
39
41
 
40
- function LabelBlock({ link, children }: { link?: string; children: ReactNode }) {
42
+ function LabelBlock({ link, children, className }: { link?: string; children: ReactNode; className?: string }) {
41
43
  const Comp = link ? NativeLink : 'span';
42
44
  return (
43
- <Comp href={link} external={!!link}>
45
+ <Comp href={link} external={!!link} className={className}>
44
46
  {children}
45
47
  </Comp>
46
48
  );
@@ -7,10 +7,13 @@ import {
7
7
  flip as flipMiddleware,
8
8
  shift,
9
9
  autoUpdate,
10
+ hide,
10
11
  } from '@floating-ui/react-dom';
11
12
  import type { Placement } from '@floating-ui/react-dom';
12
13
  import styles from './label.module.scss';
13
14
 
15
+ const HAS_RESIZE_OBSERVER = typeof window !== 'undefined' && !!window.ResizeObserver;
16
+
14
17
  export interface LabelContainerProps extends React.HTMLAttributes<HTMLDivElement> {
15
18
  targetRef: RefObject<HTMLElement | null>;
16
19
  offset?: [number, number];
@@ -32,12 +35,14 @@ export function LabelContainer({
32
35
  style,
33
36
  ...rest
34
37
  }: LabelContainerProps) {
35
- const { x, y, strategy, floating, reference, refs, update } = useFloating({
38
+ const { x, y, strategy, floating, reference, refs, update, middlewareData } = useFloating({
36
39
  placement,
37
40
  middleware: compact([
38
41
  offset && offsetMiddleware({ mainAxis: offset[0], crossAxis: offset[1] }),
39
42
  flip && flipMiddleware(),
40
- shift({ rootBoundary: 'viewport' }),
43
+ // enabling 'shift' for 'crossAxis' will make floating-ui push the label _inside_, when it has nowhere to go
44
+ shift({ rootBoundary: 'document', mainAxis: true, crossAxis: true }),
45
+ hide({ strategy: 'referenceHidden' }),
41
46
  ]),
42
47
  });
43
48
 
@@ -48,19 +53,20 @@ export function LabelContainer({
48
53
  // automatically update on scroll, resize, etc.
49
54
  // `watchMotion` will trigger continuous updates using animation frame
50
55
  useEffect(() => {
51
- if (!refs.reference.current || !refs.floating.current) return () => {};
56
+ if (!refs.reference.current || !refs.floating.current || !HAS_RESIZE_OBSERVER) return () => {};
52
57
 
53
58
  return autoUpdate(refs.reference.current, refs.floating.current, update, { animationFrame: !!watchMotion });
54
59
  }, [refs.reference.current, refs.floating.current, update, watchMotion]);
55
60
 
56
- const isReady = x !== null;
61
+ const isReady = !middlewareData.hide?.referenceHidden;
57
62
 
58
63
  return (
59
64
  <div
60
65
  {...rest}
61
66
  ref={floating}
62
67
  className={classnames(className, !isReady && styles.hidden)}
63
- style={{ ...style, position: strategy, top: y ?? '', left: x ?? '' }}
68
+ // starting at pos [0,0] will ensure the label doesn't increase the document size.
69
+ style={{ ...style, position: strategy, top: y ?? 0, left: x ?? 0 }}
64
70
  />
65
71
  );
66
72
  }
@@ -24,6 +24,8 @@
24
24
  }
25
25
 
26
26
  .hidden {
27
+ // label size is needed for position calculations,
28
+ // so it can't be removed by `display: none`
27
29
  visibility: hidden;
28
30
  pointer-events: none;
29
31
  user-select: none;
@@ -1,9 +1,23 @@
1
- import React, { PropsWithChildren } from 'react';
2
- import { componentMetaField } from '@teambit/react.ui.highlighter.component-metadata.bit-component-meta';
1
+ import React, { ButtonHTMLAttributes, HTMLAttributes } from 'react';
2
+ import { componentMetaField, ComponentMeta } from '@teambit/react.ui.highlighter.component-metadata.bit-component-meta';
3
3
 
4
- export function MockTarget({ children, ...rest }: PropsWithChildren<{}>) {
5
- return <div {...rest}>mocked {children}</div>;
4
+ export function MockTarget({ children, ...rest }: HTMLAttributes<HTMLDivElement>) {
5
+ return <div {...rest}>{children}</div>;
6
6
  }
7
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] = {
8
15
  id: 'teambit.design/ui/icon-button@1.6.2',
9
- };
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 CHANGED
@@ -1,83 +1,50 @@
1
1
  {
2
2
  "name": "@teambit/react.ui.component-highlighter",
3
- "version": "0.0.513",
3
+ "version": "0.2.0",
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.513"
9
+ "version": "0.2.0"
10
10
  },
11
11
  "dependencies": {
12
- "get-xpath": "3.0.1",
13
- "classnames": "2.2.6",
14
- "@floating-ui/react-dom": "0.6.0",
15
- "use-debounce": "6.0.1",
16
- "uuid": "3.4.0",
17
- "lodash.compact": "3.0.1",
18
- "url-join": "4.0.1",
12
+ "get-xpath": "^3.0.1",
13
+ "classnames": "^2.3.1",
14
+ "uuid": "^3.4.0",
15
+ "use-debounce": "^8.0.1",
16
+ "@floating-ui/react-dom": "0.7.2",
17
+ "lodash.compact": "^3.0.1",
18
+ "url-join": "^4.0.1",
19
19
  "@tippyjs/react": "4.2.0",
20
20
  "core-js": "^3.0.0",
21
- "@teambit/base-ui.routing.native-link": "1.0.0",
22
21
  "@teambit/react.ui.highlighter.component-metadata.bit-component-meta": "0.0.21",
23
22
  "@teambit/component-id": "0.0.402",
24
- "@teambit/react.modules.dom-to-react": "0.0.489",
25
23
  "@teambit/ui-foundation.ui.constants.z-indexes": "0.0.487",
26
- "@teambit/react.ui.hover-selector": "0.0.165",
27
- "@teambit/component.modules.component-url": "0.0.124"
24
+ "@teambit/base-ui.routing.native-link": "1.0.0",
25
+ "@teambit/component.modules.component-url": "0.0.124",
26
+ "@teambit/react.modules.dom-to-react": "0.2.0",
27
+ "@teambit/react.ui.hover-selector": "0.2.0"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@types/react": "^17.0.8",
31
- "@testing-library/react": "11.2.6",
32
- "@types/classnames": "2.2.11",
33
- "@types/react-dom": "^17.0.5",
31
+ "@testing-library/react": "^12.1.5",
34
32
  "@types/uuid": "3.4.9",
33
+ "@types/react-dom": "^17.0.5",
35
34
  "@types/lodash.compact": "3.0.6",
36
- "@types/url-join": "4.0.0",
35
+ "@types/url-join": "^4.0.0",
37
36
  "@types/mocha": "9.1.0",
38
37
  "@types/testing-library__jest-dom": "5.9.5",
39
38
  "@babel/runtime": "7.12.18",
40
39
  "@types/jest": "^26.0.0",
41
- "@types/node": "12.20.4",
42
- "@teambit/design.ui.icon-button": "1.0.16"
40
+ "@types/node": "12.20.4"
43
41
  },
44
42
  "peerDependencies": {
45
43
  "react-dom": "^16.8.0 || ^17.0.0",
46
44
  "react": "^16.8.0 || ^17.0.0"
47
45
  },
48
46
  "license": "Apache-2.0",
49
- "bit": {
50
- "bindingPrefix": "@teambit",
51
- "env": {},
52
- "overrides": {
53
- "dependencies": {
54
- "@teambit/legacy": "-",
55
- "core-js": "^3.0.0",
56
- "react-dom": "-",
57
- "react": "-"
58
- },
59
- "devDependencies": {
60
- "@teambit/legacy": "-",
61
- "@types/mocha": "9.1.0",
62
- "@types/testing-library__jest-dom": "5.9.5",
63
- "@babel/runtime": "7.12.18",
64
- "@types/jest": "^26.0.0",
65
- "@types/react-dom": "^17.0.5",
66
- "@types/react": "^17.0.8",
67
- "@types/node": "12.20.4",
68
- "react-dom": "-",
69
- "react": "-"
70
- },
71
- "peerDependencies": {
72
- "react-dom": "^16.8.0 || ^17.0.0",
73
- "react": "^16.8.0 || ^17.0.0"
74
- }
75
- }
76
- },
77
47
  "private": false,
78
- "engines": {
79
- "node": ">=12.22.0"
80
- },
81
48
  "repository": {
82
49
  "type": "git",
83
50
  "url": "https://github.com/teambit/bit"
@@ -88,10 +55,6 @@
88
55
  "collaboration",
89
56
  "web",
90
57
  "react",
91
- "react-components",
92
- "angular",
93
- "angular-components",
94
- "vue",
95
- "vue-components"
58
+ "react-components"
96
59
  ]
97
60
  }
@@ -0,0 +1,8 @@
1
+ import * as compositions_0 from '/Users/kutner/Library/Caches/Bit/capsules/4d3a484af3d3d771b8ef753524d1f10bb4be2fdd/teambit.react_ui_component-highlighter@0.2.0/dist/children-highlighter/children-highlighter.composition.js';
2
+ import * as compositions_1 from '/Users/kutner/Library/Caches/Bit/capsules/4d3a484af3d3d771b8ef753524d1f10bb4be2fdd/teambit.react_ui_component-highlighter@0.2.0/dist/element-highlighter/element-highlighter.compositions.js';
3
+ import * as compositions_2 from '/Users/kutner/Library/Caches/Bit/capsules/4d3a484af3d3d771b8ef753524d1f10bb4be2fdd/teambit.react_ui_component-highlighter@0.2.0/dist/hover-highlighter/hover-highlighter.compositions.js';
4
+ import * as compositions_3 from '/Users/kutner/Library/Caches/Bit/capsules/4d3a484af3d3d771b8ef753524d1f10bb4be2fdd/teambit.react_ui_component-highlighter@0.2.0/dist/label/component-strip.compositions.js';
5
+ import * as overview_0 from '/Users/kutner/Library/Caches/Bit/capsules/4d3a484af3d3d771b8ef753524d1f10bb4be2fdd/teambit.react_ui_component-highlighter@0.2.0/dist/component-highlighter.docs.md';
6
+
7
+ export const compositions = [compositions_0, compositions_1, compositions_2, compositions_3];
8
+ export const overview = [overview_0];
package/tsconfig.json CHANGED
@@ -7,13 +7,14 @@
7
7
  "DOM.Iterable"
8
8
  ],
9
9
  "target": "es2015",
10
- "module": "commonjs",
10
+ "module": "CommonJS",
11
11
  "jsx": "react",
12
12
  "allowJs": true,
13
13
  "composite": true,
14
14
  "declaration": true,
15
15
  "sourceMap": true,
16
16
  "skipLibCheck": true,
17
+ "experimentalDecorators": true,
17
18
  "outDir": "dist",
18
19
  "moduleResolution": "node",
19
20
  "esModuleInterop": true,
@@ -21,6 +22,11 @@
21
22
  "resolveJsonModule": true
22
23
  },
23
24
  "exclude": [
24
- "dist"
25
+ "dist",
26
+ "package.json"
27
+ ],
28
+ "include": [
29
+ "**/*",
30
+ "**/*.json"
25
31
  ]
26
32
  }
@@ -1,2 +0,0 @@
1
- export const compositions = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.react_ui_component-highlighter@0.0.513/dist/children-highlighter/children-highlighter.composition.js'), require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.react_ui_component-highlighter@0.0.513/dist/element-highlighter/element-highlighter.compositions.js'), require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.react_ui_component-highlighter@0.0.513/dist/hover-highlighter/hover-highlighter.compositions.js')]
2
- export const overview = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.react_ui_component-highlighter@0.0.513/dist/component-highlighter.docs.md')]