sanity-plugin-graph-view 1.0.4 → 2.0.0
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/LICENSE +1 -1
- package/README.md +78 -28
- package/lib/index.esm.js +2 -0
- package/lib/index.esm.js.map +1 -0
- package/lib/index.js +2 -0
- package/lib/index.js.map +1 -0
- package/lib/src/index.d.ts +9 -0
- package/package.json +79 -31
- package/sanity.json +2 -6
- package/src/index.ts +1 -0
- package/src/plugin.tsx +30 -0
- package/src/tool/GraphView.tsx +489 -0
- package/{lib/tool/GraphToolIcon.js → src/tool/GraphViewIcon.tsx} +9 -28
- package/src/tool/GraphViewStyle.tsx +63 -0
- package/src/tool/hooks.ts +36 -0
- package/src/tool/utils.ts +51 -0
- package/v2-incompatible.js +11 -0
- package/.editorconfig +0 -16
- package/.eslintignore +0 -1
- package/.eslintrc.js +0 -18
- package/.prettierrc +0 -6
- package/assets/head-silhouette.jpg +0 -0
- package/assets/sanity-logo.png +0 -0
- package/assets/screengrab.gif +0 -0
- package/babel.config.js +0 -13
- package/config.dist.json +0 -1
- package/lib/tool/GraphTool.css +0 -56
- package/lib/tool/GraphTool.js +0 -980
- package/lib/tool/GraphView.css +0 -56
- package/lib/tool/GraphView.js +0 -724
- package/lib/tool/GraphViewIcon.js +0 -32
- package/lib/tool/hooks.js +0 -33
- package/lib/tool/index.js +0 -21
- package/lib/tool/utils.js +0 -76
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.GraphViewIcon = void 0;
|
|
9
|
-
|
|
10
|
-
var _react = _interopRequireDefault(require("react"));
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Couple of things to note:
|
|
14
|
-
* - width and height is set to 1em
|
|
15
|
-
* - fill is `currentColor` - this will ensure that the icon looks uniform and
|
|
16
|
-
* that the hover/active state works. You can of course render anything you
|
|
17
|
-
* would like here, but for plugins that are to be used in more than one
|
|
18
|
-
* studio, we suggest these rules are followed
|
|
19
|
-
**/
|
|
20
|
-
var GraphViewIcon = function GraphViewIcon() {
|
|
21
|
-
return /*#__PURE__*/_react["default"].createElement("svg", {
|
|
22
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
23
|
-
width: "1em",
|
|
24
|
-
height: "1em",
|
|
25
|
-
viewBox: "0 0 46.063 46.063"
|
|
26
|
-
}, /*#__PURE__*/_react["default"].createElement("path", {
|
|
27
|
-
fill: "currentColor",
|
|
28
|
-
d: "M18.022 38.676v2.813h-1.21q-4.864 0-6.525-1.447-1.64-1.445-1.64-5.762v-4.666q0-2.95-1.055-4.083-1.055-1.13-3.828-1.13h-1.19v-2.794h1.19q2.793 0 3.828-1.114 1.055-1.132 1.055-4.043V11.76q0-4.316 1.64-5.742 1.66-1.446 6.524-1.446h1.212v2.793h-1.328q-2.754 0-3.594.86-.84.86-.84 3.613v4.844q0 3.066-.898 4.453-.88 1.387-3.028 1.875 2.168.527 3.047 1.914.88 1.387.88 4.434v4.843q0 2.754.84 3.614.84.86 3.594.86h1.328zM28.04 38.676h1.368q2.735 0 3.555-.84.84-.84.84-3.633V29.36q0-3.047.88-4.434.878-1.387 3.046-1.914-2.17-.488-3.048-1.875-.88-1.387-.88-4.453V11.84q0-2.773-.84-3.613-.82-.86-3.554-.86H28.04V4.574h1.232q4.863 0 6.484 1.446 1.64 1.426 1.64 5.742v4.687q0 2.91 1.055 4.042 1.056 1.114 3.83 1.114h1.21V24.4h-1.21q-2.774 0-3.83 1.13-1.053 1.134-1.053 4.084v4.667q0 4.318-1.64 5.763-1.622 1.446-6.485 1.446h-1.23v-2.814z"
|
|
29
|
-
}));
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
exports.GraphViewIcon = GraphViewIcon;
|
package/lib/tool/hooks.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.useListen = useListen;
|
|
9
|
-
exports.useFetchDocuments = useFetchDocuments;
|
|
10
|
-
|
|
11
|
-
var _react = require("react");
|
|
12
|
-
|
|
13
|
-
var _client = _interopRequireDefault(require("part:@sanity/base/client"));
|
|
14
|
-
|
|
15
|
-
function useListen(query, params, options, onUpdate, dependencies) {
|
|
16
|
-
(0, _react.useEffect)(function () {
|
|
17
|
-
var subscription = _client["default"].listen(query, params, options).subscribe(function (update) {
|
|
18
|
-
onUpdate(update);
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
return function () {
|
|
22
|
-
subscription.unsubscribe();
|
|
23
|
-
};
|
|
24
|
-
}, dependencies);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function useFetchDocuments(query, onFetch, dependencies) {
|
|
28
|
-
(0, _react.useEffect)(function () {
|
|
29
|
-
_client["default"].fetch(query).then(function (result) {
|
|
30
|
-
onFetch(result);
|
|
31
|
-
});
|
|
32
|
-
}, dependencies);
|
|
33
|
-
}
|
package/lib/tool/index.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports["default"] = void 0;
|
|
7
|
-
|
|
8
|
-
var _router = require("part:@sanity/base/router");
|
|
9
|
-
|
|
10
|
-
var _GraphView = require("./GraphView");
|
|
11
|
-
|
|
12
|
-
var _GraphViewIcon = require("./GraphViewIcon");
|
|
13
|
-
|
|
14
|
-
var _default = {
|
|
15
|
-
title: 'Graph',
|
|
16
|
-
name: 'graph-your-content',
|
|
17
|
-
router: (0, _router.route)('/:selectedDocumentId'),
|
|
18
|
-
icon: _GraphViewIcon.GraphViewIcon,
|
|
19
|
-
component: _GraphView.GraphView
|
|
20
|
-
};
|
|
21
|
-
exports["default"] = _default;
|
package/lib/tool/utils.js
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.sizeOf = sizeOf;
|
|
9
|
-
exports.loadImage = loadImage;
|
|
10
|
-
exports.sortBy = sortBy;
|
|
11
|
-
exports.truncate = truncate;
|
|
12
|
-
|
|
13
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
14
|
-
|
|
15
|
-
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
16
|
-
|
|
17
|
-
function sizeOf(value) {
|
|
18
|
-
if (value == null) {
|
|
19
|
-
return 0;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
if ((0, _typeof2["default"])(value) === 'object') {
|
|
23
|
-
return Object.entries(value).reduce(function (total, _ref) {
|
|
24
|
-
var _ref2 = (0, _slicedToArray2["default"])(_ref, 2),
|
|
25
|
-
k = _ref2[0],
|
|
26
|
-
v = _ref2[1];
|
|
27
|
-
|
|
28
|
-
return total + sizeOf(k) + sizeOf(v);
|
|
29
|
-
}, 0);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
if (Array.isArray(value)) {
|
|
33
|
-
return Object.entries(value).reduce(function (total, v) {
|
|
34
|
-
return total + sizeOf(v);
|
|
35
|
-
}, 0);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if (typeof value === 'string') {
|
|
39
|
-
return value.length;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return 1;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function loadImage(url, w, h) {
|
|
46
|
-
return new Promise(function (resolve) {
|
|
47
|
-
var img = new Image(w, h);
|
|
48
|
-
|
|
49
|
-
img.onload = function () {
|
|
50
|
-
resolve(img);
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
img.onerror = function (event) {
|
|
54
|
-
console.log('Image error', event);
|
|
55
|
-
resolve(null);
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
img.src = url;
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function sortBy(array, f) {
|
|
63
|
-
return array.sort(function (a, b) {
|
|
64
|
-
var va = f(a);
|
|
65
|
-
var vb = f(b);
|
|
66
|
-
return va < vb ? -1 : va > vb ? 1 : 0;
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function truncate(s, limit) {
|
|
71
|
-
if (s.length > limit) {
|
|
72
|
-
s = s.substring(0, limit) + '…';
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
return s;
|
|
76
|
-
}
|