@teambit/docs 0.0.568 → 0.0.569

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.
@@ -0,0 +1,20 @@
1
+ import { DocProp } from './doc-prop';
2
+
3
+ export class DocPropList {
4
+ constructor(readonly docProps: DocProp[]) {}
5
+
6
+ get(name: string) {
7
+ return this.docProps.find((docProp) => docProp.name === name);
8
+ }
9
+
10
+ static from(object: any): DocPropList {
11
+ const props = Object.keys(object)
12
+ .map((key) => {
13
+ if (!object[key]) return undefined;
14
+ return new DocProp(key, object[key]);
15
+ })
16
+ .filter((prop) => !!prop) as DocProp[];
17
+
18
+ return new DocPropList(props);
19
+ }
20
+ }
@@ -0,0 +1,19 @@
1
+ import type { Serializable } from '@teambit/toolbox.types.serializable';
2
+
3
+ export class DocProp {
4
+ constructor(
5
+ /**
6
+ * name of the doc property.
7
+ */
8
+ readonly name: string,
9
+
10
+ /**
11
+ * value of the doc property.
12
+ */
13
+ readonly value: Serializable
14
+ ) {}
15
+
16
+ getAs<T>() {
17
+ return this.value as T;
18
+ }
19
+ }
package/doc/doc.ts ADDED
@@ -0,0 +1,42 @@
1
+ import type { SerializableMap } from '@teambit/toolbox.types.serializable';
2
+ import { DocPropList } from './doc-prop-list';
3
+
4
+ export class Doc {
5
+ constructor(readonly filePath: string, readonly props: DocPropList) {}
6
+
7
+ toObject() {
8
+ return {
9
+ filePath: this.filePath,
10
+ props: this.props.docProps,
11
+ };
12
+ }
13
+
14
+ /**
15
+ * shorthand for getting the component description.
16
+ */
17
+ get description(): string {
18
+ const value = this.props.get('description')?.value;
19
+ if (!value) return '';
20
+ return value as string;
21
+ }
22
+
23
+ /**
24
+ * shorthand for getting the component labels.
25
+ */
26
+ get labels() {
27
+ const value = this.props.get('labels')?.value;
28
+ if (!value) return [];
29
+ return value as string[];
30
+ }
31
+
32
+ /**
33
+ * shorthand for getting the component labels.
34
+ */
35
+ get displayName() {
36
+ return this.props.get('displayName');
37
+ }
38
+
39
+ static from(path: string, propObject: SerializableMap) {
40
+ return new Doc(path, DocPropList.from(propObject));
41
+ }
42
+ }
package/doc/index.ts ADDED
@@ -0,0 +1,3 @@
1
+ export { Doc } from './doc';
2
+ export { DocProp } from './doc-prop';
3
+ export { DocPropList } from './doc-prop-list';
package/docs-store.tsx ADDED
@@ -0,0 +1,9 @@
1
+ import React from 'react';
2
+ import ReactDOM from 'react-dom';
3
+
4
+ // let docs = [];
5
+
6
+ export function addDocs(docs: any[]) {
7
+ const Doc = docs[0];
8
+ ReactDOM.render(<Doc />, document.getElementById('root'));
9
+ }
package/docs.data.tsx ADDED
@@ -0,0 +1,13 @@
1
+ export const docsMock = {
2
+ title: 'Radio',
3
+ subTitle:
4
+ 'Radio Buttons are graphical interface elements that allow user to choose only one of a predefined set of mutually exclusive options.',
5
+ labels: ['chart', 'graph', 'ui-components', 'react'],
6
+ installMethods: [
7
+ { title: 'install package', content: '@google.material-ui/radio' },
8
+ {
9
+ title: 'Import from CDN',
10
+ content: 'https://esm.bit.dev/@google/material-ui/radio/',
11
+ },
12
+ ],
13
+ };
@@ -0,0 +1,48 @@
1
+ import React, { ReactNode } from 'react';
2
+ import { PreviewAspect, RenderingContext, PreviewPreview, PreviewRuntime, PreviewModule } from '@teambit/preview';
3
+
4
+ import { DocsAspect } from './docs.aspect';
5
+
6
+ export class DocsPreview {
7
+ constructor(
8
+ /**
9
+ * preview extension.
10
+ */
11
+ private preview: PreviewPreview
12
+ ) {}
13
+
14
+ render = (componentId: string, modules: PreviewModule, [compositions]: [any], context: RenderingContext) => {
15
+ const docsModule = this.selectPreviewModel(componentId, modules);
16
+
17
+ modules.mainModule.default(NoopProvider, componentId, docsModule, compositions, context);
18
+ };
19
+
20
+ selectPreviewModel(componentId: string, modules: PreviewModule) {
21
+ const relevant = modules.componentMap[componentId];
22
+ if (!relevant) return undefined;
23
+
24
+ // only one doc file is supported.
25
+ return relevant[0];
26
+ }
27
+
28
+ static runtime = PreviewRuntime;
29
+ static dependencies = [PreviewAspect];
30
+
31
+ static async provider([preview]: [PreviewPreview]) {
32
+ const docsPreview = new DocsPreview(preview);
33
+ preview.registerPreview({
34
+ name: 'overview',
35
+ render: docsPreview.render.bind(docsPreview),
36
+ selectPreviewModel: docsPreview.selectPreviewModel.bind(docsPreview),
37
+ include: ['compositions'],
38
+ });
39
+
40
+ return docsPreview;
41
+ }
42
+ }
43
+
44
+ DocsAspect.addRuntime(DocsPreview);
45
+
46
+ function NoopProvider({ children }: { children: ReactNode }) {
47
+ return <>{children}</>;
48
+ }
@@ -0,0 +1,25 @@
1
+ import { ComponentAspect, ComponentUI } from '@teambit/component';
2
+ import { UIRuntime } from '@teambit/ui';
3
+
4
+ import { DocsAspect } from './docs.aspect';
5
+ import { OverviewSection } from './overview.section';
6
+
7
+ export class DocsUI {
8
+ static dependencies = [ComponentAspect];
9
+
10
+ static runtime = UIRuntime;
11
+
12
+ static async provider([component]: [ComponentUI]) {
13
+ const docs = new DocsUI();
14
+ const section = new OverviewSection(docs);
15
+
16
+ component.registerRoute(section.route);
17
+ component.registerNavigation(section.navigationLink, section.order);
18
+
19
+ return docs;
20
+ }
21
+ }
22
+
23
+ export default DocsUI;
24
+
25
+ DocsAspect.addRuntime(DocsUI);
@@ -0,0 +1,14 @@
1
+ /* eslint-disable max-classes-per-file */
2
+ import { BitBaseEvent } from '@teambit/pubsub';
3
+
4
+ class ClickInsideAnIframeEventData {
5
+ constructor(private clickEvent: any) {}
6
+ }
7
+
8
+ export class ClickInsideAnIframeEvent extends BitBaseEvent<ClickInsideAnIframeEventData> {
9
+ static readonly TYPE = 'click-inside-an-iframe';
10
+
11
+ constructor(readonly timestamp = Date.now(), readonly clickEvent) {
12
+ super(ClickInsideAnIframeEvent.TYPE, '0.0.1', timestamp, new ClickInsideAnIframeEventData(clickEvent));
13
+ }
14
+ }
@@ -0,0 +1 @@
1
+ export * from './click-inside-an-iframe';
@@ -0,0 +1,5 @@
1
+ export class DocReadError extends Error {
2
+ constructor(filePath: string, error: Error) {
3
+ super(`failed reading doc in file path: ${filePath} with error: ${error}`);
4
+ }
5
+ }
@@ -0,0 +1,6 @@
1
+ export class FileExtensionNotSupported extends Error {
2
+ constructor(filePath: string, extension: string) {
3
+ super(`failed reading doc file: ${filePath} as file extension ${extension} is not supported
4
+ by any of registered component doc readers. To register a doc reader please use the 'registerDocReader' API of the teambit.docs/docs.`);
5
+ }
6
+ }
@@ -0,0 +1,2 @@
1
+ export { FileExtensionNotSupported } from './file-extension-not-supported';
2
+ export { DocReadError } from './doc-read-error';
@@ -0,0 +1 @@
1
+ export { Overview } from './overview';
@@ -0,0 +1,23 @@
1
+ import React, { useContext } from 'react';
2
+ import { ComponentContext } from '@teambit/component';
3
+ import { ComponentPreview } from '@teambit/preview.ui.component-preview';
4
+ import { StatusMessageCard } from '@teambit/design.ui.surfaces.status-message-card';
5
+
6
+ export function Overview() {
7
+ const component = useContext(ComponentContext);
8
+ if (component?.buildStatus === 'pending' && component?.host === 'teambit.scope/scope')
9
+ return (
10
+ <StatusMessageCard style={{ margin: 'auto' }} status="PROCESSING" title="component preview pending">
11
+ this might take some time
12
+ </StatusMessageCard>
13
+ );
14
+ if (component?.buildStatus === 'failed' && component?.host === 'teambit.scope/scope')
15
+ return (
16
+ <StatusMessageCard
17
+ style={{ margin: 'auto' }}
18
+ status="FAILURE"
19
+ title="failed to get component preview "
20
+ ></StatusMessageCard>
21
+ );
22
+ return <ComponentPreview component={component} style={{ width: '100%', height: '100%' }} previewName="overview" />;
23
+ }
@@ -0,0 +1,28 @@
1
+ import { Section } from '@teambit/component';
2
+ import React from 'react';
3
+
4
+ import { DocsUI } from './docs.ui.runtime';
5
+ import { Overview } from './overview';
6
+
7
+ export class OverviewSection implements Section {
8
+ constructor(
9
+ /**
10
+ * docs ui extension.
11
+ */
12
+ private docs: DocsUI
13
+ ) {}
14
+
15
+ navigationLink = {
16
+ href: '',
17
+ exact: true,
18
+ children: 'Overview',
19
+ };
20
+
21
+ route = {
22
+ path: '',
23
+ exact: true,
24
+ children: <Overview />,
25
+ };
26
+
27
+ order = 10;
28
+ }
package/package.json CHANGED
@@ -1,33 +1,33 @@
1
1
  {
2
2
  "name": "@teambit/docs",
3
- "version": "0.0.568",
3
+ "version": "0.0.569",
4
4
  "homepage": "https://bit.dev/teambit/docs/docs",
5
5
  "main": "dist/index.js",
6
6
  "componentId": {
7
7
  "scope": "teambit.docs",
8
8
  "name": "docs",
9
- "version": "0.0.568"
9
+ "version": "0.0.569"
10
10
  },
11
11
  "dependencies": {
12
12
  "@teambit/harmony": "0.2.11",
13
13
  "graphql-tag": "2.12.1",
14
14
  "@babel/runtime": "7.12.18",
15
15
  "core-js": "^3.0.0",
16
- "@teambit/compiler": "0.0.568",
17
- "@teambit/component": "0.0.568",
18
- "@teambit/pkg": "0.0.568",
19
- "@teambit/workspace": "0.0.568",
20
- "@teambit/cli": "0.0.394",
21
- "@teambit/dev-files": "0.0.568",
22
- "@teambit/envs": "0.0.568",
23
- "@teambit/graphql": "0.0.568",
24
- "@teambit/logger": "0.0.480",
25
- "@teambit/preview": "0.0.568",
26
- "@teambit/ui": "0.0.568",
27
- "@teambit/toolbox.types.serializable": "0.0.468",
28
- "@teambit/pubsub": "0.0.568",
16
+ "@teambit/compiler": "0.0.569",
17
+ "@teambit/component": "0.0.569",
18
+ "@teambit/pkg": "0.0.569",
19
+ "@teambit/workspace": "0.0.569",
20
+ "@teambit/cli": "0.0.395",
21
+ "@teambit/dev-files": "0.0.569",
22
+ "@teambit/envs": "0.0.569",
23
+ "@teambit/graphql": "0.0.569",
24
+ "@teambit/logger": "0.0.481",
25
+ "@teambit/preview": "0.0.569",
26
+ "@teambit/ui": "0.0.569",
27
+ "@teambit/toolbox.types.serializable": "0.0.469",
28
+ "@teambit/pubsub": "0.0.569",
29
29
  "@teambit/design.ui.surfaces.status-message-card": "0.0.6",
30
- "@teambit/preview.ui.component-preview": "0.0.471"
30
+ "@teambit/preview.ui.component-preview": "0.0.472"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@types/react-dom": "^17.0.5",
@@ -38,7 +38,7 @@
38
38
  "@types/node": "12.20.4"
39
39
  },
40
40
  "peerDependencies": {
41
- "@teambit/legacy": "1.0.180",
41
+ "@teambit/legacy": "1.0.181",
42
42
  "react-dom": "^16.8.0 || ^17.0.0",
43
43
  "react": "^16.8.0 || ^17.0.0"
44
44
  },
@@ -66,27 +66,12 @@
66
66
  "react": "-"
67
67
  },
68
68
  "peerDependencies": {
69
- "@teambit/legacy": "1.0.180",
69
+ "@teambit/legacy": "1.0.181",
70
70
  "react-dom": "^16.8.0 || ^17.0.0",
71
71
  "react": "^16.8.0 || ^17.0.0"
72
72
  }
73
73
  }
74
74
  },
75
- "files": [
76
- "dist",
77
- "!dist/tsconfig.tsbuildinfo",
78
- "**/*.md",
79
- "**/*.mdx",
80
- "**/*.js",
81
- "**/*.json",
82
- "**/*.sass",
83
- "**/*.scss",
84
- "**/*.less",
85
- "**/*.css",
86
- "**/*.css",
87
- "**/*.jpeg",
88
- "**/*.gif"
89
- ],
90
75
  "private": false,
91
76
  "engines": {
92
77
  "node": ">=12.22.0"
@@ -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
+ }