eddev 0.1.48 → 0.1.49
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/blocks/EditorErrorBoundary.d.ts +15 -0
- package/blocks/EditorErrorBoundary.js +64 -0
- package/build/codegen-worker-script.d.ts +5 -0
- package/build/codegen-worker-script.js +543 -0
- package/build/webpack-worker-script.d.ts +2 -0
- package/build/webpack-worker-script.js +160 -0
- package/cli/display/lib/Observable.d.ts +11 -0
- package/cli/display/lib/Observable.js +34 -0
- package/cli/display/lib/useObservable.d.ts +2 -0
- package/cli/display/lib/useObservable.js +12 -0
- package/cli/generate.d.ts +1 -0
- package/cli/generate.js +46 -0
- package/components/ContentBlocks.d.ts +36 -0
- package/components/ContentBlocks.js +92 -0
- package/components/routing.d.ts +44 -0
- package/components/routing.js +363 -0
- package/gravityforms/useGravityForm.js +5 -3
- package/package.json +1 -1
- package/utils/remoteProps.d.ts +12 -0
- package/utils/remoteProps.js +95 -0
- package/fields/ImageWell.d.ts +0 -8
- package/fields/ImageWell.js +0 -64
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
+
function step(op) {
|
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
+
while (_) try {
|
|
29
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
+
switch (op[0]) {
|
|
32
|
+
case 0: case 1: t = op; break;
|
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
+
default:
|
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
+
if (t[2]) _.ops.pop();
|
|
42
|
+
_.trys.pop(); continue;
|
|
43
|
+
}
|
|
44
|
+
op = body.call(thisArg, _);
|
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
50
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
|
+
};
|
|
52
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
|
+
exports.RouteItemContext = exports.Switch = exports.Link = exports.RouterRoot = exports.createRouteItem = exports.Route = exports.useRoute = void 0;
|
|
54
|
+
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
55
|
+
var react_1 = require("react");
|
|
56
|
+
var react_merge_refs_1 = __importDefault(require("react-merge-refs"));
|
|
57
|
+
var url_parse_1 = __importDefault(require("url-parse"));
|
|
58
|
+
// const logger = (...args: any[]) => console.log(...args)
|
|
59
|
+
var logger = function () {
|
|
60
|
+
var args = [];
|
|
61
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
62
|
+
args[_i] = arguments[_i];
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
function createRouteContext(opts) {
|
|
66
|
+
var _a, _b;
|
|
67
|
+
var subscribers = [];
|
|
68
|
+
var notify = function (item, status) {
|
|
69
|
+
subscribers.forEach(function (handler) { return handler(item, status); });
|
|
70
|
+
};
|
|
71
|
+
var parentIsSwitch = opts.parent && opts.parent.isSwitch;
|
|
72
|
+
var ctx = {
|
|
73
|
+
item: opts.initial,
|
|
74
|
+
config: opts.config || {},
|
|
75
|
+
parent: opts.parent,
|
|
76
|
+
children: [],
|
|
77
|
+
status: "inactive",
|
|
78
|
+
currentMatch: false,
|
|
79
|
+
isSwitch: !!opts.isSwitch,
|
|
80
|
+
onNavigate: opts.onNavigate,
|
|
81
|
+
onPreload: opts.onPreload,
|
|
82
|
+
propagateChange: function (item, matches) {
|
|
83
|
+
ctx.item = item;
|
|
84
|
+
ctx.currentMatch = matches;
|
|
85
|
+
ctx.status = matches ? "active" : "inactive";
|
|
86
|
+
ctx.children.forEach(function (child) {
|
|
87
|
+
child.propagateChange(item, child.match(item));
|
|
88
|
+
});
|
|
89
|
+
notify(item, ctx.status);
|
|
90
|
+
},
|
|
91
|
+
propagateCandidate: function (next, prev) {
|
|
92
|
+
// if (ctx.status === "leaving") return Promise.resolve();
|
|
93
|
+
var promises = [Promise.resolve()];
|
|
94
|
+
var matches = ctx.match(next);
|
|
95
|
+
logger(ctx.config.debugName, "was", ctx.status, matches);
|
|
96
|
+
if (ctx.status === "active" && (!matches || matches !== ctx.currentMatch)) {
|
|
97
|
+
logger(ctx.config.debugName, "is leaving because ", matches, "!=", ctx.currentMatch);
|
|
98
|
+
ctx.status = "leaving";
|
|
99
|
+
}
|
|
100
|
+
logger(ctx.config.debugName, "is now", ctx.status);
|
|
101
|
+
if (ctx.status === "leaving") {
|
|
102
|
+
promises.push(this.propagateLeaving(prev, next, false));
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
ctx.children.forEach(function (child) {
|
|
106
|
+
promises.push(child.propagateCandidate(next, prev));
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
notify(prev, ctx.status);
|
|
110
|
+
return Promise.all(promises);
|
|
111
|
+
},
|
|
112
|
+
propagateLeaving: function (current, next, parentIsLeaving) {
|
|
113
|
+
ctx.status = parentIsLeaving ? "parent-leaving" : "leaving";
|
|
114
|
+
logger(ctx.status);
|
|
115
|
+
var promises = [Promise.resolve()];
|
|
116
|
+
if (ctx.config.beforeLeave) {
|
|
117
|
+
var result = ctx.config.beforeLeave(current, next, parentIsLeaving);
|
|
118
|
+
if (result)
|
|
119
|
+
promises.push(result);
|
|
120
|
+
}
|
|
121
|
+
ctx.children.forEach(function (child) {
|
|
122
|
+
var result = child.propagateLeaving(current, next, true);
|
|
123
|
+
if (result) {
|
|
124
|
+
promises.push(result);
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
notify(current, ctx.status);
|
|
128
|
+
return Promise.all(promises);
|
|
129
|
+
},
|
|
130
|
+
subscribe: function (handler) {
|
|
131
|
+
subscribers.push(handler);
|
|
132
|
+
handler(ctx.item, ctx.status);
|
|
133
|
+
return function () {
|
|
134
|
+
var i = subscribers.indexOf(handler);
|
|
135
|
+
if (i !== -1) {
|
|
136
|
+
subscribers.splice(i, 1);
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
},
|
|
140
|
+
getFirstMatch: function (item) {
|
|
141
|
+
logger("Checking items", this.children, item);
|
|
142
|
+
for (var _i = 0, _a = this.children; _i < _a.length; _i++) {
|
|
143
|
+
var child = _a[_i];
|
|
144
|
+
if (child.matchSelf(item)) {
|
|
145
|
+
logger("Matched", child.config.debugName);
|
|
146
|
+
return child;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
match: function (item) {
|
|
151
|
+
if (parentIsSwitch) {
|
|
152
|
+
var parent_1 = ctx.parent;
|
|
153
|
+
return parent_1.getFirstMatch(item) === ctx && this.matchSelf(item);
|
|
154
|
+
}
|
|
155
|
+
return this.matchSelf(item);
|
|
156
|
+
},
|
|
157
|
+
matchSelf: function (item) {
|
|
158
|
+
var _a, _b;
|
|
159
|
+
if ((_a = ctx === null || ctx === void 0 ? void 0 : ctx.config) === null || _a === void 0 ? void 0 : _a.match) {
|
|
160
|
+
return (_b = ctx === null || ctx === void 0 ? void 0 : ctx.config) === null || _b === void 0 ? void 0 : _b.match(item);
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
return true;
|
|
164
|
+
}
|
|
165
|
+
},
|
|
166
|
+
update: function () { },
|
|
167
|
+
dispose: (_a = opts.dispose) !== null && _a !== void 0 ? _a : (function () { }),
|
|
168
|
+
fork: function (config, opts) {
|
|
169
|
+
if (opts === void 0) { opts = {}; }
|
|
170
|
+
var child = createRouteContext({
|
|
171
|
+
initial: ctx.item,
|
|
172
|
+
config: config,
|
|
173
|
+
parent: ctx,
|
|
174
|
+
isSwitch: opts.isSwitch,
|
|
175
|
+
onNavigate: ctx.onNavigate,
|
|
176
|
+
onPreload: ctx.onPreload,
|
|
177
|
+
dispose: function () {
|
|
178
|
+
var i = ctx.children.indexOf(child);
|
|
179
|
+
if (i !== -1)
|
|
180
|
+
ctx.children.splice(i, 1);
|
|
181
|
+
},
|
|
182
|
+
});
|
|
183
|
+
ctx.children.push(child);
|
|
184
|
+
if (ctx.isSwitch) {
|
|
185
|
+
}
|
|
186
|
+
return child;
|
|
187
|
+
},
|
|
188
|
+
};
|
|
189
|
+
logger("Initting", ctx.config.debugName, opts.initial);
|
|
190
|
+
if (parentIsSwitch) {
|
|
191
|
+
logger("Parent is switch");
|
|
192
|
+
if (!((_b = opts.parent) === null || _b === void 0 ? void 0 : _b.getFirstMatch(opts.initial))) {
|
|
193
|
+
logger("FFFF", ctx.config.match, ctx.match(opts.initial));
|
|
194
|
+
ctx.currentMatch = ctx.matchSelf(opts.initial);
|
|
195
|
+
ctx.status = ctx.currentMatch ? "active" : "inactive";
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
ctx.currentMatch = ctx.matchSelf(opts.initial);
|
|
200
|
+
ctx.status = ctx.currentMatch ? "active" : "inactive";
|
|
201
|
+
}
|
|
202
|
+
subscribers.push(function (item, status) {
|
|
203
|
+
if (ctx.config.onChange) {
|
|
204
|
+
ctx.config.onChange(item, status);
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
// notify(ctx.item, ctx.status);
|
|
208
|
+
return ctx;
|
|
209
|
+
}
|
|
210
|
+
var RouterContext = (0, react_1.createContext)(undefined);
|
|
211
|
+
function useForkedRouter(conf, opts) {
|
|
212
|
+
var parent = (0, react_1.useContext)(RouterContext);
|
|
213
|
+
var ctx = (0, react_1.useMemo)(function () {
|
|
214
|
+
return parent.fork(conf, opts);
|
|
215
|
+
}, [parent]);
|
|
216
|
+
// useEffect(() => {
|
|
217
|
+
// if (onChange) {
|
|
218
|
+
// return ctx.subscribe(onChange);
|
|
219
|
+
// }
|
|
220
|
+
// }, [ctx, onChange]);
|
|
221
|
+
Object.assign(ctx.config, conf);
|
|
222
|
+
// ctx.config.match = conf.match;
|
|
223
|
+
// ctx.config.beforeLeave = conf.beforeLeave;
|
|
224
|
+
// ctx.config.beforeLeave = conf.beforeLeave;
|
|
225
|
+
(0, react_1.useEffect)(function () {
|
|
226
|
+
return function () { return ctx.dispose(); };
|
|
227
|
+
}, [ctx]);
|
|
228
|
+
return ctx;
|
|
229
|
+
}
|
|
230
|
+
function useRoute() {
|
|
231
|
+
var router = (0, react_1.useContext)(RouterContext);
|
|
232
|
+
var _a = (0, react_1.useState)(router.item), route = _a[0], setRoute = _a[1];
|
|
233
|
+
(0, react_1.useEffect)(function () {
|
|
234
|
+
return router.subscribe(function (item, status) {
|
|
235
|
+
setRoute(item);
|
|
236
|
+
});
|
|
237
|
+
}, [router]);
|
|
238
|
+
return route;
|
|
239
|
+
}
|
|
240
|
+
exports.useRoute = useRoute;
|
|
241
|
+
function Route(props) {
|
|
242
|
+
var ctx = useForkedRouter({
|
|
243
|
+
match: props.match,
|
|
244
|
+
beforeLeave: props.beforeLeave,
|
|
245
|
+
debugName: props.debugName,
|
|
246
|
+
onChange: props.onChange,
|
|
247
|
+
});
|
|
248
|
+
logger("Intial route for", props.debugName, ctx.status, ctx.currentMatch);
|
|
249
|
+
var _a = (0, react_1.useState)(ctx.status), status = _a[0], setStatus = _a[1];
|
|
250
|
+
(0, react_1.useEffect)(function () {
|
|
251
|
+
return ctx.subscribe(function (item, status) {
|
|
252
|
+
setStatus(status);
|
|
253
|
+
});
|
|
254
|
+
}, [ctx]);
|
|
255
|
+
if (status === "inactive")
|
|
256
|
+
return null;
|
|
257
|
+
return (0, jsx_runtime_1.jsx)(RouterContext.Provider, __assign({ value: ctx }, { children: props.children }), void 0);
|
|
258
|
+
}
|
|
259
|
+
exports.Route = Route;
|
|
260
|
+
function createRouteItem(url, data) {
|
|
261
|
+
var parsed = (0, url_parse_1.default)(url, true);
|
|
262
|
+
return __assign(__assign({}, parsed), { data: data });
|
|
263
|
+
}
|
|
264
|
+
exports.createRouteItem = createRouteItem;
|
|
265
|
+
function RouterRoot(props) {
|
|
266
|
+
var _this = this;
|
|
267
|
+
var onNavigateRef = (0, react_1.useRef)(props.onNavigateRequest);
|
|
268
|
+
var onPreNavigateRef = (0, react_1.useRef)(props.onPreload);
|
|
269
|
+
var ctx = (0, react_1.useMemo)(function () {
|
|
270
|
+
return createRouteContext({
|
|
271
|
+
initial: createRouteItem(props.url, props.data),
|
|
272
|
+
config: {
|
|
273
|
+
debugName: "ROOT",
|
|
274
|
+
},
|
|
275
|
+
onNavigate: function (path) { return __awaiter(_this, void 0, void 0, function () {
|
|
276
|
+
return __generator(this, function (_a) {
|
|
277
|
+
// User has clicked a link
|
|
278
|
+
if (onNavigateRef.current) {
|
|
279
|
+
onNavigateRef.current(path);
|
|
280
|
+
}
|
|
281
|
+
return [2 /*return*/];
|
|
282
|
+
});
|
|
283
|
+
}); },
|
|
284
|
+
onPreload: function (path) {
|
|
285
|
+
if (onPreNavigateRef.current) {
|
|
286
|
+
onPreNavigateRef.current(path);
|
|
287
|
+
}
|
|
288
|
+
},
|
|
289
|
+
});
|
|
290
|
+
}, []);
|
|
291
|
+
onNavigateRef.current = props.onNavigateRequest;
|
|
292
|
+
onPreNavigateRef.current = props.onPreload;
|
|
293
|
+
(0, react_1.useEffect)(function () {
|
|
294
|
+
var cancelled = false;
|
|
295
|
+
var item = createRouteItem(props.url, props.data);
|
|
296
|
+
if (item.href !== ctx.item.href || item.data !== ctx.item.data) {
|
|
297
|
+
ctx.propagateCandidate(item, ctx.item).then(function () {
|
|
298
|
+
if (!cancelled) {
|
|
299
|
+
ctx.propagateChange(item, true);
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
return function () {
|
|
303
|
+
cancelled = true;
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
}, [props.url, props.data]);
|
|
307
|
+
return (0, jsx_runtime_1.jsx)(RouterContext.Provider, __assign({ value: ctx }, { children: props.children }), void 0);
|
|
308
|
+
}
|
|
309
|
+
exports.RouterRoot = RouterRoot;
|
|
310
|
+
exports.Link = (0, react_1.forwardRef)(function (props, ref) {
|
|
311
|
+
var localRef = (0, react_1.useRef)();
|
|
312
|
+
var router = (0, react_1.useContext)(RouterContext);
|
|
313
|
+
(0, react_1.useEffect)(function () {
|
|
314
|
+
if (props.preload && localRef.current) {
|
|
315
|
+
router === null || router === void 0 ? void 0 : router.onPreload(localRef.current.href);
|
|
316
|
+
}
|
|
317
|
+
}, [props.preload]);
|
|
318
|
+
return ((0, jsx_runtime_1.jsx)("a", __assign({ ref: (0, react_merge_refs_1.default)([localRef, ref]) }, props, { onMouseEnter: function (e) {
|
|
319
|
+
if (props.onMouseOver) {
|
|
320
|
+
props.onMouseOver(e);
|
|
321
|
+
}
|
|
322
|
+
router === null || router === void 0 ? void 0 : router.onPreload(e.currentTarget.href);
|
|
323
|
+
}, onClick: function (e) {
|
|
324
|
+
if (process.admin) {
|
|
325
|
+
e.preventDefault();
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
if (props.onClick) {
|
|
329
|
+
props.onClick(e);
|
|
330
|
+
}
|
|
331
|
+
if (!e.isDefaultPrevented() && router && !e.ctrlKey && !e.metaKey) {
|
|
332
|
+
var url = (0, url_parse_1.default)(e.currentTarget.href, true);
|
|
333
|
+
if (url.origin === document.location.origin) {
|
|
334
|
+
router.onNavigate(e.currentTarget.href);
|
|
335
|
+
e.preventDefault();
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
} }), void 0));
|
|
339
|
+
});
|
|
340
|
+
function Switch(_a) {
|
|
341
|
+
var children = _a.children;
|
|
342
|
+
var ctx = useForkedRouter({
|
|
343
|
+
debugName: "SWITCH",
|
|
344
|
+
match: function () {
|
|
345
|
+
return true;
|
|
346
|
+
},
|
|
347
|
+
beforeLeave: function () {
|
|
348
|
+
return undefined;
|
|
349
|
+
},
|
|
350
|
+
}, { isSwitch: true });
|
|
351
|
+
return (0, jsx_runtime_1.jsx)(RouterContext.Provider, __assign({ value: ctx }, { children: children }), void 0);
|
|
352
|
+
}
|
|
353
|
+
exports.Switch = Switch;
|
|
354
|
+
function RouteItemContext(props) {
|
|
355
|
+
var ctx = useForkedRouter({
|
|
356
|
+
match: function () { return true; },
|
|
357
|
+
beforeLeave: undefined,
|
|
358
|
+
debugName: undefined,
|
|
359
|
+
onChange: undefined,
|
|
360
|
+
});
|
|
361
|
+
return (0, jsx_runtime_1.jsx)(RouterContext.Provider, __assign({ value: ctx }, { children: props.children }), void 0);
|
|
362
|
+
}
|
|
363
|
+
exports.RouteItemContext = RouteItemContext;
|
|
@@ -96,7 +96,6 @@ function useGravityForm(opts) {
|
|
|
96
96
|
submit: function (state) {
|
|
97
97
|
dispatch({ type: "submitting" });
|
|
98
98
|
submit(form, state).then(function (result) {
|
|
99
|
-
console.log("RESULT", result);
|
|
100
99
|
if (cancelled)
|
|
101
100
|
return;
|
|
102
101
|
if (result.success) {
|
|
@@ -126,7 +125,11 @@ function prepareValuesPayload(form, state, data) {
|
|
|
126
125
|
for (var _i = 0, _a = form.fields; _i < _a.length; _i++) {
|
|
127
126
|
var field = _a[_i];
|
|
128
127
|
var value = state.values[field.id];
|
|
129
|
-
|
|
128
|
+
var key = "input_" + field.id;
|
|
129
|
+
if (field.type === "consent") {
|
|
130
|
+
key += "_1";
|
|
131
|
+
}
|
|
132
|
+
data[key] = value;
|
|
130
133
|
}
|
|
131
134
|
return data;
|
|
132
135
|
}
|
|
@@ -137,7 +140,6 @@ function submit(form, state) {
|
|
|
137
140
|
switch (_a.label) {
|
|
138
141
|
case 0:
|
|
139
142
|
_a.trys.push([0, 3, , 4]);
|
|
140
|
-
console.log("Submitting", { form: form, state: state });
|
|
141
143
|
url = "/wp-json/ed/v1/gf/submit";
|
|
142
144
|
params = {
|
|
143
145
|
formID: form.id,
|
package/package.json
CHANGED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import URLParse from "url-parse";
|
|
2
|
+
export interface RouteData {
|
|
3
|
+
view: string;
|
|
4
|
+
viewType: "react" | "html";
|
|
5
|
+
viewData: any;
|
|
6
|
+
appData: any;
|
|
7
|
+
}
|
|
8
|
+
export declare function parseURL(url: string): URLParse<string>;
|
|
9
|
+
export declare function setInitialProps(url: string, data: RouteData): void;
|
|
10
|
+
export declare function isSameOrigin(url: string): boolean;
|
|
11
|
+
export declare function fetchProps(url: string): Promise<RouteData>;
|
|
12
|
+
export declare function hasCachedProps(url: string): boolean;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.hasCachedProps = exports.fetchProps = exports.isSameOrigin = exports.setInitialProps = exports.parseURL = void 0;
|
|
43
|
+
var url_parse_1 = __importDefault(require("url-parse"));
|
|
44
|
+
var qs_1 = __importDefault(require("qs"));
|
|
45
|
+
var cache = {};
|
|
46
|
+
function parseURL(url) {
|
|
47
|
+
return (0, url_parse_1.default)(url, qs_1.default.parse);
|
|
48
|
+
}
|
|
49
|
+
exports.parseURL = parseURL;
|
|
50
|
+
function getRouteCacheKey(url) {
|
|
51
|
+
var parsed = parseURL(url);
|
|
52
|
+
return parsed.pathname;
|
|
53
|
+
}
|
|
54
|
+
function setInitialProps(url, data) {
|
|
55
|
+
var cacheKey = getRouteCacheKey(url);
|
|
56
|
+
cache[cacheKey] = data;
|
|
57
|
+
}
|
|
58
|
+
exports.setInitialProps = setInitialProps;
|
|
59
|
+
function isSameOrigin(url) {
|
|
60
|
+
var parsed = parseURL(url);
|
|
61
|
+
return parsed.origin === document.location.origin;
|
|
62
|
+
}
|
|
63
|
+
exports.isSameOrigin = isSameOrigin;
|
|
64
|
+
function fetchProps(url) {
|
|
65
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
66
|
+
var parsed, cacheKey, requestUrl, response, data;
|
|
67
|
+
return __generator(this, function (_a) {
|
|
68
|
+
switch (_a.label) {
|
|
69
|
+
case 0:
|
|
70
|
+
parsed = parseURL(url);
|
|
71
|
+
cacheKey = getRouteCacheKey(url);
|
|
72
|
+
// Cached value?
|
|
73
|
+
if (cache[cacheKey])
|
|
74
|
+
return [2 /*return*/, Promise.resolve(cache[cacheKey])];
|
|
75
|
+
parsed.query["_props"] = "1";
|
|
76
|
+
requestUrl = parsed.toString();
|
|
77
|
+
return [4 /*yield*/, fetch(requestUrl)];
|
|
78
|
+
case 1:
|
|
79
|
+
response = _a.sent();
|
|
80
|
+
return [4 /*yield*/, response.json()];
|
|
81
|
+
case 2:
|
|
82
|
+
data = _a.sent();
|
|
83
|
+
cache[cacheKey] = data;
|
|
84
|
+
return [2 /*return*/, data];
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
exports.fetchProps = fetchProps;
|
|
90
|
+
function hasCachedProps(url) {
|
|
91
|
+
var cacheKey = getRouteCacheKey(url);
|
|
92
|
+
// Cached value?
|
|
93
|
+
return !!cache[cacheKey];
|
|
94
|
+
}
|
|
95
|
+
exports.hasCachedProps = hasCachedProps;
|
package/fields/ImageWell.d.ts
DELETED
package/fields/ImageWell.js
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ImageWell = void 0;
|
|
4
|
-
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
-
var react_1 = require("@stitches/react");
|
|
6
|
-
var react_2 = require("react");
|
|
7
|
-
function ImageWell(props) {
|
|
8
|
-
var _a = (0, react_2.useState)(null), selectedImage = _a[0], setSelectedImage = _a[1];
|
|
9
|
-
var _b = (0, react_2.useState)(false), imageIsLoading = _b[0], setImageIsLoading = _b[1];
|
|
10
|
-
(0, react_2.useEffect)(function () {
|
|
11
|
-
if (props.value) {
|
|
12
|
-
var cancelled = false;
|
|
13
|
-
setImageIsLoading(true);
|
|
14
|
-
fetch("/wp-json/ed/v1/media/" + Number(props.value))
|
|
15
|
-
.then(function (response) { return response.json(); })
|
|
16
|
-
.then(function (image) {
|
|
17
|
-
setImageIsLoading(false);
|
|
18
|
-
setSelectedImage(image);
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
}, [props.value]);
|
|
22
|
-
return ((0, jsx_runtime_1.jsxs)(Wrapper, { children: [imageIsLoading ? ((0, jsx_runtime_1.jsx)(Loading, { children: (0, jsx_runtime_1.jsx)(Spinner, {}, void 0) }, void 0)) : selectedImage ? ((0, jsx_runtime_1.jsx)(ImageContainer, { children: (0, jsx_runtime_1.jsx)("img", { src: selectedImage.sizes[props.previewSize] || selectedImage.sizes["thumbnail"] }, void 0) }, void 0)) : null, (0, jsx_runtime_1.jsx)(Toolbar, { children: selectedImage || imageIsLoading ? ((0, jsx_runtime_1.jsxs)(react_2.Fragment, { children: [(0, jsx_runtime_1.jsx)(Button, { children: "Remove" }, void 0), (0, jsx_runtime_1.jsx)(Button, { children: "Edit" }, void 0), (0, jsx_runtime_1.jsx)(Button, { children: "View" }, void 0)] }, void 0)) : null }, void 0)] }, void 0));
|
|
23
|
-
}
|
|
24
|
-
exports.ImageWell = ImageWell;
|
|
25
|
-
var Wrapper = (0, react_1.styled)("div", {
|
|
26
|
-
position: "relative",
|
|
27
|
-
display: "block",
|
|
28
|
-
width: "100%",
|
|
29
|
-
border: "1px solid #aaaaaa",
|
|
30
|
-
});
|
|
31
|
-
var ImageContainer = (0, react_1.styled)("div", {
|
|
32
|
-
padding: "4px",
|
|
33
|
-
img: {
|
|
34
|
-
maxWidth: "100%",
|
|
35
|
-
},
|
|
36
|
-
});
|
|
37
|
-
var spin = (0, react_1.keyframes)({
|
|
38
|
-
from: {
|
|
39
|
-
transform: "rotate(0deg)",
|
|
40
|
-
},
|
|
41
|
-
to: {
|
|
42
|
-
transform: "rotate(360deg)",
|
|
43
|
-
},
|
|
44
|
-
});
|
|
45
|
-
var Spinner = (0, react_1.styled)("div", {
|
|
46
|
-
display: "block",
|
|
47
|
-
width: "32px",
|
|
48
|
-
height: "32px",
|
|
49
|
-
border: "4px solid transparent",
|
|
50
|
-
borderTop: "currentColor",
|
|
51
|
-
animation: "".concat(spin, " 1s linear infinite"),
|
|
52
|
-
});
|
|
53
|
-
var Loading = (0, react_1.styled)("div", {
|
|
54
|
-
display: "flex",
|
|
55
|
-
justifyContent: "center",
|
|
56
|
-
alignItems: "center",
|
|
57
|
-
padding: "8px",
|
|
58
|
-
});
|
|
59
|
-
var Toolbar = (0, react_1.styled)("div", {
|
|
60
|
-
position: "absolute",
|
|
61
|
-
top: 0,
|
|
62
|
-
right: 0,
|
|
63
|
-
padding: "4px",
|
|
64
|
-
});
|