datocms-react-ui 2.0.1 → 2.0.3
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/cjs/ContextInspector/index.js +49 -30
- package/dist/cjs/ContextInspector/index.js.map +1 -1
- package/dist/esm/ContextInspector/index.d.ts +4 -0
- package/dist/esm/ContextInspector/index.js +47 -29
- package/dist/esm/ContextInspector/index.js.map +1 -1
- package/dist/types/ContextInspector/index.d.ts +4 -0
- package/package.json +3 -3
- package/src/ContextInspector/index.tsx +116 -80
- package/types.json +1270 -1183
|
@@ -35,11 +35,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
35
35
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
36
|
};
|
|
37
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
-
exports.ContextInspector = void 0;
|
|
38
|
+
exports.ContextInspector = exports.Group = void 0;
|
|
39
|
+
var datocms_plugin_sdk_1 = require("datocms-plugin-sdk");
|
|
39
40
|
var react_1 = __importStar(require("react"));
|
|
40
41
|
var __1 = require("..");
|
|
41
42
|
var styles_module_css_json_1 = __importDefault(require("./styles.module.css.json"));
|
|
42
|
-
var datocms_plugin_sdk_1 = require("datocms-plugin-sdk");
|
|
43
43
|
var baseUrl = 'https://github.com/datocms/plugins-sdk/blob/master/packages/sdk/';
|
|
44
44
|
function copyTextToClipboard(text) {
|
|
45
45
|
var textArea = document.createElement('textarea');
|
|
@@ -79,9 +79,10 @@ var ExpandablePane = function (_a) {
|
|
|
79
79
|
react_1.default.createElement("button", { type: "button", className: styles_module_css_json_1.default.panelHandle, onClick: function () { return setOpen(function (open) { return !open; }); } }, label),
|
|
80
80
|
open && react_1.default.createElement("div", { className: styles_module_css_json_1.default.panelBody }, children)));
|
|
81
81
|
};
|
|
82
|
-
function
|
|
82
|
+
function Group(_a) {
|
|
83
|
+
var _b, _c;
|
|
84
|
+
var group = _a.group;
|
|
83
85
|
var ctx = (0, __1.useCtx)();
|
|
84
|
-
var hook = datocms_plugin_sdk_1.manifest.hooks[ctx.mode];
|
|
85
86
|
var handleCopy = function (text) {
|
|
86
87
|
copyTextToClipboard(text);
|
|
87
88
|
ctx.notice('Copied to clipboard!');
|
|
@@ -89,35 +90,53 @@ function ContextInspector() {
|
|
|
89
90
|
var handleRun = function (example) {
|
|
90
91
|
Function("\n \"use strict\";\n return(\n async function(ctx) {\n try {\n ".concat(example, "\n } catch(e) {\n console.error(e);\n await ctx.alert('Execution failed! See console for errors!');\n }\n }\n )\n "))()(ctx);
|
|
91
92
|
};
|
|
93
|
+
return (react_1.default.createElement(ExpandablePane, { label: group.name ? capitalize(group.name) : 'Properties and methods', key: group.name },
|
|
94
|
+
((_b = group.comment) === null || _b === void 0 ? void 0 : _b.markdownText) && (react_1.default.createElement("div", { className: styles_module_css_json_1.default.groupDescription }, (_c = group.comment) === null || _c === void 0 ? void 0 : _c.markdownText)),
|
|
95
|
+
react_1.default.createElement("div", { className: styles_module_css_json_1.default.propertyGroup }, Object.entries(group.items).map(function (_a) {
|
|
96
|
+
var _b, _c;
|
|
97
|
+
var name = _a[0], info = _a[1];
|
|
98
|
+
return (react_1.default.createElement("div", { key: name, className: styles_module_css_json_1.default.propertyOrMethod },
|
|
99
|
+
react_1.default.createElement("div", { className: styles_module_css_json_1.default.propertyOrMethodBody },
|
|
100
|
+
react_1.default.createElement("a", { className: styles_module_css_json_1.default.propertyOrMethodName, href: "".concat(baseUrl).concat(info.location.filePath, "#L").concat(info.location.lineNumber), target: "_blank", rel: "noreferrer" },
|
|
101
|
+
name,
|
|
102
|
+
info.type.startsWith('(') ? info.type : ": ".concat(info.type)),
|
|
103
|
+
react_1.default.createElement("div", null, (_b = info.comment) === null || _b === void 0 ? void 0 : _b.markdownText)),
|
|
104
|
+
!info.type.startsWith('(') && (react_1.default.createElement("div", { className: styles_module_css_json_1.default.propertyOrMethodExample },
|
|
105
|
+
react_1.default.createElement("pre", null, JSON.stringify(ctx[name], null, 2)),
|
|
106
|
+
react_1.default.createElement("div", { className: styles_module_css_json_1.default.propertyOrMethodExampleActions },
|
|
107
|
+
react_1.default.createElement(__1.Button, { type: "button", buttonSize: "xxs", onClick: handleCopy.bind(null, JSON.stringify(ctx[name], null, 2)) }, "Copy value")))),
|
|
108
|
+
((_c = info.comment) === null || _c === void 0 ? void 0 : _c.example) && (react_1.default.createElement("div", { className: styles_module_css_json_1.default.propertyOrMethodExample },
|
|
109
|
+
react_1.default.createElement("pre", null, info.comment.example),
|
|
110
|
+
react_1.default.createElement("div", { className: styles_module_css_json_1.default.propertyOrMethodExampleActions },
|
|
111
|
+
react_1.default.createElement(__1.Button, { type: "button", buttonSize: "xxs", buttonType: "primary", onClick: handleRun.bind(null, info.comment.example) }, "Run example"),
|
|
112
|
+
react_1.default.createElement(__1.Button, { type: "button", buttonSize: "xxs", onClick: handleCopy.bind(null, info.comment.example) }, "Copy example"))))));
|
|
113
|
+
}))));
|
|
114
|
+
}
|
|
115
|
+
exports.Group = Group;
|
|
116
|
+
var sortByNameWithNullOnTop = function (a, b) {
|
|
117
|
+
// If both names are null, maintain their original order
|
|
118
|
+
if (!a.name && !b.name)
|
|
119
|
+
return 0;
|
|
120
|
+
// If a's name is null, it should come first
|
|
121
|
+
if (!a.name)
|
|
122
|
+
return -1;
|
|
123
|
+
// If b's name is null, it should come first
|
|
124
|
+
if (!b.name)
|
|
125
|
+
return 1;
|
|
126
|
+
// If neither name is null, use localeCompare for alphabetical sorting
|
|
127
|
+
return a.name.localeCompare(b.name);
|
|
128
|
+
};
|
|
129
|
+
function ContextInspector() {
|
|
130
|
+
var ctx = (0, __1.useCtx)();
|
|
131
|
+
var hook = datocms_plugin_sdk_1.manifest.hooks[ctx.mode];
|
|
92
132
|
if (!hook.ctxArgument) {
|
|
93
133
|
return null;
|
|
94
134
|
}
|
|
95
|
-
var
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
((_a = group.comment) === null || _a === void 0 ? void 0 : _a.comment) && (react_1.default.createElement("div", { className: styles_module_css_json_1.default.groupDescription }, (_b = group.comment) === null || _b === void 0 ? void 0 : _b.comment)),
|
|
101
|
-
Object.entries(group.items).map(function (_a) {
|
|
102
|
-
var _b, _c;
|
|
103
|
-
var name = _a[0], info = _a[1];
|
|
104
|
-
return (react_1.default.createElement("div", { key: name, className: styles_module_css_json_1.default.propertyOrMethod },
|
|
105
|
-
react_1.default.createElement("div", { className: styles_module_css_json_1.default.propertyOrMethodBody },
|
|
106
|
-
react_1.default.createElement("a", { className: styles_module_css_json_1.default.propertyOrMethodName, href: "".concat(baseUrl).concat(info.location.filePath, "#L").concat(info.location.lineNumber), target: "_blank", rel: "noreferrer" },
|
|
107
|
-
name,
|
|
108
|
-
info.type.startsWith('(') ? info.type : ": ".concat(info.type)),
|
|
109
|
-
react_1.default.createElement("div", null, (_b = info.comment) === null || _b === void 0 ? void 0 : _b.comment)),
|
|
110
|
-
!info.type.startsWith('(') && (react_1.default.createElement("div", { className: styles_module_css_json_1.default.propertyOrMethodExample },
|
|
111
|
-
react_1.default.createElement("pre", null, JSON.stringify(ctx[name], null, 2)),
|
|
112
|
-
react_1.default.createElement("div", { className: styles_module_css_json_1.default.propertyOrMethodExampleActions },
|
|
113
|
-
react_1.default.createElement(__1.Button, { type: "button", buttonSize: "xxs", onClick: handleCopy.bind(null, JSON.stringify(ctx[name], null, 2)) }, "Copy value")))),
|
|
114
|
-
((_c = info.comment) === null || _c === void 0 ? void 0 : _c.example) && (react_1.default.createElement("div", { className: styles_module_css_json_1.default.propertyOrMethodExample },
|
|
115
|
-
react_1.default.createElement("pre", null, info.comment.example),
|
|
116
|
-
react_1.default.createElement("div", { className: styles_module_css_json_1.default.propertyOrMethodExampleActions },
|
|
117
|
-
react_1.default.createElement(__1.Button, { type: "button", buttonSize: "xxs", buttonType: "primary", onClick: handleRun.bind(null, info.comment.example) }, "Run example"),
|
|
118
|
-
react_1.default.createElement(__1.Button, { type: "button", buttonSize: "xxs", onClick: handleCopy.bind(null, info.comment.example) }, "Copy example"))))));
|
|
119
|
-
}))));
|
|
120
|
-
})));
|
|
135
|
+
var specific = __spreadArray(__spreadArray([], (hook.ctxArgument.additionalProperties || []), true), (hook.ctxArgument.additionalMethods || []), true).sort(sortByNameWithNullOnTop);
|
|
136
|
+
var base = __spreadArray(__spreadArray([], datocms_plugin_sdk_1.manifest.baseCtx.properties, true), datocms_plugin_sdk_1.manifest.baseCtx.methods, true).sort(sortByNameWithNullOnTop);
|
|
137
|
+
return (react_1.default.createElement("div", { className: styles_module_css_json_1.default.inspector },
|
|
138
|
+
specific.length > 0 && (react_1.default.createElement(ExpandablePane, { label: "Hook-specific" }, specific.map(function (group) { return (react_1.default.createElement(Group, { key: group.name, group: group })); }))),
|
|
139
|
+
react_1.default.createElement(ExpandablePane, { label: "Available on every hook" }, base.map(function (group) { return (react_1.default.createElement(Group, { key: group.name, group: group })); }))));
|
|
121
140
|
}
|
|
122
141
|
exports.ContextInspector = ContextInspector;
|
|
123
142
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/ContextInspector/index.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAAwC;AACxC,wBAAoC;AACpC,oFAAyC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/ContextInspector/index.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yDAA8C;AAE9C,6CAAwC;AACxC,wBAAoC;AACpC,oFAAyC;AAEzC,IAAM,OAAO,GACX,kEAAkE,CAAC;AAErE,SAAS,mBAAmB,CAAC,IAAY;IACvC,IAAM,QAAQ,GAAG,QAAQ,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;IACpD,QAAQ,CAAC,KAAK,CAAC,QAAQ,GAAG,OAAO,CAAC;IAClC,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ACZ,CAAC,IAAI,CAAC,WAAW,CAAC,oBAAoB,IAAI,EAAE,CAAC,SAC7C,CAAC,IAAI,CAAC,WAAW,CAAC,iBAAiB,IAAI,EAAE,CAAC,QAC7C,IAAI,CAAC,uBAAuB,CAAC,CAAC;IAEhC,IAAM,IAAI,GAAG,gCACR,6BAAQ,CAAC,OAAO,CAAC,UAAU,SAC3B,6BAAQ,CAAC,OAAO,CAAC,OAAO,QAC3B,IAAI,CAAC,uBAAuB,CAAC,CAAC;IAEhC,OAAO,CACL,uCAAK,SAAS,EAAE,gCAAC,CAAC,SAAS;QACxB,QAAQ,CAAC,MAAM,GAAG,CAAC,IAAI,CACtB,8BAAC,cAAc,IAAC,KAAK,EAAC,eAAe,IAClC,QAAQ,CAAC,GAAG,CAAC,UAAC,KAAK,IAAK,OAAA,CACvB,8BAAC,KAAK,IAAC,GAAG,EAAE,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,GAAI,CACzC,EAFwB,CAExB,CAAC,CACa,CAClB;QACD,8BAAC,cAAc,IAAC,KAAK,EAAC,yBAAyB,IAC5C,IAAI,CAAC,GAAG,CAAC,UAAC,KAAK,IAAK,OAAA,CACnB,8BAAC,KAAK,IAAC,GAAG,EAAE,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,GAAI,CACzC,EAFoB,CAEpB,CAAC,CACa,CACb,CACP,CAAC;AACJ,CAAC;AAnCD,4CAmCC"}
|
|
@@ -1,2 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
+
import { PropertiesOrMethodsGroup } from 'datocms-plugin-sdk/dist/types/manifestTypes';
|
|
3
|
+
export declare function Group({ group, }: {
|
|
4
|
+
group: PropertiesOrMethodsGroup;
|
|
5
|
+
}): JSX.Element;
|
|
2
6
|
export declare function ContextInspector(): JSX.Element | null;
|
|
@@ -7,10 +7,10 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
7
7
|
}
|
|
8
8
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
9
9
|
};
|
|
10
|
+
import { manifest } from 'datocms-plugin-sdk';
|
|
10
11
|
import React, { useState } from 'react';
|
|
11
12
|
import { Button, useCtx } from '..';
|
|
12
13
|
import s from './styles.module.css.json';
|
|
13
|
-
import { manifest } from 'datocms-plugin-sdk';
|
|
14
14
|
var baseUrl = 'https://github.com/datocms/plugins-sdk/blob/master/packages/sdk/';
|
|
15
15
|
function copyTextToClipboard(text) {
|
|
16
16
|
var textArea = document.createElement('textarea');
|
|
@@ -50,9 +50,10 @@ var ExpandablePane = function (_a) {
|
|
|
50
50
|
React.createElement("button", { type: "button", className: s.panelHandle, onClick: function () { return setOpen(function (open) { return !open; }); } }, label),
|
|
51
51
|
open && React.createElement("div", { className: s.panelBody }, children)));
|
|
52
52
|
};
|
|
53
|
-
export function
|
|
53
|
+
export function Group(_a) {
|
|
54
|
+
var _b, _c;
|
|
55
|
+
var group = _a.group;
|
|
54
56
|
var ctx = useCtx();
|
|
55
|
-
var hook = manifest.hooks[ctx.mode];
|
|
56
57
|
var handleCopy = function (text) {
|
|
57
58
|
copyTextToClipboard(text);
|
|
58
59
|
ctx.notice('Copied to clipboard!');
|
|
@@ -60,34 +61,51 @@ export function ContextInspector() {
|
|
|
60
61
|
var handleRun = function (example) {
|
|
61
62
|
Function("\n \"use strict\";\n return(\n async function(ctx) {\n try {\n ".concat(example, "\n } catch(e) {\n console.error(e);\n await ctx.alert('Execution failed! See console for errors!');\n }\n }\n )\n "))()(ctx);
|
|
62
63
|
};
|
|
64
|
+
return (React.createElement(ExpandablePane, { label: group.name ? capitalize(group.name) : 'Properties and methods', key: group.name },
|
|
65
|
+
((_b = group.comment) === null || _b === void 0 ? void 0 : _b.markdownText) && (React.createElement("div", { className: s.groupDescription }, (_c = group.comment) === null || _c === void 0 ? void 0 : _c.markdownText)),
|
|
66
|
+
React.createElement("div", { className: s.propertyGroup }, Object.entries(group.items).map(function (_a) {
|
|
67
|
+
var _b, _c;
|
|
68
|
+
var name = _a[0], info = _a[1];
|
|
69
|
+
return (React.createElement("div", { key: name, className: s.propertyOrMethod },
|
|
70
|
+
React.createElement("div", { className: s.propertyOrMethodBody },
|
|
71
|
+
React.createElement("a", { className: s.propertyOrMethodName, href: "".concat(baseUrl).concat(info.location.filePath, "#L").concat(info.location.lineNumber), target: "_blank", rel: "noreferrer" },
|
|
72
|
+
name,
|
|
73
|
+
info.type.startsWith('(') ? info.type : ": ".concat(info.type)),
|
|
74
|
+
React.createElement("div", null, (_b = info.comment) === null || _b === void 0 ? void 0 : _b.markdownText)),
|
|
75
|
+
!info.type.startsWith('(') && (React.createElement("div", { className: s.propertyOrMethodExample },
|
|
76
|
+
React.createElement("pre", null, JSON.stringify(ctx[name], null, 2)),
|
|
77
|
+
React.createElement("div", { className: s.propertyOrMethodExampleActions },
|
|
78
|
+
React.createElement(Button, { type: "button", buttonSize: "xxs", onClick: handleCopy.bind(null, JSON.stringify(ctx[name], null, 2)) }, "Copy value")))),
|
|
79
|
+
((_c = info.comment) === null || _c === void 0 ? void 0 : _c.example) && (React.createElement("div", { className: s.propertyOrMethodExample },
|
|
80
|
+
React.createElement("pre", null, info.comment.example),
|
|
81
|
+
React.createElement("div", { className: s.propertyOrMethodExampleActions },
|
|
82
|
+
React.createElement(Button, { type: "button", buttonSize: "xxs", buttonType: "primary", onClick: handleRun.bind(null, info.comment.example) }, "Run example"),
|
|
83
|
+
React.createElement(Button, { type: "button", buttonSize: "xxs", onClick: handleCopy.bind(null, info.comment.example) }, "Copy example"))))));
|
|
84
|
+
}))));
|
|
85
|
+
}
|
|
86
|
+
var sortByNameWithNullOnTop = function (a, b) {
|
|
87
|
+
// If both names are null, maintain their original order
|
|
88
|
+
if (!a.name && !b.name)
|
|
89
|
+
return 0;
|
|
90
|
+
// If a's name is null, it should come first
|
|
91
|
+
if (!a.name)
|
|
92
|
+
return -1;
|
|
93
|
+
// If b's name is null, it should come first
|
|
94
|
+
if (!b.name)
|
|
95
|
+
return 1;
|
|
96
|
+
// If neither name is null, use localeCompare for alphabetical sorting
|
|
97
|
+
return a.name.localeCompare(b.name);
|
|
98
|
+
};
|
|
99
|
+
export function ContextInspector() {
|
|
100
|
+
var ctx = useCtx();
|
|
101
|
+
var hook = manifest.hooks[ctx.mode];
|
|
63
102
|
if (!hook.ctxArgument) {
|
|
64
103
|
return null;
|
|
65
104
|
}
|
|
66
|
-
var
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
((_a = group.comment) === null || _a === void 0 ? void 0 : _a.comment) && (React.createElement("div", { className: s.groupDescription }, (_b = group.comment) === null || _b === void 0 ? void 0 : _b.comment)),
|
|
72
|
-
Object.entries(group.items).map(function (_a) {
|
|
73
|
-
var _b, _c;
|
|
74
|
-
var name = _a[0], info = _a[1];
|
|
75
|
-
return (React.createElement("div", { key: name, className: s.propertyOrMethod },
|
|
76
|
-
React.createElement("div", { className: s.propertyOrMethodBody },
|
|
77
|
-
React.createElement("a", { className: s.propertyOrMethodName, href: "".concat(baseUrl).concat(info.location.filePath, "#L").concat(info.location.lineNumber), target: "_blank", rel: "noreferrer" },
|
|
78
|
-
name,
|
|
79
|
-
info.type.startsWith('(') ? info.type : ": ".concat(info.type)),
|
|
80
|
-
React.createElement("div", null, (_b = info.comment) === null || _b === void 0 ? void 0 : _b.comment)),
|
|
81
|
-
!info.type.startsWith('(') && (React.createElement("div", { className: s.propertyOrMethodExample },
|
|
82
|
-
React.createElement("pre", null, JSON.stringify(ctx[name], null, 2)),
|
|
83
|
-
React.createElement("div", { className: s.propertyOrMethodExampleActions },
|
|
84
|
-
React.createElement(Button, { type: "button", buttonSize: "xxs", onClick: handleCopy.bind(null, JSON.stringify(ctx[name], null, 2)) }, "Copy value")))),
|
|
85
|
-
((_c = info.comment) === null || _c === void 0 ? void 0 : _c.example) && (React.createElement("div", { className: s.propertyOrMethodExample },
|
|
86
|
-
React.createElement("pre", null, info.comment.example),
|
|
87
|
-
React.createElement("div", { className: s.propertyOrMethodExampleActions },
|
|
88
|
-
React.createElement(Button, { type: "button", buttonSize: "xxs", buttonType: "primary", onClick: handleRun.bind(null, info.comment.example) }, "Run example"),
|
|
89
|
-
React.createElement(Button, { type: "button", buttonSize: "xxs", onClick: handleCopy.bind(null, info.comment.example) }, "Copy example"))))));
|
|
90
|
-
}))));
|
|
91
|
-
})));
|
|
105
|
+
var specific = __spreadArray(__spreadArray([], (hook.ctxArgument.additionalProperties || []), true), (hook.ctxArgument.additionalMethods || []), true).sort(sortByNameWithNullOnTop);
|
|
106
|
+
var base = __spreadArray(__spreadArray([], manifest.baseCtx.properties, true), manifest.baseCtx.methods, true).sort(sortByNameWithNullOnTop);
|
|
107
|
+
return (React.createElement("div", { className: s.inspector },
|
|
108
|
+
specific.length > 0 && (React.createElement(ExpandablePane, { label: "Hook-specific" }, specific.map(function (group) { return (React.createElement(Group, { key: group.name, group: group })); }))),
|
|
109
|
+
React.createElement(ExpandablePane, { label: "Available on every hook" }, base.map(function (group) { return (React.createElement(Group, { key: group.name, group: group })); }))));
|
|
92
110
|
}
|
|
93
111
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/ContextInspector/index.tsx"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,KAAK,EAAE,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AACpC,OAAO,CAAC,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/ContextInspector/index.tsx"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAE9C,OAAO,KAAK,EAAE,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;A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G,MAAM,EAAE,CAAC;IAErB,IAAM,IAAI,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAEtC,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE;QACrB,OAAO,IAAI,CAAC;KACb;IAED,IAAM,QAAQ,GAAG,gCACZ,CAAC,IAAI,CAAC,WAAW,CAAC,oBAAoB,IAAI,EAAE,CAAC,SAC7C,CAAC,IAAI,CAAC,WAAW,CAAC,iBAAiB,IAAI,EAAE,CAAC,QAC7C,IAAI,CAAC,uBAAuB,CAAC,CAAC;IAEhC,IAAM,IAAI,GAAG,gCACR,QAAQ,CAAC,OAAO,CAAC,UAAU,SAC3B,QAAQ,CAAC,OAAO,CAAC,OAAO,QAC3B,IAAI,CAAC,uBAAuB,CAAC,CAAC;IAEhC,OAAO,CACL,6BAAK,SAAS,EAAE,CAAC,CAAC,SAAS;QACxB,QAAQ,CAAC,MAAM,GAAG,CAAC,IAAI,CACtB,oBAAC,cAAc,IAAC,KAAK,EAAC,eAAe,IAClC,QAAQ,CAAC,GAAG,CAAC,UAAC,KAAK,IAAK,OAAA,CACvB,oBAAC,KAAK,IAAC,GAAG,EAAE,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,GAAI,CACzC,EAFwB,CAExB,CAAC,CACa,CAClB;QACD,oBAAC,cAAc,IAAC,KAAK,EAAC,yBAAyB,IAC5C,IAAI,CAAC,GAAG,CAAC,UAAC,KAAK,IAAK,OAAA,CACnB,oBAAC,KAAK,IAAC,GAAG,EAAE,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,GAAI,CACzC,EAFoB,CAEpB,CAAC,CACa,CACb,CACP,CAAC;AACJ,CAAC"}
|
|
@@ -1,2 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
+
import { PropertiesOrMethodsGroup } from 'datocms-plugin-sdk/dist/types/manifestTypes';
|
|
3
|
+
export declare function Group({ group, }: {
|
|
4
|
+
group: PropertiesOrMethodsGroup;
|
|
5
|
+
}): JSX.Element;
|
|
2
6
|
export declare function ContextInspector(): JSX.Element | null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "datocms-react-ui",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.3",
|
|
4
4
|
"description": "React components to use inside DatoCMS plugins",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"datocms",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"classnames": "^2.3.1",
|
|
44
|
-
"datocms-plugin-sdk": "^2.0.
|
|
44
|
+
"datocms-plugin-sdk": "^2.0.3",
|
|
45
45
|
"react-intersection-observer": "^8.31.0",
|
|
46
46
|
"react-select": "^5.2.1",
|
|
47
47
|
"scroll-into-view-if-needed": "^2.2.20"
|
|
@@ -57,5 +57,5 @@
|
|
|
57
57
|
"postcss-nested": "^5.0.6",
|
|
58
58
|
"typedoc": "^0.23.20"
|
|
59
59
|
},
|
|
60
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "b505f6681411e687cd6908661d73670ecaf8a584"
|
|
61
61
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { manifest } from 'datocms-plugin-sdk';
|
|
2
|
+
import { PropertiesOrMethodsGroup } from 'datocms-plugin-sdk/dist/types/manifestTypes';
|
|
1
3
|
import React, { useState } from 'react';
|
|
2
4
|
import { Button, useCtx } from '..';
|
|
3
5
|
import s from './styles.module.css.json';
|
|
4
|
-
import { manifest } from 'datocms-plugin-sdk';
|
|
5
6
|
|
|
6
7
|
const baseUrl =
|
|
7
8
|
'https://github.com/datocms/plugins-sdk/blob/master/packages/sdk/';
|
|
@@ -57,11 +58,11 @@ const ExpandablePane = ({ children, label }: any) => {
|
|
|
57
58
|
);
|
|
58
59
|
};
|
|
59
60
|
|
|
60
|
-
export function
|
|
61
|
+
export function Group({
|
|
62
|
+
group,
|
|
63
|
+
}: { group: PropertiesOrMethodsGroup }): JSX.Element {
|
|
61
64
|
const ctx = useCtx();
|
|
62
65
|
|
|
63
|
-
const hook = manifest.hooks[ctx.mode];
|
|
64
|
-
|
|
65
66
|
const handleCopy = (text: string) => {
|
|
66
67
|
copyTextToClipboard(text);
|
|
67
68
|
(ctx as any).notice('Copied to clipboard!');
|
|
@@ -85,91 +86,126 @@ export function ContextInspector(): JSX.Element | null {
|
|
|
85
86
|
)()(ctx);
|
|
86
87
|
};
|
|
87
88
|
|
|
89
|
+
return (
|
|
90
|
+
<ExpandablePane
|
|
91
|
+
label={group.name ? capitalize(group.name) : 'Properties and methods'}
|
|
92
|
+
key={group.name}
|
|
93
|
+
>
|
|
94
|
+
{group.comment?.markdownText && (
|
|
95
|
+
<div className={s.groupDescription}>{group.comment?.markdownText}</div>
|
|
96
|
+
)}
|
|
97
|
+
<div className={s.propertyGroup}>
|
|
98
|
+
{Object.entries(group.items).map(([name, info]) => (
|
|
99
|
+
<div key={name} className={s.propertyOrMethod}>
|
|
100
|
+
<div className={s.propertyOrMethodBody}>
|
|
101
|
+
<a
|
|
102
|
+
className={s.propertyOrMethodName}
|
|
103
|
+
href={`${baseUrl}${info.location.filePath}#L${info.location.lineNumber}`}
|
|
104
|
+
target="_blank"
|
|
105
|
+
rel="noreferrer"
|
|
106
|
+
>
|
|
107
|
+
{name}
|
|
108
|
+
{info.type.startsWith('(') ? info.type : `: ${info.type}`}
|
|
109
|
+
</a>
|
|
110
|
+
|
|
111
|
+
<div>{info.comment?.markdownText}</div>
|
|
112
|
+
</div>
|
|
113
|
+
{!info.type.startsWith('(') && (
|
|
114
|
+
<div className={s.propertyOrMethodExample}>
|
|
115
|
+
<pre>{JSON.stringify((ctx as any)[name], null, 2)}</pre>
|
|
116
|
+
<div className={s.propertyOrMethodExampleActions}>
|
|
117
|
+
<Button
|
|
118
|
+
type="button"
|
|
119
|
+
buttonSize="xxs"
|
|
120
|
+
onClick={handleCopy.bind(
|
|
121
|
+
null,
|
|
122
|
+
JSON.stringify((ctx as any)[name], null, 2),
|
|
123
|
+
)}
|
|
124
|
+
>
|
|
125
|
+
Copy value
|
|
126
|
+
</Button>
|
|
127
|
+
</div>
|
|
128
|
+
</div>
|
|
129
|
+
)}
|
|
130
|
+
{info.comment?.example && (
|
|
131
|
+
<div className={s.propertyOrMethodExample}>
|
|
132
|
+
<pre>{info.comment.example}</pre>
|
|
133
|
+
<div className={s.propertyOrMethodExampleActions}>
|
|
134
|
+
<Button
|
|
135
|
+
type="button"
|
|
136
|
+
buttonSize="xxs"
|
|
137
|
+
buttonType="primary"
|
|
138
|
+
onClick={handleRun.bind(null, info.comment.example)}
|
|
139
|
+
>
|
|
140
|
+
Run example
|
|
141
|
+
</Button>
|
|
142
|
+
<Button
|
|
143
|
+
type="button"
|
|
144
|
+
buttonSize="xxs"
|
|
145
|
+
onClick={handleCopy.bind(null, info.comment.example)}
|
|
146
|
+
>
|
|
147
|
+
Copy example
|
|
148
|
+
</Button>
|
|
149
|
+
</div>
|
|
150
|
+
</div>
|
|
151
|
+
)}
|
|
152
|
+
</div>
|
|
153
|
+
))}
|
|
154
|
+
</div>
|
|
155
|
+
</ExpandablePane>
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const sortByNameWithNullOnTop = (
|
|
160
|
+
a: { name?: string },
|
|
161
|
+
b: { name?: string },
|
|
162
|
+
): number => {
|
|
163
|
+
// If both names are null, maintain their original order
|
|
164
|
+
if (!a.name && !b.name) return 0;
|
|
165
|
+
|
|
166
|
+
// If a's name is null, it should come first
|
|
167
|
+
if (!a.name) return -1;
|
|
168
|
+
|
|
169
|
+
// If b's name is null, it should come first
|
|
170
|
+
if (!b.name) return 1;
|
|
171
|
+
|
|
172
|
+
// If neither name is null, use localeCompare for alphabetical sorting
|
|
173
|
+
return a.name.localeCompare(b.name);
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
export function ContextInspector(): JSX.Element | null {
|
|
177
|
+
const ctx = useCtx();
|
|
178
|
+
|
|
179
|
+
const hook = manifest.hooks[ctx.mode];
|
|
180
|
+
|
|
88
181
|
if (!hook.ctxArgument) {
|
|
89
182
|
return null;
|
|
90
183
|
}
|
|
91
184
|
|
|
92
|
-
const
|
|
93
|
-
...manifest.baseCtx.properties,
|
|
185
|
+
const specific = [
|
|
94
186
|
...(hook.ctxArgument.additionalProperties || []),
|
|
95
|
-
...manifest.baseCtx.methods,
|
|
96
187
|
...(hook.ctxArgument.additionalMethods || []),
|
|
97
|
-
];
|
|
188
|
+
].sort(sortByNameWithNullOnTop);
|
|
189
|
+
|
|
190
|
+
const base = [
|
|
191
|
+
...manifest.baseCtx.properties,
|
|
192
|
+
...manifest.baseCtx.methods,
|
|
193
|
+
].sort(sortByNameWithNullOnTop);
|
|
98
194
|
|
|
99
195
|
return (
|
|
100
196
|
<div className={s.inspector}>
|
|
101
|
-
{
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
{Object.entries(group.items).map(([name, info]) => (
|
|
114
|
-
<div key={name} className={s.propertyOrMethod}>
|
|
115
|
-
<div className={s.propertyOrMethodBody}>
|
|
116
|
-
<a
|
|
117
|
-
className={s.propertyOrMethodName}
|
|
118
|
-
href={`${baseUrl}${info.location.filePath}#L${info.location.lineNumber}`}
|
|
119
|
-
target="_blank"
|
|
120
|
-
rel="noreferrer"
|
|
121
|
-
>
|
|
122
|
-
{name}
|
|
123
|
-
{info.type.startsWith('(') ? info.type : `: ${info.type}`}
|
|
124
|
-
</a>
|
|
125
|
-
|
|
126
|
-
<div>{info.comment?.comment}</div>
|
|
127
|
-
</div>
|
|
128
|
-
{!info.type.startsWith('(') && (
|
|
129
|
-
<div className={s.propertyOrMethodExample}>
|
|
130
|
-
<pre>{JSON.stringify((ctx as any)[name], null, 2)}</pre>
|
|
131
|
-
<div className={s.propertyOrMethodExampleActions}>
|
|
132
|
-
<Button
|
|
133
|
-
type="button"
|
|
134
|
-
buttonSize="xxs"
|
|
135
|
-
onClick={handleCopy.bind(
|
|
136
|
-
null,
|
|
137
|
-
JSON.stringify((ctx as any)[name], null, 2),
|
|
138
|
-
)}
|
|
139
|
-
>
|
|
140
|
-
Copy value
|
|
141
|
-
</Button>
|
|
142
|
-
</div>
|
|
143
|
-
</div>
|
|
144
|
-
)}
|
|
145
|
-
{info.comment?.example && (
|
|
146
|
-
<div className={s.propertyOrMethodExample}>
|
|
147
|
-
<pre>{info.comment.example}</pre>
|
|
148
|
-
<div className={s.propertyOrMethodExampleActions}>
|
|
149
|
-
<Button
|
|
150
|
-
type="button"
|
|
151
|
-
buttonSize="xxs"
|
|
152
|
-
buttonType="primary"
|
|
153
|
-
onClick={handleRun.bind(null, info.comment.example)}
|
|
154
|
-
>
|
|
155
|
-
Run example
|
|
156
|
-
</Button>
|
|
157
|
-
<Button
|
|
158
|
-
type="button"
|
|
159
|
-
buttonSize="xxs"
|
|
160
|
-
onClick={handleCopy.bind(null, info.comment.example)}
|
|
161
|
-
>
|
|
162
|
-
Copy example
|
|
163
|
-
</Button>
|
|
164
|
-
</div>
|
|
165
|
-
</div>
|
|
166
|
-
)}
|
|
167
|
-
</div>
|
|
168
|
-
))}
|
|
169
|
-
</div>
|
|
170
|
-
</ExpandablePane>
|
|
171
|
-
);
|
|
172
|
-
})}
|
|
197
|
+
{specific.length > 0 && (
|
|
198
|
+
<ExpandablePane label="Hook-specific">
|
|
199
|
+
{specific.map((group) => (
|
|
200
|
+
<Group key={group.name} group={group} />
|
|
201
|
+
))}
|
|
202
|
+
</ExpandablePane>
|
|
203
|
+
)}
|
|
204
|
+
<ExpandablePane label="Available on every hook">
|
|
205
|
+
{base.map((group) => (
|
|
206
|
+
<Group key={group.name} group={group} />
|
|
207
|
+
))}
|
|
208
|
+
</ExpandablePane>
|
|
173
209
|
</div>
|
|
174
210
|
);
|
|
175
211
|
}
|