eddev 0.1.28 → 0.1.32
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/ContentBlocks.d.ts +36 -0
- package/blocks/ContentBlocks.js +89 -0
- package/blocks/blockAttributes.d.ts +1 -1
- package/blocks/index.d.ts +1 -0
- package/blocks/index.js +1 -0
- package/blocks/inlineEditing.js +2 -2
- package/build/workers/codegen-worker-script.js +3 -2
- package/components/BrowserRouter.js +1 -1
- package/components/InlinePage.js +1 -1
- package/components/index.d.ts +0 -2
- package/components/index.js +0 -2
- package/components/routing.d.ts +2 -0
- package/entry/Root.js +4 -4
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +1 -1
- package/routing/index.d.ts +1 -0
- package/routing/index.js +13 -0
- package/routing/routing.d.ts +45 -0
- package/routing/routing.js +373 -0
- package/build/codegen-worker-script.d.ts +0 -5
- package/build/codegen-worker-script.js +0 -543
- package/build/webpack-worker-script.d.ts +0 -2
- package/build/webpack-worker-script.js +0 -160
- package/cli/generate.d.ts +0 -1
- package/cli/generate.js +0 -46
|
@@ -0,0 +1,373 @@
|
|
|
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.isInternalPageLink = 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
|
+
var isInternalPageLink = function (href) {
|
|
311
|
+
var url = (0, url_parse_1.default)(href, true);
|
|
312
|
+
if (url && url.origin === document.location.origin && !url.pathname.match(/\./)) {
|
|
313
|
+
return true;
|
|
314
|
+
}
|
|
315
|
+
else {
|
|
316
|
+
return false;
|
|
317
|
+
}
|
|
318
|
+
};
|
|
319
|
+
exports.isInternalPageLink = isInternalPageLink;
|
|
320
|
+
exports.Link = (0, react_1.forwardRef)(function (props, ref) {
|
|
321
|
+
var localRef = (0, react_1.useRef)();
|
|
322
|
+
var router = (0, react_1.useContext)(RouterContext);
|
|
323
|
+
(0, react_1.useEffect)(function () {
|
|
324
|
+
if (props.preload && localRef.current && (0, exports.isInternalPageLink)(localRef.current.href)) {
|
|
325
|
+
router === null || router === void 0 ? void 0 : router.onPreload(localRef.current.href);
|
|
326
|
+
}
|
|
327
|
+
}, [props.preload]);
|
|
328
|
+
return ((0, jsx_runtime_1.jsx)("a", __assign({ ref: (0, react_merge_refs_1.default)([localRef, ref]) }, props, { onMouseEnter: function (e) {
|
|
329
|
+
if (props.onMouseOver) {
|
|
330
|
+
props.onMouseOver(e);
|
|
331
|
+
}
|
|
332
|
+
router === null || router === void 0 ? void 0 : router.onPreload(e.currentTarget.href);
|
|
333
|
+
}, onClick: function (e) {
|
|
334
|
+
if (process.admin) {
|
|
335
|
+
e.preventDefault();
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
if (props.onClick) {
|
|
339
|
+
props.onClick(e);
|
|
340
|
+
}
|
|
341
|
+
if (!e.isDefaultPrevented() && router && !e.ctrlKey && !e.metaKey) {
|
|
342
|
+
var href = e.currentTarget.href;
|
|
343
|
+
if ((0, exports.isInternalPageLink)(href)) {
|
|
344
|
+
router.onNavigate(e.currentTarget.href);
|
|
345
|
+
e.preventDefault();
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
} }), void 0));
|
|
349
|
+
});
|
|
350
|
+
function Switch(_a) {
|
|
351
|
+
var children = _a.children;
|
|
352
|
+
var ctx = useForkedRouter({
|
|
353
|
+
debugName: "SWITCH",
|
|
354
|
+
match: function () {
|
|
355
|
+
return true;
|
|
356
|
+
},
|
|
357
|
+
beforeLeave: function () {
|
|
358
|
+
return undefined;
|
|
359
|
+
},
|
|
360
|
+
}, { isSwitch: true });
|
|
361
|
+
return (0, jsx_runtime_1.jsx)(RouterContext.Provider, __assign({ value: ctx }, { children: children }), void 0);
|
|
362
|
+
}
|
|
363
|
+
exports.Switch = Switch;
|
|
364
|
+
function RouteItemContext(props) {
|
|
365
|
+
var ctx = useForkedRouter({
|
|
366
|
+
match: function () { return true; },
|
|
367
|
+
beforeLeave: undefined,
|
|
368
|
+
debugName: undefined,
|
|
369
|
+
onChange: undefined,
|
|
370
|
+
});
|
|
371
|
+
return (0, jsx_runtime_1.jsx)(RouterContext.Provider, __assign({ value: ctx }, { children: props.children }), void 0);
|
|
372
|
+
}
|
|
373
|
+
exports.RouteItemContext = RouteItemContext;
|