@teambit/docs 0.0.553 → 0.0.557

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.
@@ -1,7 +1,21 @@
1
1
  import type { Serializable } from '@teambit/toolbox.types.serializable';
2
2
  export declare class DocProp {
3
+ /**
4
+ * name of the doc property.
5
+ */
3
6
  readonly name: string;
7
+ /**
8
+ * value of the doc property.
9
+ */
4
10
  readonly value: Serializable;
5
- constructor(name: string, value: Serializable);
11
+ constructor(
12
+ /**
13
+ * name of the doc property.
14
+ */
15
+ name: string,
16
+ /**
17
+ * value of the doc property.
18
+ */
19
+ value: Serializable);
6
20
  getAs<T>(): T;
7
21
  }
package/dist/doc/doc.d.ts CHANGED
@@ -8,8 +8,17 @@ export declare class Doc {
8
8
  filePath: string;
9
9
  props: import("./doc-prop").DocProp[];
10
10
  };
11
+ /**
12
+ * shorthand for getting the component description.
13
+ */
11
14
  get description(): string;
15
+ /**
16
+ * shorthand for getting the component labels.
17
+ */
12
18
  get labels(): string[];
19
+ /**
20
+ * shorthand for getting the component labels.
21
+ */
13
22
  get displayName(): import("./doc-prop").DocProp | undefined;
14
23
  static from(path: string, propObject: SerializableMap): Doc;
15
24
  }
@@ -1,6 +1,16 @@
1
1
  export declare class DocModule {
2
2
  readonly path: string;
3
+ /**
4
+ * original doc module.
5
+ */
3
6
  readonly module: any;
4
- constructor(path: string, module: any);
7
+ constructor(path: string,
8
+ /**
9
+ * original doc module.
10
+ */
11
+ module: any);
12
+ /**
13
+ * get the abstract.
14
+ */
5
15
  get abstract(): any;
6
16
  }
@@ -2,6 +2,13 @@
2
2
  import type { Component } from '@teambit/component';
3
3
  import { Doc } from './doc';
4
4
  export interface DocReader {
5
+ /**
6
+ * read a component doc.
7
+ * @TODO refactor to virtual-file component after @david completes.
8
+ */
5
9
  read(path: string, contents: Buffer, component: Component): Promise<Doc>;
10
+ /**
11
+ * determine which file formats are supported by the doc reader.
12
+ */
6
13
  isFormatSupported(ext: string): boolean;
7
14
  }
package/dist/docs.d.ts CHANGED
@@ -1,6 +1,15 @@
1
1
  import React from 'react';
2
2
  export declare type Docs = {
3
+ /**
4
+ * default is the docs content.
5
+ */
3
6
  default: React.ComponentType;
7
+ /**
8
+ * component abstract.
9
+ */
4
10
  abstract: string;
11
+ /**
12
+ * array of labels.
13
+ */
5
14
  labels: string[];
6
15
  };
@@ -19,10 +19,19 @@ export declare type DocProp = {};
19
19
  export declare type DocPropSlot = SlotRegistry<DocProp>;
20
20
  export declare type DocReaderSlot = SlotRegistry<DocReader>;
21
21
  export declare type DocsConfig = {
22
+ /**
23
+ * glob patterns to identify doc files.
24
+ */
22
25
  patterns: string[];
23
26
  };
27
+ /**
28
+ * the component documentation extension.
29
+ */
24
30
  export declare class DocsMain {
25
31
  private patterns;
32
+ /**
33
+ * envs extension.
34
+ */
26
35
  private preview;
27
36
  private pkg;
28
37
  private compiler;
@@ -31,15 +40,32 @@ export declare class DocsMain {
31
40
  private devFiles;
32
41
  private docPropSlot;
33
42
  private docReaderSlot;
34
- constructor(patterns: string[], preview: PreviewMain, pkg: PkgMain, compiler: CompilerMain, workspace: Workspace, logger: Logger, devFiles: DevFilesMain, docPropSlot: DocPropSlot, docReaderSlot: DocReaderSlot);
43
+ constructor(patterns: string[],
44
+ /**
45
+ * envs extension.
46
+ */
47
+ preview: PreviewMain, pkg: PkgMain, compiler: CompilerMain, workspace: Workspace, logger: Logger, devFiles: DevFilesMain, docPropSlot: DocPropSlot, docReaderSlot: DocReaderSlot);
48
+ /**
49
+ * returns an array of doc file paths for a set of components.
50
+ */
35
51
  getDocsMap(components: Component[]): ComponentMap<AbstractVinyl[]>;
36
52
  getDocsFiles(component: Component): AbstractVinyl[];
53
+ /**
54
+ * compute the description of the component from its source code and docs file.
55
+ */
37
56
  getDescription(component: Component): Promise<string>;
38
57
  getTemplate(context: ExecutionContext): Promise<any>;
39
58
  getDocReader(extension: string): DocReader | undefined;
59
+ /**
60
+ * compute a doc for a component.
61
+ */
40
62
  computeDoc(component: Component): Promise<Doc | null>;
41
63
  getDoc(component: Component): Doc | null;
42
64
  getPatterns(): string[];
65
+ /**
66
+ * register a new doc reader. this allows to support further
67
+ * documentation file formats.
68
+ */
43
69
  registerDocReader(docReader: DocReader): this;
44
70
  static slots: ((registerFn: () => string) => SlotRegistry<DocProp>)[];
45
71
  static runtime: import("@teambit/harmony").RuntimeDefinition;
@@ -4,9 +4,16 @@ import { PreviewDefinition } from '@teambit/preview';
4
4
  import { AbstractVinyl } from '@teambit/legacy/dist/consumer/component/sources';
5
5
  import { DocsMain } from './docs.main.runtime';
6
6
  export declare class DocsPreviewDefinition implements PreviewDefinition {
7
+ /**
8
+ * docs extension.
9
+ */
7
10
  private docs;
8
11
  readonly prefix = "overview";
9
- constructor(docs: DocsMain);
12
+ constructor(
13
+ /**
14
+ * docs extension.
15
+ */
16
+ docs: DocsMain);
10
17
  renderTemplatePath(context: ExecutionContext): Promise<string>;
11
18
  getModuleMap(components: Component[]): Promise<ComponentMap<AbstractVinyl[]>>;
12
19
  }
@@ -1,7 +1,14 @@
1
1
  import { RenderingContext, PreviewPreview, PreviewModule } from '@teambit/preview';
2
2
  export declare class DocsPreview {
3
+ /**
4
+ * preview extension.
5
+ */
3
6
  private preview;
4
- constructor(preview: PreviewPreview);
7
+ constructor(
8
+ /**
9
+ * preview extension.
10
+ */
11
+ preview: PreviewPreview);
5
12
  render: (componentId: string, modules: PreviewModule, [compositions]: [any], context: RenderingContext) => void;
6
13
  selectPreviewModel(componentId: string, modules: PreviewModule): import("@teambit/preview").ModuleFile<any> | undefined;
7
14
  static runtime: import("@teambit/harmony").RuntimeDefinition;
@@ -1,8 +1,15 @@
1
1
  import { Section } from '@teambit/component';
2
2
  import { DocsUI } from './docs.ui.runtime';
3
3
  export declare class OverviewSection implements Section {
4
+ /**
5
+ * docs ui extension.
6
+ */
4
7
  private docs;
5
- constructor(docs: DocsUI);
8
+ constructor(
9
+ /**
10
+ * docs ui extension.
11
+ */
12
+ docs: DocsUI);
6
13
  navigationLink: {
7
14
  href: string;
8
15
  exact: boolean;
package/package.json CHANGED
@@ -1,33 +1,33 @@
1
1
  {
2
2
  "name": "@teambit/docs",
3
- "version": "0.0.553",
3
+ "version": "0.0.557",
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.553"
9
+ "version": "0.0.557"
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.553",
17
- "@teambit/component": "0.0.553",
18
- "@teambit/pkg": "0.0.553",
19
- "@teambit/workspace": "0.0.553",
20
- "@teambit/cli": "0.0.384",
21
- "@teambit/dev-files": "0.0.553",
22
- "@teambit/envs": "0.0.553",
23
- "@teambit/graphql": "0.0.553",
24
- "@teambit/logger": "0.0.469",
25
- "@teambit/preview": "0.0.553",
26
- "@teambit/ui": "0.0.553",
27
- "@teambit/toolbox.types.serializable": "0.0.458",
28
- "@teambit/pubsub": "0.0.553",
16
+ "@teambit/compiler": "0.0.557",
17
+ "@teambit/component": "0.0.557",
18
+ "@teambit/pkg": "0.0.557",
19
+ "@teambit/workspace": "0.0.557",
20
+ "@teambit/cli": "0.0.388",
21
+ "@teambit/dev-files": "0.0.557",
22
+ "@teambit/envs": "0.0.557",
23
+ "@teambit/graphql": "0.0.557",
24
+ "@teambit/logger": "0.0.473",
25
+ "@teambit/preview": "0.0.557",
26
+ "@teambit/ui": "0.0.557",
27
+ "@teambit/toolbox.types.serializable": "0.0.462",
29
28
  "@teambit/design.ui.surfaces.status-message-card": "0.0.6",
30
- "@teambit/preview.ui.component-preview": "0.0.461"
29
+ "@teambit/preview.ui.component-preview": "0.0.465",
30
+ "@teambit/pubsub": "0.0.557"
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.170",
41
+ "@teambit/legacy": "1.0.174",
42
42
  "react-dom": "^16.8.0 || ^17.0.0",
43
43
  "react": "^16.8.0 || ^17.0.0"
44
44
  },
@@ -66,12 +66,20 @@
66
66
  "react": "-"
67
67
  },
68
68
  "peerDependencies": {
69
- "@teambit/legacy": "1.0.170",
69
+ "@teambit/legacy": "1.0.174",
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
+ "README.md",
79
+ "README.mdx",
80
+ "*.js",
81
+ "*.json"
82
+ ],
75
83
  "private": false,
76
84
  "engines": {
77
85
  "node": ">=12.22.0"
package/tsconfig.json CHANGED
@@ -15,9 +15,9 @@
15
15
  "skipLibCheck": true,
16
16
  "moduleResolution": "node",
17
17
  "esModuleInterop": true,
18
- "outDir": "dist",
19
18
  "composite": true,
20
19
  "emitDeclarationOnly": true,
20
+ "outDir": "dist",
21
21
  "experimentalDecorators": true,
22
22
  "emitDecoratorMetadata": true,
23
23
  "allowSyntheticDefaultImports": true,
@@ -25,7 +25,6 @@
25
25
  "strict": true,
26
26
  "noImplicitAny": false,
27
27
  "rootDir": ".",
28
- "removeComments": true,
29
28
  "preserveConstEnums": true,
30
29
  "resolveJsonModule": true
31
30
  },
@@ -1,29 +0,0 @@
1
- import { resolve } from 'path';
2
- import type { PkgMain } from '@teambit/pkg';
3
- import type { Component } from '@teambit/component';
4
- import type { CompilerMain } from '@teambit/compiler';
5
- import type { Workspace } from '@teambit/workspace';
6
- import { DocReader } from './doc-reader';
7
- import { Doc } from './doc';
8
-
9
- export class DefaultDocReader implements DocReader {
10
- constructor(private pkg: PkgMain, private compiler: CompilerMain, private workspace: Workspace) {}
11
-
12
- async read(path: string, contents: Buffer, component: Component) {
13
- const packageName = this.pkg.getPackageName(component);
14
- const distPath = this.compiler.getDistPathBySrcPath(component, path);
15
- // eslint-disable-next-line
16
- const docsModule = require(resolve(`${this.workspace.path}/node_modules/${packageName}/${distPath}`));
17
- return Doc.from(path, {
18
- labels: docsModule.labels || docsModule.default?.labels,
19
- description: docsModule.abstract || docsModule.default?.abstract || docsModule.description,
20
- displayName: docsModule.displayName || docsModule.default?.componentDisplayName,
21
- });
22
- }
23
-
24
- readonly supportedExtensions = ['.ts', '.js', '.jsx', '.tsx'];
25
-
26
- isFormatSupported(format: string) {
27
- return this.supportedExtensions.includes(format);
28
- }
29
- }
@@ -1,20 +0,0 @@
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
- }
package/doc/doc-prop.ts DELETED
@@ -1,19 +0,0 @@
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 DELETED
@@ -1,42 +0,0 @@
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 DELETED
@@ -1,3 +0,0 @@
1
- export { Doc } from './doc';
2
- export { DocProp } from './doc-prop';
3
- export { DocPropList } from './doc-prop-list';
package/doc-module.ts DELETED
@@ -1,17 +0,0 @@
1
- export class DocModule {
2
- constructor(
3
- readonly path: string,
4
-
5
- /**
6
- * original doc module.
7
- */
8
- readonly module: any
9
- ) {}
10
-
11
- /**
12
- * get the abstract.
13
- */
14
- get abstract() {
15
- return this.module.abstract || this.module.default?.abstract;
16
- }
17
- }
package/doc-reader.ts DELETED
@@ -1,15 +0,0 @@
1
- import type { Component } from '@teambit/component';
2
- import { Doc } from './doc';
3
-
4
- export interface DocReader {
5
- /**
6
- * read a component doc.
7
- * @TODO refactor to virtual-file component after @david completes.
8
- */
9
- read(path: string, contents: Buffer, component: Component): Promise<Doc>;
10
-
11
- /**
12
- * determine which file formats are supported by the doc reader.
13
- */
14
- isFormatSupported(ext: string): boolean;
15
- }
package/docs-store.tsx DELETED
@@ -1,9 +0,0 @@
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.aspect.ts DELETED
@@ -1,9 +0,0 @@
1
- import { Aspect } from '@teambit/harmony';
2
-
3
- export const DocsAspect = Aspect.create({
4
- id: 'teambit.docs/docs',
5
- dependencies: [],
6
- defaultConfig: {},
7
- });
8
-
9
- export default DocsAspect;
package/docs.data.tsx DELETED
@@ -1,13 +0,0 @@
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
- };
package/docs.graphql.ts DELETED
@@ -1,26 +0,0 @@
1
- import gql from 'graphql-tag';
2
- import { Component } from '@teambit/component';
3
- import { DocsMain } from './docs.main.runtime';
4
-
5
- export function docsSchema(docs: DocsMain) {
6
- return {
7
- typeDefs: gql`
8
- extend type Component {
9
- description: String
10
- labels: [String]
11
- }
12
- `,
13
- resolvers: {
14
- Component: {
15
- description: (component: Component) => {
16
- return docs.getDescription(component);
17
- },
18
-
19
- labels: (component: Component) => {
20
- const doc = docs.getDoc(component);
21
- return doc?.labels || [];
22
- },
23
- },
24
- },
25
- };
26
- }
@@ -1,215 +0,0 @@
1
- import { Slot, SlotRegistry } from '@teambit/harmony';
2
- import { MainRuntime } from '@teambit/cli';
3
- import { LoggerAspect, LoggerMain, Logger } from '@teambit/logger';
4
- import { CompilerAspect, CompilerMain } from '@teambit/compiler';
5
- import ComponentAspect, { Component, ComponentMap } from '@teambit/component';
6
- import { PkgAspect, PkgMain } from '@teambit/pkg';
7
- import { ExecutionContext } from '@teambit/envs';
8
- import { GraphqlAspect, GraphqlMain } from '@teambit/graphql';
9
- import { PreviewAspect, PreviewMain } from '@teambit/preview';
10
- import DevFilesAspect, { DevFilesMain } from '@teambit/dev-files';
11
- import { AbstractVinyl } from '@teambit/legacy/dist/consumer/component/sources';
12
- import ConsumerComponent from '@teambit/legacy/dist/consumer/component';
13
- import { Workspace, WorkspaceAspect } from '@teambit/workspace';
14
- import { DocsAspect } from './docs.aspect';
15
- import { DocsPreviewDefinition } from './docs.preview-definition';
16
- import { docsSchema } from './docs.graphql';
17
- import { DocReader } from './doc-reader';
18
- import { DefaultDocReader } from './default-doc-reader';
19
- import { FileExtensionNotSupported } from './exceptions';
20
- import { Doc, DocPropList } from './doc';
21
-
22
- export type ComponentDocs = {
23
- files: string[];
24
- component: Component;
25
- };
26
-
27
- export type DocProp = {};
28
-
29
- export type DocPropSlot = SlotRegistry<DocProp>;
30
-
31
- export type DocReaderSlot = SlotRegistry<DocReader>;
32
-
33
- export type DocsConfig = {
34
- /**
35
- * glob patterns to identify doc files.
36
- */
37
- patterns: string[];
38
- };
39
-
40
- /**
41
- * the component documentation extension.
42
- */
43
- export class DocsMain {
44
- constructor(
45
- private patterns: string[],
46
- /**
47
- * envs extension.
48
- */
49
- private preview: PreviewMain,
50
-
51
- private pkg: PkgMain,
52
-
53
- private compiler: CompilerMain,
54
-
55
- private workspace: Workspace,
56
-
57
- private logger: Logger,
58
-
59
- private devFiles: DevFilesMain,
60
-
61
- private docPropSlot: DocPropSlot,
62
-
63
- private docReaderSlot: DocReaderSlot
64
- ) {}
65
-
66
- /**
67
- * returns an array of doc file paths for a set of components.
68
- */
69
- getDocsMap(components: Component[]): ComponentMap<AbstractVinyl[]> {
70
- return ComponentMap.as<AbstractVinyl[]>(components, (component) => {
71
- return this.getDocsFiles(component);
72
- });
73
- }
74
-
75
- getDocsFiles(component: Component): AbstractVinyl[] {
76
- const devFiles = this.devFiles.computeDevFiles(component);
77
- const docFiles = devFiles.get(DocsAspect.id);
78
- return component.state.filesystem.files.filter((file) => docFiles.includes(file.relative));
79
- }
80
-
81
- /**
82
- * compute the description of the component from its source code and docs file.
83
- */
84
- async getDescription(component: Component): Promise<string> {
85
- const componentDoc = this.getDoc(component);
86
- const desc = componentDoc?.description;
87
- if (desc) return desc;
88
- const consumerComponent: ConsumerComponent = component.state._consumer;
89
- const fromJsDocs = consumerComponent.docs?.find((doc) => doc.description);
90
-
91
- return fromJsDocs?.description || '';
92
- }
93
-
94
- async getTemplate(context: ExecutionContext) {
95
- return context.env.getDocsTemplate();
96
- }
97
-
98
- getDocReader(extension: string) {
99
- return this.docReaderSlot.values().find((docReader) => docReader.isFormatSupported(extension));
100
- }
101
-
102
- /**
103
- * compute a doc for a component.
104
- */
105
- async computeDoc(component: Component) {
106
- const docFiles = this.getDocsFiles(component);
107
- if (docFiles.length) {
108
- // currently taking the the first docs file found with an abstract. (we support only one)
109
- const docFile = docFiles[0];
110
-
111
- try {
112
- const docReader = this.getDocReader(docFile.extname);
113
- if (!docReader) throw new FileExtensionNotSupported(docFile.relative, docFile.extname);
114
- const doc = await docReader.read(docFile.relative, docFile.contents, component);
115
- return doc;
116
- } catch (err: any) {
117
- this.logger.error('docs.main.runtime.computeDoc caught an error', err);
118
- return null;
119
- }
120
- }
121
-
122
- return null;
123
- }
124
-
125
- getDoc(component: Component) {
126
- const docData = component.state.aspects.get(DocsAspect.id)?.data?.doc;
127
- if (!docData) return null;
128
- return new Doc(docData.filePath, new DocPropList(docData.props));
129
- }
130
-
131
- getPatterns() {
132
- return this.patterns;
133
- }
134
-
135
- /**
136
- * register a new doc reader. this allows to support further
137
- * documentation file formats.
138
- */
139
- registerDocReader(docReader: DocReader) {
140
- this.docReaderSlot.register(docReader);
141
- return this;
142
- }
143
-
144
- static slots = [Slot.withType<DocProp>(), Slot.withType<DocReader>()];
145
-
146
- static runtime = MainRuntime;
147
- static dependencies = [
148
- PreviewAspect,
149
- GraphqlAspect,
150
- WorkspaceAspect,
151
- PkgAspect,
152
- CompilerAspect,
153
- LoggerAspect,
154
- DevFilesAspect,
155
- ComponentAspect,
156
- ];
157
-
158
- static defaultConfig = {
159
- patterns: ['**/*.docs.*'],
160
- };
161
-
162
- static async provider(
163
- [preview, graphql, workspace, pkg, compiler, loggerAspect, devFiles]: [
164
- PreviewMain,
165
- GraphqlMain,
166
- Workspace,
167
- PkgMain,
168
- CompilerMain,
169
- LoggerMain,
170
- DevFilesMain
171
- ],
172
- config: DocsConfig,
173
- [docPropSlot, docReaderSlot]: [DocPropSlot, DocReaderSlot]
174
- ) {
175
- const logger = loggerAspect.createLogger(DocsAspect.id);
176
- const docs = new DocsMain(
177
- config.patterns,
178
-
179
- preview,
180
-
181
- pkg,
182
-
183
- compiler,
184
-
185
- workspace,
186
-
187
- logger,
188
-
189
- devFiles,
190
-
191
- docPropSlot,
192
-
193
- docReaderSlot
194
- );
195
- docs.registerDocReader(new DefaultDocReader(pkg, compiler, workspace));
196
- devFiles.registerDevPattern(config.patterns);
197
-
198
- if (workspace) {
199
- workspace.onComponentLoad(async (component) => {
200
- const doc = await docs.computeDoc(component);
201
-
202
- return {
203
- doc: doc?.toObject(),
204
- };
205
- });
206
- }
207
-
208
- graphql.register(docsSchema(docs));
209
-
210
- preview.registerDefinition(new DocsPreviewDefinition(docs));
211
- return docs;
212
- }
213
- }
214
-
215
- DocsAspect.addRuntime(DocsMain);
@@ -1,26 +0,0 @@
1
- import { Component, ComponentMap } from '@teambit/component';
2
- import { ExecutionContext } from '@teambit/envs';
3
- import { PreviewDefinition } from '@teambit/preview';
4
- import { AbstractVinyl } from '@teambit/legacy/dist/consumer/component/sources';
5
-
6
- import { DocsMain } from './docs.main.runtime';
7
-
8
- export class DocsPreviewDefinition implements PreviewDefinition {
9
- readonly prefix = 'overview';
10
-
11
- constructor(
12
- /**
13
- * docs extension.
14
- */
15
- private docs: DocsMain
16
- ) {}
17
-
18
- async renderTemplatePath(context: ExecutionContext): Promise<string> {
19
- return this.docs.getTemplate(context);
20
- }
21
-
22
- async getModuleMap(components: Component[]): Promise<ComponentMap<AbstractVinyl[]>> {
23
- const map = this.docs.getDocsMap(components);
24
- return map.filter((value) => value.length !== 0);
25
- }
26
- }
@@ -1,48 +0,0 @@
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
- }
package/docs.service.ts DELETED
@@ -1,9 +0,0 @@
1
- import { EnvService, ExecutionContext } from '@teambit/envs';
2
-
3
- export class DocsService implements EnvService<any> {
4
- name = 'docs';
5
-
6
- async run(context: ExecutionContext) {
7
- return context.env.getDocsTemplate();
8
- }
9
- }
package/docs.ts DELETED
@@ -1,18 +0,0 @@
1
- import React from 'react';
2
-
3
- export type Docs = {
4
- /**
5
- * default is the docs content.
6
- */
7
- default: React.ComponentType;
8
-
9
- /**
10
- * component abstract.
11
- */
12
- abstract: string;
13
-
14
- /**
15
- * array of labels.
16
- */
17
- labels: string[];
18
- };
@@ -1,25 +0,0 @@
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);
@@ -1,14 +0,0 @@
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
- }
package/events/index.ts DELETED
@@ -1 +0,0 @@
1
- export * from './click-inside-an-iframe';
@@ -1,5 +0,0 @@
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
- }
@@ -1,6 +0,0 @@
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
- }
@@ -1,2 +0,0 @@
1
- export { FileExtensionNotSupported } from './file-extension-not-supported';
2
- export { DocReadError } from './doc-read-error';
package/index.ts DELETED
@@ -1,9 +0,0 @@
1
- import { DocsAspect } from './docs.aspect';
2
-
3
- export type { DocsMain } from './docs.main.runtime';
4
- export type { DocsUI } from './docs.ui.runtime';
5
- export type { DocsPreview } from './docs.preview.runtime';
6
- export type { DocReader } from './doc-reader';
7
- export { Doc, DocProp, DocPropList } from './doc';
8
- export { DocsAspect };
9
- export default DocsAspect;
package/overview/index.ts DELETED
@@ -1 +0,0 @@
1
- export { Overview } from './overview';
@@ -1,23 +0,0 @@
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
- }
@@ -1,28 +0,0 @@
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/types/asset.d.ts DELETED
@@ -1,29 +0,0 @@
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 DELETED
@@ -1,42 +0,0 @@
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
- }