@stoplight/elements-dev-portal 3.0.11 → 3.0.12-beta-0.1

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 (107) hide show
  1. package/.storybook/main.js +6 -0
  2. package/.storybook/manager.js +1 -0
  3. package/.storybook/preview.jsx +46 -0
  4. package/dist/LICENSE +190 -0
  5. package/dist/README.md +22 -0
  6. package/{index.esm.js → dist/index.esm.js} +8 -2
  7. package/{index.js → dist/index.js} +8 -2
  8. package/{index.mjs → dist/index.mjs} +8 -2
  9. package/dist/package.json +51 -0
  10. package/dist/version.d.ts +1 -0
  11. package/{web-components.min.js → dist/web-components.min.js} +1 -1
  12. package/jest.config.js +10 -0
  13. package/package.json +71 -17
  14. package/src/__fixtures__/branches.json +28 -0
  15. package/src/__fixtures__/node-content.json +257 -0
  16. package/src/__fixtures__/table-of-contents.json +144 -0
  17. package/src/components/BranchSelector/BranchSelector.spec.tsx +61 -0
  18. package/src/components/BranchSelector/BranchSelector.stories.tsx +41 -0
  19. package/src/components/BranchSelector/BranchSelector.tsx +50 -0
  20. package/src/components/BranchSelector/index.tsx +1 -0
  21. package/src/components/DevPortalProvider/index.tsx +25 -0
  22. package/src/components/Forbidden.tsx +11 -0
  23. package/src/components/Loading.tsx +9 -0
  24. package/src/components/NodeContent/NodeContent.spec.tsx +128 -0
  25. package/src/components/NodeContent/NodeContent.stories.tsx +60 -0
  26. package/src/components/NodeContent/NodeContent.tsx +235 -0
  27. package/src/components/NodeContent/index.tsx +1 -0
  28. package/src/components/NotFound.tsx +11 -0
  29. package/src/components/Search/Search.stories.tsx +151 -0
  30. package/src/components/Search/Search.tsx +161 -0
  31. package/src/components/Search/SearchOverlay.tsx +88 -0
  32. package/src/components/Search/index.tsx +1 -0
  33. package/src/components/TableOfContents/TableOfContents.stories.tsx +68 -0
  34. package/src/components/TableOfContents/TableOfContents.tsx +54 -0
  35. package/src/components/TableOfContents/index.tsx +1 -0
  36. package/src/components/UpgradeToStarter.tsx +22 -0
  37. package/src/consts.ts +32 -0
  38. package/src/containers/StoplightProject.spec.tsx +78 -0
  39. package/src/containers/StoplightProject.stories.tsx +28 -0
  40. package/src/containers/StoplightProject.tsx +269 -0
  41. package/src/handlers/__tests__/getBranches.test.ts +30 -0
  42. package/src/handlers/__tests__/getNodeContent.test.ts +35 -0
  43. package/src/handlers/__tests__/getNodes.test.ts +38 -0
  44. package/src/handlers/__tests__/getTableOfContents.test.ts +34 -0
  45. package/src/handlers/__tests__/getWorkspace.test.ts +30 -0
  46. package/src/handlers/getBranches.ts +27 -0
  47. package/src/handlers/getNodeContent.ts +53 -0
  48. package/src/handlers/getNodes.ts +69 -0
  49. package/src/handlers/getTableOfContents.ts +30 -0
  50. package/src/handlers/getWorkspace.ts +27 -0
  51. package/src/hooks/__tests__/dataFetching.spec.tsx +42 -0
  52. package/src/hooks/useGetBranches.ts +17 -0
  53. package/src/hooks/useGetNodeContent.ts +24 -0
  54. package/src/hooks/useGetNodes.ts +34 -0
  55. package/src/hooks/useGetTableOfContents.ts +17 -0
  56. package/src/hooks/useGetWorkspace.tsx +13 -0
  57. package/src/index.ts +25 -0
  58. package/src/styles.css +1 -0
  59. package/src/types.ts +85 -0
  60. package/src/version.ts +2 -0
  61. package/src/web-components/__stories__/StoplightProject.stories.tsx +33 -0
  62. package/src/web-components/components.ts +19 -0
  63. package/src/web-components/index.ts +3 -0
  64. package/tsconfig.build.json +18 -0
  65. package/tsconfig.json +7 -0
  66. package/web-components.config.js +1 -0
  67. package/version.d.ts +0 -1
  68. /package/{components → dist/components}/BranchSelector/BranchSelector.d.ts +0 -0
  69. /package/{components → dist/components}/BranchSelector/BranchSelector.spec.d.ts +0 -0
  70. /package/{components → dist/components}/BranchSelector/BranchSelector.stories.d.ts +0 -0
  71. /package/{components → dist/components}/BranchSelector/index.d.ts +0 -0
  72. /package/{components → dist/components}/DevPortalProvider/index.d.ts +0 -0
  73. /package/{components → dist/components}/Forbidden.d.ts +0 -0
  74. /package/{components → dist/components}/Loading.d.ts +0 -0
  75. /package/{components → dist/components}/NodeContent/NodeContent.d.ts +0 -0
  76. /package/{components → dist/components}/NodeContent/NodeContent.spec.d.ts +0 -0
  77. /package/{components → dist/components}/NodeContent/NodeContent.stories.d.ts +0 -0
  78. /package/{components → dist/components}/NodeContent/index.d.ts +0 -0
  79. /package/{components → dist/components}/NotFound.d.ts +0 -0
  80. /package/{components → dist/components}/Search/Search.d.ts +0 -0
  81. /package/{components → dist/components}/Search/Search.stories.d.ts +0 -0
  82. /package/{components → dist/components}/Search/SearchOverlay.d.ts +0 -0
  83. /package/{components → dist/components}/Search/index.d.ts +0 -0
  84. /package/{components → dist/components}/TableOfContents/TableOfContents.d.ts +0 -0
  85. /package/{components → dist/components}/TableOfContents/TableOfContents.stories.d.ts +0 -0
  86. /package/{components → dist/components}/TableOfContents/index.d.ts +0 -0
  87. /package/{components → dist/components}/UpgradeToStarter.d.ts +0 -0
  88. /package/{consts.d.ts → dist/consts.d.ts} +0 -0
  89. /package/{containers → dist/containers}/StoplightProject.d.ts +0 -0
  90. /package/{containers → dist/containers}/StoplightProject.spec.d.ts +0 -0
  91. /package/{containers → dist/containers}/StoplightProject.stories.d.ts +0 -0
  92. /package/{handlers → dist/handlers}/getBranches.d.ts +0 -0
  93. /package/{handlers → dist/handlers}/getNodeContent.d.ts +0 -0
  94. /package/{handlers → dist/handlers}/getNodes.d.ts +0 -0
  95. /package/{handlers → dist/handlers}/getTableOfContents.d.ts +0 -0
  96. /package/{handlers → dist/handlers}/getWorkspace.d.ts +0 -0
  97. /package/{hooks → dist/hooks}/useGetBranches.d.ts +0 -0
  98. /package/{hooks → dist/hooks}/useGetNodeContent.d.ts +0 -0
  99. /package/{hooks → dist/hooks}/useGetNodes.d.ts +0 -0
  100. /package/{hooks → dist/hooks}/useGetTableOfContents.d.ts +0 -0
  101. /package/{hooks → dist/hooks}/useGetWorkspace.d.ts +0 -0
  102. /package/{index.d.ts → dist/index.d.ts} +0 -0
  103. /package/{styles.min.css → dist/styles.min.css} +0 -0
  104. /package/{types.d.ts → dist/types.d.ts} +0 -0
  105. /package/{web-components → dist/web-components}/components.d.ts +0 -0
  106. /package/{web-components → dist/web-components}/index.d.ts +0 -0
  107. /package/{web-components.min.js.LICENSE.txt → dist/web-components.min.js.LICENSE.txt} +0 -0
@@ -0,0 +1,17 @@
1
+ import * as React from 'react';
2
+ import { useQuery } from 'react-query';
3
+
4
+ import { PlatformContext } from '../components/DevPortalProvider';
5
+ import { devPortalCacheKeys } from '../consts';
6
+ import { getBranches } from '../handlers/getBranches';
7
+
8
+ export function useGetBranches({ projectId }: { projectId: string }) {
9
+ const { platformUrl, platformAuthToken, isLoggedIn } = React.useContext(PlatformContext);
10
+ return useQuery(
11
+ [...devPortalCacheKeys.branchesList(projectId), platformUrl, isLoggedIn],
12
+ () => getBranches({ projectId, platformUrl, platformAuthToken }),
13
+ {
14
+ enabled: projectId ? true : false,
15
+ },
16
+ );
17
+ }
@@ -0,0 +1,24 @@
1
+ import * as React from 'react';
2
+ import { useQuery } from 'react-query';
3
+
4
+ import { PlatformContext } from '../components/DevPortalProvider';
5
+ import { devPortalCacheKeys } from '../consts';
6
+ import { getNodeContent } from '../handlers/getNodeContent';
7
+
8
+ export function useGetNodeContent({
9
+ nodeSlug,
10
+ projectId,
11
+ branchSlug,
12
+ }: {
13
+ nodeSlug: string;
14
+ projectId: string;
15
+ branchSlug?: string;
16
+ }) {
17
+ const { platformUrl, platformAuthToken, isLoggedIn } = React.useContext(PlatformContext);
18
+
19
+ return useQuery(
20
+ [...devPortalCacheKeys.branchNodeDetails(projectId, branchSlug ?? '', nodeSlug), platformUrl, isLoggedIn],
21
+ () => getNodeContent({ nodeSlug, projectId, branchSlug, platformUrl, platformAuthToken }),
22
+ { enabled: nodeSlug && projectId ? true : false },
23
+ );
24
+ }
@@ -0,0 +1,34 @@
1
+ import * as React from 'react';
2
+ import { useQuery } from 'react-query';
3
+ import { useDebounce } from 'use-debounce';
4
+
5
+ import { PlatformContext } from '../components/DevPortalProvider';
6
+ import { devPortalCacheKeys } from '../consts';
7
+ import { getNodes } from '../handlers/getNodes';
8
+
9
+ export function useGetNodes({
10
+ search,
11
+ workspaceId,
12
+ projectIds,
13
+ branch,
14
+ pause,
15
+ }: {
16
+ search: string;
17
+ workspaceId?: string;
18
+ projectIds?: string[];
19
+ branch?: string;
20
+ pause?: boolean;
21
+ }) {
22
+ const { platformUrl, platformAuthToken, isLoggedIn } = React.useContext(PlatformContext);
23
+ const [debounceSearch] = useDebounce(search, 500);
24
+ return useQuery(
25
+ [
26
+ ...devPortalCacheKeys.searchNodes({ projectIds, branchSlug: branch, workspaceId, search: debounceSearch }),
27
+ platformUrl,
28
+ isLoggedIn,
29
+ ],
30
+ () =>
31
+ getNodes({ workspaceId, projectIds, branchSlug: branch, search: debounceSearch, platformUrl, platformAuthToken }),
32
+ { enabled: !pause, keepPreviousData: true },
33
+ );
34
+ }
@@ -0,0 +1,17 @@
1
+ import * as React from 'react';
2
+ import { useQuery } from 'react-query';
3
+
4
+ import { PlatformContext } from '../components/DevPortalProvider';
5
+ import { devPortalCacheKeys } from '../consts';
6
+ import { getTableOfContents } from '../handlers/getTableOfContents';
7
+
8
+ export function useGetTableOfContents({ projectId, branchSlug }: { projectId: string; branchSlug?: string }) {
9
+ const { platformUrl, platformAuthToken, isLoggedIn } = React.useContext(PlatformContext);
10
+ return useQuery(
11
+ [...devPortalCacheKeys.branchTOC(projectId, branchSlug ?? ''), platformUrl, isLoggedIn],
12
+ () => getTableOfContents({ projectId, branchSlug, platformUrl, platformAuthToken }),
13
+ // Here projectId cHJqOjA is an encoded value of zero,
14
+ // hence avoiding the graphql call for invalid project id
15
+ { enabled: projectId && projectId !== 'cHJqOjA' ? true : false },
16
+ );
17
+ }
@@ -0,0 +1,13 @@
1
+ import * as React from 'react';
2
+ import { useQuery } from 'react-query';
3
+
4
+ import { PlatformContext } from '../components/DevPortalProvider';
5
+ import { devPortalCacheKeys } from '../consts';
6
+ import { getWorkspace } from '../handlers/getWorkspace';
7
+
8
+ export function useGetWorkspace({ projectIds }: { projectIds: string[] }) {
9
+ const { platformUrl, platformAuthToken } = React.useContext(PlatformContext);
10
+ return useQuery([...devPortalCacheKeys.searchNodes({ projectIds }), platformUrl, platformAuthToken], () =>
11
+ getWorkspace({ projectIds, platformUrl, platformAuthToken }),
12
+ );
13
+ }
package/src/index.ts ADDED
@@ -0,0 +1,25 @@
1
+ export type { BranchSelectorProps } from './components/BranchSelector';
2
+ export { BranchSelector } from './components/BranchSelector';
3
+ export type { DevPortalProviderProps } from './components/DevPortalProvider';
4
+ export { DevPortalProvider } from './components/DevPortalProvider';
5
+ export type { NodeContentProps } from './components/NodeContent';
6
+ export { NodeContent } from './components/NodeContent';
7
+ export type { SearchProps } from './components/Search';
8
+ export { Search, SearchResults } from './components/Search';
9
+ export type { TableOfContentsProps } from './components/TableOfContents';
10
+ export { TableOfContents } from './components/TableOfContents';
11
+ export { devPortalCacheKeys } from './consts';
12
+ export type { StoplightProjectProps } from './containers/StoplightProject';
13
+ export { StoplightProject } from './containers/StoplightProject';
14
+ export { getBranches } from './handlers/getBranches';
15
+ export { getNodeContent, ResponseError } from './handlers/getNodeContent';
16
+ export { getNodes } from './handlers/getNodes';
17
+ export { getTableOfContents } from './handlers/getTableOfContents';
18
+ export { getWorkspace } from './handlers/getWorkspace';
19
+ export { useGetBranches } from './hooks/useGetBranches';
20
+ export { useGetNodeContent } from './hooks/useGetNodeContent';
21
+ export { useGetNodes } from './hooks/useGetNodes';
22
+ export { useGetTableOfContents } from './hooks/useGetTableOfContents';
23
+ export { useGetWorkspace } from './hooks/useGetWorkspace';
24
+ export type { ProjectTableOfContents } from './types';
25
+ export type { Branch, Node, NodeSearchResult } from './types';
package/src/styles.css ADDED
@@ -0,0 +1 @@
1
+ @import '../../elements-core/src/styles.css';
package/src/types.ts ADDED
@@ -0,0 +1,85 @@
1
+ import { TableOfContentsItem } from '@stoplight/elements-core';
2
+
3
+ export type Branch = {
4
+ id: number;
5
+ slug: string;
6
+ is_default: boolean;
7
+ is_published: boolean;
8
+ name?: string;
9
+ };
10
+
11
+ export type Branches = {
12
+ items: Branch[];
13
+ };
14
+
15
+ export type ProjectTableOfContents = {
16
+ items: TableOfContentsItem[];
17
+ hide_powered_by?: boolean;
18
+ collapseTableOfContents?: boolean;
19
+ };
20
+
21
+ export type Node = NodeSummary & {
22
+ data: any;
23
+ links: {
24
+ mock_url?: string;
25
+ /**
26
+ * @deprecated use export_original_file_url instead
27
+ */
28
+ export_url?: string;
29
+ /**
30
+ * The URL to export the original file. This is not a bundled output, meaning references are left in place.
31
+ */
32
+ export_original_file_url?: string;
33
+ /**
34
+ * The URL to export a bundled form of the file. Bundling means references are copied into the output file.
35
+ */
36
+ export_bundled_file_url?: string;
37
+ };
38
+ outbound_edges: NodeEdge[];
39
+ inbound_edges: NodeEdge[];
40
+ disableProps?: any;
41
+ };
42
+
43
+ export type NodeSummary = {
44
+ id: string;
45
+ type: string;
46
+ uri: string;
47
+ slug: string;
48
+ title: string;
49
+ summary: string;
50
+ project_id: string;
51
+ branch_id: string;
52
+ branch_node_id: number;
53
+ branch: string;
54
+ };
55
+
56
+ export type NodeEdge = {
57
+ id: string;
58
+ type: string;
59
+ uri: string;
60
+ slug: string;
61
+ title: string;
62
+ };
63
+
64
+ export type NodeSearchResult = NodeSummary & {
65
+ highlighted: {
66
+ name: string | null;
67
+ summary: string | null;
68
+ data: string | null;
69
+ };
70
+ project_slug: string;
71
+ project_name: string;
72
+ node_id: number;
73
+ };
74
+
75
+ export type Workspace = {
76
+ id: string;
77
+ name: string;
78
+ slug: string;
79
+ default_branch_id: string;
80
+ workspace: {
81
+ id: string;
82
+ name: string;
83
+ slug: string;
84
+ };
85
+ };
package/src/version.ts ADDED
@@ -0,0 +1,2 @@
1
+ // auto-updated during build
2
+ export const appVersion = '3.0.12-beta-0.1';
@@ -0,0 +1,33 @@
1
+ import '../index';
2
+
3
+ import { Story } from '@storybook/react';
4
+ import React from 'react';
5
+
6
+ declare global {
7
+ namespace JSX {
8
+ interface IntrinsicElements {
9
+ 'elements-stoplight-project': React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement>;
10
+ }
11
+ }
12
+ }
13
+
14
+ const Template: Story = (props: any) => <elements-stoplight-project {...props} />;
15
+
16
+ export default {
17
+ title: 'web-components/StoplightProject',
18
+ argTypes: {
19
+ projectId: { control: 'text' },
20
+ platformUrl: { control: 'text' },
21
+ router: {
22
+ control: { type: 'inline-radio', options: ['history', 'hash', 'memory'] },
23
+ defaultValue: 'history',
24
+ },
25
+ },
26
+ };
27
+
28
+ export const defaultProject = Template.bind({});
29
+ defaultProject.storyName = "Stoplight's Demo workspace";
30
+ defaultProject.args = {
31
+ projectId: 'cHJqOjYwNjYx',
32
+ platformUrl: 'https://stoplight.io',
33
+ };
@@ -0,0 +1,19 @@
1
+ import { createElementClass } from '@stoplight/elements-core';
2
+
3
+ import { StoplightProject } from '../containers/StoplightProject';
4
+
5
+ export const StoplightProjectElement = createElementClass(StoplightProject, {
6
+ projectId: { type: 'string', defaultValue: '' },
7
+ hideTryIt: { type: 'boolean' },
8
+ hideServerInfo: { type: 'boolean' },
9
+ hideSecurityInfo: { type: 'boolean' },
10
+ hideMocking: { type: 'boolean' },
11
+ hideExport: { type: 'boolean' },
12
+ basePath: { type: 'string' },
13
+ staticRouterPath: { type: 'string' },
14
+ router: { type: 'string' },
15
+ platformUrl: { type: 'string' },
16
+ collapseTableOfContents: { type: 'boolean' },
17
+ tryItCredentialsPolicy: { type: 'string' },
18
+ tryItCorsProxy: { type: 'string' },
19
+ });
@@ -0,0 +1,3 @@
1
+ import { StoplightProjectElement } from './components';
2
+
3
+ window.customElements.define('elements-stoplight-project', StoplightProjectElement);
@@ -0,0 +1,18 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "include": [
4
+ "src"
5
+ ],
6
+ "exclude": [
7
+ "**/__*__/**"
8
+ ],
9
+ "compilerOptions": {
10
+ "baseUrl": "./",
11
+ "outDir": "dist",
12
+ "moduleResolution": "node",
13
+ "paths": {
14
+ "@stoplight/elements-core": ["../elements-core/dist"],
15
+ "@stoplight/elements-core/*": ["../elements-core/dist/*"]
16
+ }
17
+ }
18
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+
4
+ "include": ["src"],
5
+
6
+ "exclude": ["**/__fixtures__/**", "**/__stories__/**", "**/__tests__/**"]
7
+ }
@@ -0,0 +1 @@
1
+ module.exports = require('../../web-components.webpack.config');
package/version.d.ts DELETED
@@ -1 +0,0 @@
1
- export declare const appVersion = "3.0.11";
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes