@teambit/code.ui.queries.get-file-content 0.0.504 → 0.0.506
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.
- package/dist/get-file-content.d.ts +3 -36
- package/dist/get-file-content.js +36 -21
- package/dist/get-file-content.js.map +1 -1
- package/get-file-content.ts +43 -9
- package/package.json +15 -12
- package/dist/tsconfig.json +0 -32
- package/package-tar/teambit-code.ui.queries.get-file-content-0.0.504.tgz +0 -0
- package/tsconfig.json +0 -32
- /package/dist/{preview-1670470092710.js → preview-1778686821215.js} +0 -0
|
@@ -1,38 +1,5 @@
|
|
|
1
|
-
import { ComponentID } from '@teambit/component';
|
|
2
|
-
declare
|
|
3
|
-
|
|
4
|
-
id: string;
|
|
5
|
-
get: {
|
|
6
|
-
id: {
|
|
7
|
-
name: string;
|
|
8
|
-
version: string;
|
|
9
|
-
scope: string;
|
|
10
|
-
};
|
|
11
|
-
getFile?: string;
|
|
12
|
-
};
|
|
13
|
-
};
|
|
14
|
-
};
|
|
15
|
-
export declare function useFileContent(componentId?: ComponentID, filePath?: string, skip?: boolean): {
|
|
16
|
-
client: import("@apollo/client").ApolloClient<any>;
|
|
17
|
-
observable: import("@apollo/client").ObservableQuery<FileResult, import("@apollo/client").OperationVariables>;
|
|
18
|
-
previousData?: FileResult;
|
|
19
|
-
error?: import("@apollo/client").ApolloError;
|
|
1
|
+
import type { ComponentID } from '@teambit/component-id';
|
|
2
|
+
export declare function useFileContent(componentId?: ComponentID, filePath?: string, skip?: boolean, host?: string): {
|
|
3
|
+
fileContent: any;
|
|
20
4
|
loading: boolean;
|
|
21
|
-
networkStatus: import("@apollo/client").NetworkStatus;
|
|
22
|
-
called: boolean;
|
|
23
|
-
variables: import("@apollo/client").OperationVariables;
|
|
24
|
-
startPolling: (pollInterval: number) => void;
|
|
25
|
-
stopPolling: () => void;
|
|
26
|
-
subscribeToMore: <TSubscriptionData = FileResult, TSubscriptionVariables = import("@apollo/client").OperationVariables>(options: import("@apollo/client").SubscribeToMoreOptions<FileResult, TSubscriptionVariables, TSubscriptionData>) => () => void;
|
|
27
|
-
updateQuery: <TVars = import("@apollo/client").OperationVariables>(mapFn: (previousQueryResult: FileResult, options: Pick<import("@apollo/client").WatchQueryOptions<TVars, FileResult>, "variables">) => FileResult) => void;
|
|
28
|
-
refetch: (variables?: Partial<import("@apollo/client").OperationVariables>) => Promise<import("@apollo/client").ApolloQueryResult<FileResult>>;
|
|
29
|
-
reobserve: (newOptions?: Partial<import("@apollo/client").WatchQueryOptions<import("@apollo/client").OperationVariables, FileResult>>, newNetworkStatus?: import("@apollo/client").NetworkStatus) => Promise<import("@apollo/client").ApolloQueryResult<FileResult>>;
|
|
30
|
-
fetchMore: <TFetchData = FileResult, TFetchVars = import("@apollo/client").OperationVariables>(fetchMoreOptions: import("@apollo/client").FetchMoreQueryOptions<TFetchVars, TFetchData> & {
|
|
31
|
-
updateQuery?: (previousQueryResult: FileResult, options: {
|
|
32
|
-
fetchMoreResult: TFetchData;
|
|
33
|
-
variables: TFetchVars;
|
|
34
|
-
}) => FileResult;
|
|
35
|
-
}) => Promise<import("@apollo/client").ApolloQueryResult<TFetchData>>;
|
|
36
|
-
fileContent: string;
|
|
37
5
|
};
|
|
38
|
-
export {};
|
package/dist/get-file-content.js
CHANGED
|
@@ -1,22 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
-
var t = {};
|
|
4
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
-
t[p] = s[p];
|
|
6
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
-
t[p[i]] = s[p[i]];
|
|
10
|
-
}
|
|
11
|
-
return t;
|
|
12
|
-
};
|
|
13
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.useFileContent =
|
|
3
|
+
exports.useFileContent = useFileContent;
|
|
15
4
|
const client_1 = require("@apollo/client");
|
|
16
5
|
const ui_foundation_ui_hooks_use_data_query_1 = require("@teambit/ui-foundation.ui.hooks.use-data-query");
|
|
17
6
|
const getFile = (0, client_1.gql) `
|
|
18
|
-
query getFile($id: String!, $path: String) {
|
|
19
|
-
getHost {
|
|
7
|
+
query getFile($id: String!, $extensionId: String, $path: String) {
|
|
8
|
+
getHost(id: $extensionId) {
|
|
20
9
|
id # used for GQL caching
|
|
21
10
|
get(id: $id) {
|
|
22
11
|
id {
|
|
@@ -30,15 +19,41 @@ const getFile = (0, client_1.gql) `
|
|
|
30
19
|
}
|
|
31
20
|
}
|
|
32
21
|
`;
|
|
33
|
-
|
|
22
|
+
const COMPONENT_CHANGED_SUBSCRIPTION = (0, client_1.gql) `
|
|
23
|
+
subscription OnComponentChangedForFile {
|
|
24
|
+
componentChanged {
|
|
25
|
+
component {
|
|
26
|
+
id {
|
|
27
|
+
name
|
|
28
|
+
scope
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
`;
|
|
34
|
+
function useFileContent(componentId, filePath, skip, host) {
|
|
34
35
|
var _a, _b;
|
|
35
36
|
const id = componentId === null || componentId === void 0 ? void 0 : componentId.toString();
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
const querySkip = skip || !componentId || filePath === undefined;
|
|
38
|
+
const { data, loading, refetch } = (0, ui_foundation_ui_hooks_use_data_query_1.useDataQuery)(getFile, {
|
|
39
|
+
variables: { id, path: filePath, extensionId: host },
|
|
40
|
+
skip: querySkip,
|
|
41
|
+
});
|
|
42
|
+
(0, client_1.useSubscription)(COMPONENT_CHANGED_SUBSCRIPTION, {
|
|
43
|
+
skip: querySkip,
|
|
44
|
+
onSubscriptionData: ({ subscriptionData }) => {
|
|
45
|
+
var _a, _b, _c;
|
|
46
|
+
const changedId = (_c = (_b = (_a = subscriptionData.data) === null || _a === void 0 ? void 0 : _a.componentChanged) === null || _b === void 0 ? void 0 : _b.component) === null || _c === void 0 ? void 0 : _c.id;
|
|
47
|
+
if (!changedId || !componentId)
|
|
48
|
+
return;
|
|
49
|
+
if (changedId.name !== componentId.fullName)
|
|
50
|
+
return;
|
|
51
|
+
if (changedId.scope && componentId.scope && changedId.scope !== componentId.scope)
|
|
52
|
+
return;
|
|
53
|
+
refetch();
|
|
54
|
+
},
|
|
55
|
+
});
|
|
40
56
|
const fileContent = (_b = (_a = data === null || data === void 0 ? void 0 : data.getHost) === null || _a === void 0 ? void 0 : _a.get) === null || _b === void 0 ? void 0 : _b.getFile;
|
|
41
|
-
return
|
|
57
|
+
return { fileContent, loading };
|
|
42
58
|
}
|
|
43
|
-
exports.useFileContent = useFileContent;
|
|
44
59
|
//# sourceMappingURL=get-file-content.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-file-content.js","sourceRoot":"","sources":["../get-file-content.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"get-file-content.js","sourceRoot":"","sources":["../get-file-content.ts"],"names":[],"mappings":";;AAwDA,wCAuBC;AA/ED,2CAAsD;AACtD,0GAA8E;AAG9E,MAAM,OAAO,GAAG,IAAA,YAAG,EAAA;;;;;;;;;;;;;;;CAelB,CAAC;AAEF,MAAM,8BAA8B,GAAG,IAAA,YAAG,EAAA;;;;;;;;;;;CAWzC,CAAC;AAwBF,SAAgB,cAAc,CAAC,WAAyB,EAAE,QAAiB,EAAE,IAAc,EAAE,IAAa;;IACxG,MAAM,EAAE,GAAG,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,QAAQ,EAAE,CAAC;IACnC,MAAM,SAAS,GAAG,IAAI,IAAI,CAAC,WAAW,IAAI,QAAQ,KAAK,SAAS,CAAC;IAEjE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,IAAA,oDAAY,EAAa,OAAO,EAAE;QACnE,SAAS,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,IAAI,EAAE;QACpD,IAAI,EAAE,SAAS;KAChB,CAAC,CAAC;IAEH,IAAA,wBAAe,EAA0B,8BAA8B,EAAE;QACvE,IAAI,EAAE,SAAS;QACf,kBAAkB,EAAE,CAAC,EAAE,gBAAgB,EAAE,EAAE,EAAE;;YAC3C,MAAM,SAAS,GAAG,MAAA,MAAA,MAAA,gBAAgB,CAAC,IAAI,0CAAE,gBAAgB,0CAAE,SAAS,0CAAE,EAAE,CAAC;YACzE,IAAI,CAAC,SAAS,IAAI,CAAC,WAAW;gBAAE,OAAO;YACvC,IAAI,SAAS,CAAC,IAAI,KAAK,WAAW,CAAC,QAAQ;gBAAE,OAAO;YACpD,IAAI,SAAS,CAAC,KAAK,IAAI,WAAW,CAAC,KAAK,IAAI,SAAS,CAAC,KAAK,KAAK,WAAW,CAAC,KAAK;gBAAE,OAAO;YAC1F,OAAO,EAAE,CAAC;QACZ,CAAC;KACF,CAAC,CAAC;IAEH,MAAM,WAAW,GAAG,MAAA,MAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,OAAO,0CAAE,GAAG,0CAAE,OAAO,CAAC;IAEhD,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,CAAC;AAClC,CAAC"}
|
package/get-file-content.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { gql } from '@apollo/client';
|
|
1
|
+
import { gql, useSubscription } from '@apollo/client';
|
|
2
2
|
import { useDataQuery } from '@teambit/ui-foundation.ui.hooks.use-data-query';
|
|
3
|
-
import { ComponentID } from '@teambit/component';
|
|
3
|
+
import type { ComponentID } from '@teambit/component-id';
|
|
4
4
|
|
|
5
5
|
const getFile = gql`
|
|
6
|
-
query getFile($id: String!, $path: String) {
|
|
7
|
-
getHost {
|
|
6
|
+
query getFile($id: String!, $extensionId: String, $path: String) {
|
|
7
|
+
getHost(id: $extensionId) {
|
|
8
8
|
id # used for GQL caching
|
|
9
9
|
get(id: $id) {
|
|
10
10
|
id {
|
|
@@ -19,6 +19,19 @@ const getFile = gql`
|
|
|
19
19
|
}
|
|
20
20
|
`;
|
|
21
21
|
|
|
22
|
+
const COMPONENT_CHANGED_SUBSCRIPTION = gql`
|
|
23
|
+
subscription OnComponentChangedForFile {
|
|
24
|
+
componentChanged {
|
|
25
|
+
component {
|
|
26
|
+
id {
|
|
27
|
+
name
|
|
28
|
+
scope
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
`;
|
|
34
|
+
|
|
22
35
|
type FileResult = {
|
|
23
36
|
getHost: {
|
|
24
37
|
id: string;
|
|
@@ -33,14 +46,35 @@ type FileResult = {
|
|
|
33
46
|
};
|
|
34
47
|
};
|
|
35
48
|
|
|
36
|
-
|
|
49
|
+
type ComponentChangedSubData = {
|
|
50
|
+
componentChanged?: {
|
|
51
|
+
component?: {
|
|
52
|
+
id: { name: string; scope: string };
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export function useFileContent(componentId?: ComponentID, filePath?: string, skip?: boolean, host?: string) {
|
|
37
58
|
const id = componentId?.toString();
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
59
|
+
const querySkip = skip || !componentId || filePath === undefined;
|
|
60
|
+
|
|
61
|
+
const { data, loading, refetch } = useDataQuery<FileResult>(getFile, {
|
|
62
|
+
variables: { id, path: filePath, extensionId: host },
|
|
63
|
+
skip: querySkip,
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
useSubscription<ComponentChangedSubData>(COMPONENT_CHANGED_SUBSCRIPTION, {
|
|
67
|
+
skip: querySkip,
|
|
68
|
+
onSubscriptionData: ({ subscriptionData }) => {
|
|
69
|
+
const changedId = subscriptionData.data?.componentChanged?.component?.id;
|
|
70
|
+
if (!changedId || !componentId) return;
|
|
71
|
+
if (changedId.name !== componentId.fullName) return;
|
|
72
|
+
if (changedId.scope && componentId.scope && changedId.scope !== componentId.scope) return;
|
|
73
|
+
refetch();
|
|
74
|
+
},
|
|
41
75
|
});
|
|
42
76
|
|
|
43
77
|
const fileContent = data?.getHost?.get?.getFile;
|
|
44
78
|
|
|
45
|
-
return { fileContent,
|
|
79
|
+
return { fileContent, loading };
|
|
46
80
|
}
|
package/package.json
CHANGED
|
@@ -1,32 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teambit/code.ui.queries.get-file-content",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"homepage": "https://bit.
|
|
3
|
+
"version": "0.0.506",
|
|
4
|
+
"homepage": "https://bit.cloud/teambit/code/ui/queries/get-file-content",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"componentId": {
|
|
7
7
|
"scope": "teambit.code",
|
|
8
8
|
"name": "ui/queries/get-file-content",
|
|
9
|
-
"version": "0.0.
|
|
9
|
+
"version": "0.0.506"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"core-js": "^3.0.0",
|
|
13
|
-
"@teambit/
|
|
13
|
+
"@teambit/component-id": "1.2.4",
|
|
14
|
+
"@teambit/ui-foundation.ui.hooks.use-data-query": "0.0.506"
|
|
14
15
|
},
|
|
15
16
|
"devDependencies": {
|
|
16
17
|
"@types/mocha": "9.1.0",
|
|
17
|
-
"@types/
|
|
18
|
-
"@babel/runtime": "7.20.0",
|
|
19
|
-
"@types/jest": "^26.0.0",
|
|
20
|
-
"@types/react-dom": "^17.0.5",
|
|
18
|
+
"@types/node": "12.20.4",
|
|
21
19
|
"@types/react": "^17.0.8",
|
|
22
|
-
"@types/
|
|
20
|
+
"@types/react-dom": "^17.0.5",
|
|
21
|
+
"@types/jest": "^26.0.0",
|
|
22
|
+
"@babel/runtime": "7.20.0",
|
|
23
|
+
"@types/testing-library__jest-dom": "5.9.5"
|
|
23
24
|
},
|
|
24
25
|
"peerDependencies": {
|
|
25
26
|
"@apollo/client": "^3.6.0",
|
|
26
|
-
"react
|
|
27
|
-
"react": "^16.8.0 || ^17.0.0"
|
|
27
|
+
"react": "^16.8.0 || ^17.0.0",
|
|
28
|
+
"react-dom": "^16.8.0 || ^17.0.0"
|
|
28
29
|
},
|
|
29
30
|
"license": "Apache-2.0",
|
|
31
|
+
"optionalDependencies": {},
|
|
32
|
+
"peerDependenciesMeta": {},
|
|
30
33
|
"private": false,
|
|
31
34
|
"engines": {
|
|
32
35
|
"node": ">=12.22.0"
|
|
@@ -45,4 +48,4 @@
|
|
|
45
48
|
"angular",
|
|
46
49
|
"angular-components"
|
|
47
50
|
]
|
|
48
|
-
}
|
|
51
|
+
}
|
package/dist/tsconfig.json
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"lib": [
|
|
4
|
-
"es2019",
|
|
5
|
-
"DOM",
|
|
6
|
-
"ES6",
|
|
7
|
-
"DOM.Iterable"
|
|
8
|
-
],
|
|
9
|
-
"target": "es2015",
|
|
10
|
-
"module": "CommonJS",
|
|
11
|
-
"jsx": "react",
|
|
12
|
-
"allowJs": true,
|
|
13
|
-
"composite": true,
|
|
14
|
-
"declaration": true,
|
|
15
|
-
"sourceMap": true,
|
|
16
|
-
"skipLibCheck": true,
|
|
17
|
-
"experimentalDecorators": true,
|
|
18
|
-
"outDir": "dist",
|
|
19
|
-
"moduleResolution": "node",
|
|
20
|
-
"esModuleInterop": true,
|
|
21
|
-
"rootDir": ".",
|
|
22
|
-
"resolveJsonModule": true
|
|
23
|
-
},
|
|
24
|
-
"exclude": [
|
|
25
|
-
"dist",
|
|
26
|
-
"package.json"
|
|
27
|
-
],
|
|
28
|
-
"include": [
|
|
29
|
-
"**/*",
|
|
30
|
-
"**/*.json"
|
|
31
|
-
]
|
|
32
|
-
}
|
|
Binary file
|
package/tsconfig.json
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"lib": [
|
|
4
|
-
"es2019",
|
|
5
|
-
"DOM",
|
|
6
|
-
"ES6",
|
|
7
|
-
"DOM.Iterable"
|
|
8
|
-
],
|
|
9
|
-
"target": "es2015",
|
|
10
|
-
"module": "CommonJS",
|
|
11
|
-
"jsx": "react",
|
|
12
|
-
"allowJs": true,
|
|
13
|
-
"composite": true,
|
|
14
|
-
"declaration": true,
|
|
15
|
-
"sourceMap": true,
|
|
16
|
-
"skipLibCheck": true,
|
|
17
|
-
"experimentalDecorators": true,
|
|
18
|
-
"outDir": "dist",
|
|
19
|
-
"moduleResolution": "node",
|
|
20
|
-
"esModuleInterop": true,
|
|
21
|
-
"rootDir": ".",
|
|
22
|
-
"resolveJsonModule": true
|
|
23
|
-
},
|
|
24
|
-
"exclude": [
|
|
25
|
-
"dist",
|
|
26
|
-
"package.json"
|
|
27
|
-
],
|
|
28
|
-
"include": [
|
|
29
|
-
"**/*",
|
|
30
|
-
"**/*.json"
|
|
31
|
-
]
|
|
32
|
-
}
|
|
File without changes
|