@graffy/explore 0.15.25-alpha.3 → 0.15.25-alpha.5
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/package.json +7 -12
- package/index.cjs +0 -193
package/package.json
CHANGED
|
@@ -2,13 +2,8 @@
|
|
|
2
2
|
"name": "@graffy/explore",
|
|
3
3
|
"description": "Graffy client library for the browser.",
|
|
4
4
|
"author": "aravind (https://github.com/aravindet)",
|
|
5
|
-
"version": "0.15.25-alpha.
|
|
6
|
-
"main": "./index.
|
|
7
|
-
"exports": {
|
|
8
|
-
"import": "./index.mjs",
|
|
9
|
-
"require": "./index.cjs"
|
|
10
|
-
},
|
|
11
|
-
"module": "./index.mjs",
|
|
5
|
+
"version": "0.15.25-alpha.5",
|
|
6
|
+
"main": "./index.mjs",
|
|
12
7
|
"types": "./types/index.d.ts",
|
|
13
8
|
"repository": {
|
|
14
9
|
"type": "git",
|
|
@@ -16,11 +11,11 @@
|
|
|
16
11
|
},
|
|
17
12
|
"license": "Apache-2.0",
|
|
18
13
|
"dependencies": {
|
|
19
|
-
"@graffy/core": "0.15.25-alpha.
|
|
20
|
-
"@graffy/fill": "0.15.25-alpha.
|
|
21
|
-
"@graffy/client": "0.15.25-alpha.
|
|
22
|
-
"@graffy/react": "0.15.25-alpha.
|
|
23
|
-
"@graffy/common": "0.15.25-alpha.
|
|
14
|
+
"@graffy/core": "0.15.25-alpha.5",
|
|
15
|
+
"@graffy/fill": "0.15.25-alpha.5",
|
|
16
|
+
"@graffy/client": "0.15.25-alpha.5",
|
|
17
|
+
"@graffy/react": "0.15.25-alpha.5",
|
|
18
|
+
"@graffy/common": "0.15.25-alpha.5"
|
|
24
19
|
},
|
|
25
20
|
"peerDependencies": {
|
|
26
21
|
"react": "^16.8.0 || ^17.0.0"
|
package/index.cjs
DELETED
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
const React = require("react");
|
|
3
|
-
const Graffy = require("@graffy/core");
|
|
4
|
-
const GraffyFill = require("@graffy/fill");
|
|
5
|
-
const GraffyClient = require("@graffy/client");
|
|
6
|
-
const react = require("@graffy/react");
|
|
7
|
-
const common = require("@graffy/common");
|
|
8
|
-
const _interopDefaultLegacy = (e) => e && typeof e === "object" && "default" in e ? e : { default: e };
|
|
9
|
-
function _interopNamespace(e) {
|
|
10
|
-
if (e && e.__esModule)
|
|
11
|
-
return e;
|
|
12
|
-
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
13
|
-
if (e) {
|
|
14
|
-
for (const k in e) {
|
|
15
|
-
if (k !== "default") {
|
|
16
|
-
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
17
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
18
|
-
enumerable: true,
|
|
19
|
-
get: () => e[k]
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
n.default = e;
|
|
25
|
-
return Object.freeze(n);
|
|
26
|
-
}
|
|
27
|
-
const React__default = /* @__PURE__ */ _interopDefaultLegacy(React);
|
|
28
|
-
const Graffy__default = /* @__PURE__ */ _interopDefaultLegacy(Graffy);
|
|
29
|
-
const GraffyFill__default = /* @__PURE__ */ _interopDefaultLegacy(GraffyFill);
|
|
30
|
-
const GraffyClient__default = /* @__PURE__ */ _interopDefaultLegacy(GraffyClient);
|
|
31
|
-
const common__namespace = /* @__PURE__ */ _interopNamespace(common);
|
|
32
|
-
function Result({ result, loading, error }) {
|
|
33
|
-
return /* @__PURE__ */ React__default.default.createElement(React__default.default.Fragment, null, loading ? /* @__PURE__ */ React__default.default.createElement("div", {
|
|
34
|
-
className: "status"
|
|
35
|
-
}, "Loading...") : error ? /* @__PURE__ */ React__default.default.createElement("div", {
|
|
36
|
-
className: "error"
|
|
37
|
-
}, error.toString()) : result ? /* @__PURE__ */ React__default.default.createElement("pre", null, JSON.stringify(result, null, 2)) : /* @__PURE__ */ React__default.default.createElement("div", {
|
|
38
|
-
className: "status"
|
|
39
|
-
}, "No results"), /* @__PURE__ */ React__default.default.createElement("style", {
|
|
40
|
-
jsx: true
|
|
41
|
-
}, `
|
|
42
|
-
.error {
|
|
43
|
-
color: #c00;
|
|
44
|
-
padding: 1rem;
|
|
45
|
-
}
|
|
46
|
-
.status {
|
|
47
|
-
color: #888;
|
|
48
|
-
padding: 1rem;
|
|
49
|
-
}
|
|
50
|
-
`));
|
|
51
|
-
}
|
|
52
|
-
function evaluate(expression) {
|
|
53
|
-
const names = Object.keys(common__namespace);
|
|
54
|
-
const fn = new Function(...names, `return ${expression};`);
|
|
55
|
-
return fn(...names.map((name) => common__namespace[name]));
|
|
56
|
-
}
|
|
57
|
-
function Explore(options) {
|
|
58
|
-
const [input, setInput] = React.useState({});
|
|
59
|
-
const [error, setError] = React.useState(null);
|
|
60
|
-
const [loading, setLoading] = React.useState(false);
|
|
61
|
-
const [result, setResult] = React.useState(null);
|
|
62
|
-
const [watching, setWatching] = React.useState(null);
|
|
63
|
-
const store = react.useStore();
|
|
64
|
-
const onInputEnd = React.useCallback(
|
|
65
|
-
(event) => {
|
|
66
|
-
try {
|
|
67
|
-
setInput(evaluate(event.target.textContent));
|
|
68
|
-
} catch (e) {
|
|
69
|
-
setError(e.message);
|
|
70
|
-
}
|
|
71
|
-
},
|
|
72
|
-
[setInput, setError]
|
|
73
|
-
);
|
|
74
|
-
const onInputStart = React.useCallback(() => setError(null), [setError]);
|
|
75
|
-
const onReadClick = async () => {
|
|
76
|
-
setWatching(false);
|
|
77
|
-
setLoading(true);
|
|
78
|
-
try {
|
|
79
|
-
setResult(await store.read(input, options));
|
|
80
|
-
} catch (e) {
|
|
81
|
-
setError(e.message);
|
|
82
|
-
} finally {
|
|
83
|
-
setLoading(false);
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
const onWriteClick = async () => {
|
|
87
|
-
setWatching(false);
|
|
88
|
-
setLoading(true);
|
|
89
|
-
try {
|
|
90
|
-
setResult(await store.write(input, options));
|
|
91
|
-
} catch (e) {
|
|
92
|
-
setError(e.message);
|
|
93
|
-
} finally {
|
|
94
|
-
setLoading(false);
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
const onWatchClick = () => {
|
|
98
|
-
setResult(null);
|
|
99
|
-
setLoading(false);
|
|
100
|
-
setWatching((w) => !w);
|
|
101
|
-
};
|
|
102
|
-
return /* @__PURE__ */ React__default.default.createElement("div", null, /* @__PURE__ */ React__default.default.createElement("pre", {
|
|
103
|
-
className: "editor",
|
|
104
|
-
contentEditable: true,
|
|
105
|
-
onFocus: onInputStart,
|
|
106
|
-
onBlur: onInputEnd
|
|
107
|
-
}), /* @__PURE__ */ React__default.default.createElement("div", {
|
|
108
|
-
className: "opbar"
|
|
109
|
-
}, /* @__PURE__ */ React__default.default.createElement("button", {
|
|
110
|
-
className: "opbtn",
|
|
111
|
-
disabled: watching,
|
|
112
|
-
onClick: onReadClick
|
|
113
|
-
}, "read()"), /* @__PURE__ */ React__default.default.createElement("button", {
|
|
114
|
-
className: "opbtn",
|
|
115
|
-
disabled: watching,
|
|
116
|
-
onClick: onWriteClick
|
|
117
|
-
}, "write()"), /* @__PURE__ */ React__default.default.createElement("button", {
|
|
118
|
-
className: "opbtn",
|
|
119
|
-
"data-active": watching,
|
|
120
|
-
onClick: onWatchClick
|
|
121
|
-
}, "watch()")), error ? /* @__PURE__ */ React__default.default.createElement("div", {
|
|
122
|
-
className: "error"
|
|
123
|
-
}, error) : watching ? /* @__PURE__ */ React__default.default.createElement(react.Query, {
|
|
124
|
-
query: input,
|
|
125
|
-
options
|
|
126
|
-
}, (props) => /* @__PURE__ */ React__default.default.createElement(Result, {
|
|
127
|
-
...props
|
|
128
|
-
})) : /* @__PURE__ */ React__default.default.createElement(Result, {
|
|
129
|
-
...{ result, loading, error }
|
|
130
|
-
}), /* @__PURE__ */ React__default.default.createElement("style", {
|
|
131
|
-
jsx: true
|
|
132
|
-
}, `
|
|
133
|
-
.error {
|
|
134
|
-
color: #c00;
|
|
135
|
-
padding: 1rem;
|
|
136
|
-
}
|
|
137
|
-
.editor {
|
|
138
|
-
min-height: 1rem;
|
|
139
|
-
width: 100%;
|
|
140
|
-
}
|
|
141
|
-
.opbar {
|
|
142
|
-
display: flex;
|
|
143
|
-
}
|
|
144
|
-
.opbtn {
|
|
145
|
-
flex: 1 1 0;
|
|
146
|
-
background: #ccc;
|
|
147
|
-
color: #333;
|
|
148
|
-
padding: 0.5rem 1rem;
|
|
149
|
-
border: none;
|
|
150
|
-
}
|
|
151
|
-
.opbtn:first-child {
|
|
152
|
-
border-top-left-radius: 4px;
|
|
153
|
-
border-bottom-left-radius: 4px;
|
|
154
|
-
}
|
|
155
|
-
.opbtn:last-child {
|
|
156
|
-
border-top-right-radius: 4px;
|
|
157
|
-
border-bottom-right-radius: 4px;
|
|
158
|
-
}
|
|
159
|
-
.opbtn:not(:disabled):hover {
|
|
160
|
-
cursor: pointer;
|
|
161
|
-
box-shadow: inset 0 0 0 20px rgba(0, 0, 0, 0.1);
|
|
162
|
-
}
|
|
163
|
-
.opbtn[data-active='true']:not(:disabled),
|
|
164
|
-
.opbtn:not(:disabled):active {
|
|
165
|
-
background: #f36;
|
|
166
|
-
color: #fff;
|
|
167
|
-
}
|
|
168
|
-
.opbtn:disabled {
|
|
169
|
-
color: #888;
|
|
170
|
-
}
|
|
171
|
-
`));
|
|
172
|
-
}
|
|
173
|
-
function ExploreContainer({
|
|
174
|
-
baseUrl = "/",
|
|
175
|
-
getOptions,
|
|
176
|
-
...options
|
|
177
|
-
}) {
|
|
178
|
-
const [store, setStore] = React.useState();
|
|
179
|
-
React.useEffect(() => {
|
|
180
|
-
const store2 = new Graffy__default.default();
|
|
181
|
-
store2.use(GraffyFill__default.default());
|
|
182
|
-
store2.use(GraffyClient__default.default(baseUrl, { getOptions }));
|
|
183
|
-
setStore(store2);
|
|
184
|
-
window.store = store2;
|
|
185
|
-
window.graffy = common__namespace;
|
|
186
|
-
}, [baseUrl]);
|
|
187
|
-
return store ? /* @__PURE__ */ React__default.default.createElement(react.GraffyProvider, {
|
|
188
|
-
store
|
|
189
|
-
}, /* @__PURE__ */ React__default.default.createElement(Explore, {
|
|
190
|
-
...options
|
|
191
|
-
})) : null;
|
|
192
|
-
}
|
|
193
|
-
module.exports = ExploreContainer;
|