@plasmicpkgs/plasmic-link-preview 1.0.83
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.md +21 -0
- package/README.md +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +8 -0
- package/dist/lib/html-metadata-parser.d.ts +11 -0
- package/dist/lib/utils.d.ts +24 -0
- package/dist/plasmic-link-preview.cjs.development.js +582 -0
- package/dist/plasmic-link-preview.cjs.development.js.map +1 -0
- package/dist/plasmic-link-preview.cjs.production.min.js +2 -0
- package/dist/plasmic-link-preview.cjs.production.min.js.map +1 -0
- package/dist/plasmic-link-preview.esm.js +573 -0
- package/dist/plasmic-link-preview.esm.js.map +1 -0
- package/package.json +53 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Plasmic
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
headless link-preview component
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Registerable } from "./lib/utils";
|
|
3
|
+
export declare type LinkPreviewProps = {
|
|
4
|
+
url: string;
|
|
5
|
+
children: React.ReactNode;
|
|
6
|
+
loadingMessage: React.ReactNode;
|
|
7
|
+
noPreviewMessage: React.ReactNode;
|
|
8
|
+
showLoading: boolean;
|
|
9
|
+
showNoPreview: boolean;
|
|
10
|
+
};
|
|
11
|
+
export declare const LinkPreview: React.FC<LinkPreviewProps>;
|
|
12
|
+
export declare const rlpComponentName = "plasmic-link-preview";
|
|
13
|
+
export declare function registerLinkPreview(loader?: Registerable): void;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface Metadata {
|
|
2
|
+
title?: string;
|
|
3
|
+
description?: string;
|
|
4
|
+
image?: string;
|
|
5
|
+
siteName?: string;
|
|
6
|
+
hostname?: string;
|
|
7
|
+
}
|
|
8
|
+
declare const isValidUrl: (url: string) => boolean;
|
|
9
|
+
declare const getMetadata: (url: string) => Promise<Metadata>;
|
|
10
|
+
export default getMetadata;
|
|
11
|
+
export { isValidUrl };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ComponentMeta, default as registerComponent } from "@plasmicapp/host/registerComponent";
|
|
2
|
+
import { default as registerGlobalContext, GlobalContextMeta } from "@plasmicapp/host/registerGlobalContext";
|
|
3
|
+
import { default as registerToken } from "@plasmicapp/host/registerToken";
|
|
4
|
+
import React from "react";
|
|
5
|
+
export declare type Registerable = {
|
|
6
|
+
registerComponent: typeof registerComponent;
|
|
7
|
+
registerGlobalContext: typeof registerGlobalContext;
|
|
8
|
+
registerToken: typeof registerToken;
|
|
9
|
+
};
|
|
10
|
+
export declare function makeRegisterComponent<T extends React.ComponentType<any>>(component: T, meta: ComponentMeta<React.ComponentProps<T>>): (loader?: Registerable | undefined) => void;
|
|
11
|
+
export declare function makeRegisterGlobalContext<T extends React.ComponentType<any>>(component: T, meta: GlobalContextMeta<React.ComponentProps<T>>): (loader?: Registerable | undefined) => void;
|
|
12
|
+
export declare function registerComponentHelper<T extends React.ComponentType<any>>(loader: Registerable | undefined, component: T, meta: ComponentMeta<React.ComponentProps<T>>): void;
|
|
13
|
+
declare type ReactElt = {
|
|
14
|
+
children: ReactElt | ReactElt[];
|
|
15
|
+
props: {
|
|
16
|
+
children: ReactElt | ReactElt[];
|
|
17
|
+
[prop: string]: any;
|
|
18
|
+
} | null;
|
|
19
|
+
type: React.ComponentType<any> | null;
|
|
20
|
+
key: string | null;
|
|
21
|
+
} | null;
|
|
22
|
+
export declare function traverseReactEltTree(children: React.ReactNode, callback: (elt: ReactElt) => void): void;
|
|
23
|
+
export declare function asArray<T>(x: T[] | T | undefined | null): T[];
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,582 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
|
6
|
+
|
|
7
|
+
var React = require('react');
|
|
8
|
+
var React__default = _interopDefault(React);
|
|
9
|
+
var registerComponent = _interopDefault(require('@plasmicapp/host/registerComponent'));
|
|
10
|
+
require('@plasmicapp/host/registerGlobalContext');
|
|
11
|
+
var host = require('@plasmicapp/host');
|
|
12
|
+
var nodeHtmlParser = require('node-html-parser');
|
|
13
|
+
|
|
14
|
+
function registerComponentHelper(loader, component, meta) {
|
|
15
|
+
if (loader) {
|
|
16
|
+
loader.registerComponent(component, meta);
|
|
17
|
+
} else {
|
|
18
|
+
registerComponent(component, meta);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function _regeneratorRuntime() {
|
|
23
|
+
_regeneratorRuntime = function () {
|
|
24
|
+
return e;
|
|
25
|
+
};
|
|
26
|
+
var t,
|
|
27
|
+
e = {},
|
|
28
|
+
r = Object.prototype,
|
|
29
|
+
n = r.hasOwnProperty,
|
|
30
|
+
o = Object.defineProperty || function (t, e, r) {
|
|
31
|
+
t[e] = r.value;
|
|
32
|
+
},
|
|
33
|
+
i = "function" == typeof Symbol ? Symbol : {},
|
|
34
|
+
a = i.iterator || "@@iterator",
|
|
35
|
+
c = i.asyncIterator || "@@asyncIterator",
|
|
36
|
+
u = i.toStringTag || "@@toStringTag";
|
|
37
|
+
function define(t, e, r) {
|
|
38
|
+
return Object.defineProperty(t, e, {
|
|
39
|
+
value: r,
|
|
40
|
+
enumerable: !0,
|
|
41
|
+
configurable: !0,
|
|
42
|
+
writable: !0
|
|
43
|
+
}), t[e];
|
|
44
|
+
}
|
|
45
|
+
try {
|
|
46
|
+
define({}, "");
|
|
47
|
+
} catch (t) {
|
|
48
|
+
define = function (t, e, r) {
|
|
49
|
+
return t[e] = r;
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function wrap(t, e, r, n) {
|
|
53
|
+
var i = e && e.prototype instanceof Generator ? e : Generator,
|
|
54
|
+
a = Object.create(i.prototype),
|
|
55
|
+
c = new Context(n || []);
|
|
56
|
+
return o(a, "_invoke", {
|
|
57
|
+
value: makeInvokeMethod(t, r, c)
|
|
58
|
+
}), a;
|
|
59
|
+
}
|
|
60
|
+
function tryCatch(t, e, r) {
|
|
61
|
+
try {
|
|
62
|
+
return {
|
|
63
|
+
type: "normal",
|
|
64
|
+
arg: t.call(e, r)
|
|
65
|
+
};
|
|
66
|
+
} catch (t) {
|
|
67
|
+
return {
|
|
68
|
+
type: "throw",
|
|
69
|
+
arg: t
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
e.wrap = wrap;
|
|
74
|
+
var h = "suspendedStart",
|
|
75
|
+
l = "suspendedYield",
|
|
76
|
+
f = "executing",
|
|
77
|
+
s = "completed",
|
|
78
|
+
y = {};
|
|
79
|
+
function Generator() {}
|
|
80
|
+
function GeneratorFunction() {}
|
|
81
|
+
function GeneratorFunctionPrototype() {}
|
|
82
|
+
var p = {};
|
|
83
|
+
define(p, a, function () {
|
|
84
|
+
return this;
|
|
85
|
+
});
|
|
86
|
+
var d = Object.getPrototypeOf,
|
|
87
|
+
v = d && d(d(values([])));
|
|
88
|
+
v && v !== r && n.call(v, a) && (p = v);
|
|
89
|
+
var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p);
|
|
90
|
+
function defineIteratorMethods(t) {
|
|
91
|
+
["next", "throw", "return"].forEach(function (e) {
|
|
92
|
+
define(t, e, function (t) {
|
|
93
|
+
return this._invoke(e, t);
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
function AsyncIterator(t, e) {
|
|
98
|
+
function invoke(r, o, i, a) {
|
|
99
|
+
var c = tryCatch(t[r], t, o);
|
|
100
|
+
if ("throw" !== c.type) {
|
|
101
|
+
var u = c.arg,
|
|
102
|
+
h = u.value;
|
|
103
|
+
return h && "object" == typeof h && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) {
|
|
104
|
+
invoke("next", t, i, a);
|
|
105
|
+
}, function (t) {
|
|
106
|
+
invoke("throw", t, i, a);
|
|
107
|
+
}) : e.resolve(h).then(function (t) {
|
|
108
|
+
u.value = t, i(u);
|
|
109
|
+
}, function (t) {
|
|
110
|
+
return invoke("throw", t, i, a);
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
a(c.arg);
|
|
114
|
+
}
|
|
115
|
+
var r;
|
|
116
|
+
o(this, "_invoke", {
|
|
117
|
+
value: function (t, n) {
|
|
118
|
+
function callInvokeWithMethodAndArg() {
|
|
119
|
+
return new e(function (e, r) {
|
|
120
|
+
invoke(t, n, e, r);
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
function makeInvokeMethod(e, r, n) {
|
|
128
|
+
var o = h;
|
|
129
|
+
return function (i, a) {
|
|
130
|
+
if (o === f) throw new Error("Generator is already running");
|
|
131
|
+
if (o === s) {
|
|
132
|
+
if ("throw" === i) throw a;
|
|
133
|
+
return {
|
|
134
|
+
value: t,
|
|
135
|
+
done: !0
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
for (n.method = i, n.arg = a;;) {
|
|
139
|
+
var c = n.delegate;
|
|
140
|
+
if (c) {
|
|
141
|
+
var u = maybeInvokeDelegate(c, n);
|
|
142
|
+
if (u) {
|
|
143
|
+
if (u === y) continue;
|
|
144
|
+
return u;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) {
|
|
148
|
+
if (o === h) throw o = s, n.arg;
|
|
149
|
+
n.dispatchException(n.arg);
|
|
150
|
+
} else "return" === n.method && n.abrupt("return", n.arg);
|
|
151
|
+
o = f;
|
|
152
|
+
var p = tryCatch(e, r, n);
|
|
153
|
+
if ("normal" === p.type) {
|
|
154
|
+
if (o = n.done ? s : l, p.arg === y) continue;
|
|
155
|
+
return {
|
|
156
|
+
value: p.arg,
|
|
157
|
+
done: n.done
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
"throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg);
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
function maybeInvokeDelegate(e, r) {
|
|
165
|
+
var n = r.method,
|
|
166
|
+
o = e.iterator[n];
|
|
167
|
+
if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y;
|
|
168
|
+
var i = tryCatch(o, e.iterator, r.arg);
|
|
169
|
+
if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y;
|
|
170
|
+
var a = i.arg;
|
|
171
|
+
return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y);
|
|
172
|
+
}
|
|
173
|
+
function pushTryEntry(t) {
|
|
174
|
+
var e = {
|
|
175
|
+
tryLoc: t[0]
|
|
176
|
+
};
|
|
177
|
+
1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e);
|
|
178
|
+
}
|
|
179
|
+
function resetTryEntry(t) {
|
|
180
|
+
var e = t.completion || {};
|
|
181
|
+
e.type = "normal", delete e.arg, t.completion = e;
|
|
182
|
+
}
|
|
183
|
+
function Context(t) {
|
|
184
|
+
this.tryEntries = [{
|
|
185
|
+
tryLoc: "root"
|
|
186
|
+
}], t.forEach(pushTryEntry, this), this.reset(!0);
|
|
187
|
+
}
|
|
188
|
+
function values(e) {
|
|
189
|
+
if (e || "" === e) {
|
|
190
|
+
var r = e[a];
|
|
191
|
+
if (r) return r.call(e);
|
|
192
|
+
if ("function" == typeof e.next) return e;
|
|
193
|
+
if (!isNaN(e.length)) {
|
|
194
|
+
var o = -1,
|
|
195
|
+
i = function next() {
|
|
196
|
+
for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next;
|
|
197
|
+
return next.value = t, next.done = !0, next;
|
|
198
|
+
};
|
|
199
|
+
return i.next = i;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
throw new TypeError(typeof e + " is not iterable");
|
|
203
|
+
}
|
|
204
|
+
return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", {
|
|
205
|
+
value: GeneratorFunctionPrototype,
|
|
206
|
+
configurable: !0
|
|
207
|
+
}), o(GeneratorFunctionPrototype, "constructor", {
|
|
208
|
+
value: GeneratorFunction,
|
|
209
|
+
configurable: !0
|
|
210
|
+
}), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) {
|
|
211
|
+
var e = "function" == typeof t && t.constructor;
|
|
212
|
+
return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name));
|
|
213
|
+
}, e.mark = function (t) {
|
|
214
|
+
return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t;
|
|
215
|
+
}, e.awrap = function (t) {
|
|
216
|
+
return {
|
|
217
|
+
__await: t
|
|
218
|
+
};
|
|
219
|
+
}, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () {
|
|
220
|
+
return this;
|
|
221
|
+
}), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) {
|
|
222
|
+
void 0 === i && (i = Promise);
|
|
223
|
+
var a = new AsyncIterator(wrap(t, r, n, o), i);
|
|
224
|
+
return e.isGeneratorFunction(r) ? a : a.next().then(function (t) {
|
|
225
|
+
return t.done ? t.value : a.next();
|
|
226
|
+
});
|
|
227
|
+
}, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () {
|
|
228
|
+
return this;
|
|
229
|
+
}), define(g, "toString", function () {
|
|
230
|
+
return "[object Generator]";
|
|
231
|
+
}), e.keys = function (t) {
|
|
232
|
+
var e = Object(t),
|
|
233
|
+
r = [];
|
|
234
|
+
for (var n in e) r.push(n);
|
|
235
|
+
return r.reverse(), function next() {
|
|
236
|
+
for (; r.length;) {
|
|
237
|
+
var t = r.pop();
|
|
238
|
+
if (t in e) return next.value = t, next.done = !1, next;
|
|
239
|
+
}
|
|
240
|
+
return next.done = !0, next;
|
|
241
|
+
};
|
|
242
|
+
}, e.values = values, Context.prototype = {
|
|
243
|
+
constructor: Context,
|
|
244
|
+
reset: function (e) {
|
|
245
|
+
if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t);
|
|
246
|
+
},
|
|
247
|
+
stop: function () {
|
|
248
|
+
this.done = !0;
|
|
249
|
+
var t = this.tryEntries[0].completion;
|
|
250
|
+
if ("throw" === t.type) throw t.arg;
|
|
251
|
+
return this.rval;
|
|
252
|
+
},
|
|
253
|
+
dispatchException: function (e) {
|
|
254
|
+
if (this.done) throw e;
|
|
255
|
+
var r = this;
|
|
256
|
+
function handle(n, o) {
|
|
257
|
+
return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o;
|
|
258
|
+
}
|
|
259
|
+
for (var o = this.tryEntries.length - 1; o >= 0; --o) {
|
|
260
|
+
var i = this.tryEntries[o],
|
|
261
|
+
a = i.completion;
|
|
262
|
+
if ("root" === i.tryLoc) return handle("end");
|
|
263
|
+
if (i.tryLoc <= this.prev) {
|
|
264
|
+
var c = n.call(i, "catchLoc"),
|
|
265
|
+
u = n.call(i, "finallyLoc");
|
|
266
|
+
if (c && u) {
|
|
267
|
+
if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
|
|
268
|
+
if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
|
|
269
|
+
} else if (c) {
|
|
270
|
+
if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
|
|
271
|
+
} else {
|
|
272
|
+
if (!u) throw new Error("try statement without catch or finally");
|
|
273
|
+
if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
},
|
|
278
|
+
abrupt: function (t, e) {
|
|
279
|
+
for (var r = this.tryEntries.length - 1; r >= 0; --r) {
|
|
280
|
+
var o = this.tryEntries[r];
|
|
281
|
+
if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) {
|
|
282
|
+
var i = o;
|
|
283
|
+
break;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null);
|
|
287
|
+
var a = i ? i.completion : {};
|
|
288
|
+
return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a);
|
|
289
|
+
},
|
|
290
|
+
complete: function (t, e) {
|
|
291
|
+
if ("throw" === t.type) throw t.arg;
|
|
292
|
+
return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y;
|
|
293
|
+
},
|
|
294
|
+
finish: function (t) {
|
|
295
|
+
for (var e = this.tryEntries.length - 1; e >= 0; --e) {
|
|
296
|
+
var r = this.tryEntries[e];
|
|
297
|
+
if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y;
|
|
298
|
+
}
|
|
299
|
+
},
|
|
300
|
+
catch: function (t) {
|
|
301
|
+
for (var e = this.tryEntries.length - 1; e >= 0; --e) {
|
|
302
|
+
var r = this.tryEntries[e];
|
|
303
|
+
if (r.tryLoc === t) {
|
|
304
|
+
var n = r.completion;
|
|
305
|
+
if ("throw" === n.type) {
|
|
306
|
+
var o = n.arg;
|
|
307
|
+
resetTryEntry(r);
|
|
308
|
+
}
|
|
309
|
+
return o;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
throw new Error("illegal catch attempt");
|
|
313
|
+
},
|
|
314
|
+
delegateYield: function (e, r, n) {
|
|
315
|
+
return this.delegate = {
|
|
316
|
+
iterator: values(e),
|
|
317
|
+
resultName: r,
|
|
318
|
+
nextLoc: n
|
|
319
|
+
}, "next" === this.method && (this.arg = t), y;
|
|
320
|
+
}
|
|
321
|
+
}, e;
|
|
322
|
+
}
|
|
323
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
324
|
+
try {
|
|
325
|
+
var info = gen[key](arg);
|
|
326
|
+
var value = info.value;
|
|
327
|
+
} catch (error) {
|
|
328
|
+
reject(error);
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
if (info.done) {
|
|
332
|
+
resolve(value);
|
|
333
|
+
} else {
|
|
334
|
+
Promise.resolve(value).then(_next, _throw);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
function _asyncToGenerator(fn) {
|
|
338
|
+
return function () {
|
|
339
|
+
var self = this,
|
|
340
|
+
args = arguments;
|
|
341
|
+
return new Promise(function (resolve, reject) {
|
|
342
|
+
var gen = fn.apply(self, args);
|
|
343
|
+
function _next(value) {
|
|
344
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
345
|
+
}
|
|
346
|
+
function _throw(err) {
|
|
347
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
348
|
+
}
|
|
349
|
+
_next(undefined);
|
|
350
|
+
});
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
function _extends() {
|
|
354
|
+
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
355
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
356
|
+
var source = arguments[i];
|
|
357
|
+
for (var key in source) {
|
|
358
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
359
|
+
target[key] = source[key];
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
return target;
|
|
364
|
+
};
|
|
365
|
+
return _extends.apply(this, arguments);
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
var readMT = function readMT(el, name) {
|
|
369
|
+
var prop = el.getAttribute("name") || el.getAttribute("property");
|
|
370
|
+
return prop == name ? el.getAttribute("content") : null;
|
|
371
|
+
};
|
|
372
|
+
var isValidUrl = function isValidUrl(url) {
|
|
373
|
+
return /(^http(s?):\/\/[^\s$.?#].[^\s]*)/i.test(url);
|
|
374
|
+
};
|
|
375
|
+
var getMetadata = /*#__PURE__*/function () {
|
|
376
|
+
var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(url) {
|
|
377
|
+
var contents, $, getHostname, getTitle, metas, meta, _loop, i, metadata;
|
|
378
|
+
return _regeneratorRuntime().wrap(function _callee$(_context2) {
|
|
379
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
380
|
+
case 0:
|
|
381
|
+
if (isValidUrl(url)) {
|
|
382
|
+
_context2.next = 2;
|
|
383
|
+
break;
|
|
384
|
+
}
|
|
385
|
+
return _context2.abrupt("return", {});
|
|
386
|
+
case 2:
|
|
387
|
+
_context2.next = 4;
|
|
388
|
+
return fetch("https://corsproxy.io/?" + url).then(function (res) {
|
|
389
|
+
return res.text();
|
|
390
|
+
});
|
|
391
|
+
case 4:
|
|
392
|
+
contents = _context2.sent;
|
|
393
|
+
$ = nodeHtmlParser.parse(contents);
|
|
394
|
+
getHostname = function getHostname() {
|
|
395
|
+
var _URL = new URL(url),
|
|
396
|
+
hostname = _URL.hostname;
|
|
397
|
+
return hostname;
|
|
398
|
+
};
|
|
399
|
+
getTitle = function getTitle() {
|
|
400
|
+
var title = $.querySelector("title");
|
|
401
|
+
return title == null ? void 0 : title.text;
|
|
402
|
+
};
|
|
403
|
+
metas = $.querySelectorAll("meta");
|
|
404
|
+
meta = {};
|
|
405
|
+
_loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop() {
|
|
406
|
+
var el;
|
|
407
|
+
return _regeneratorRuntime().wrap(function _loop$(_context) {
|
|
408
|
+
while (1) switch (_context.prev = _context.next) {
|
|
409
|
+
case 0:
|
|
410
|
+
el = metas[i];
|
|
411
|
+
["title", "description", "image"].forEach(function (s) {
|
|
412
|
+
var val = readMT(el, s);
|
|
413
|
+
if (val) meta[s] = val;
|
|
414
|
+
});
|
|
415
|
+
["og:title", "og:description", "og:image", "og:url", "og:site_name", "og:type"].forEach(function (s) {
|
|
416
|
+
var val = readMT(el, s);
|
|
417
|
+
if (val) meta[s.split(":")[1]] = val;
|
|
418
|
+
});
|
|
419
|
+
case 3:
|
|
420
|
+
case "end":
|
|
421
|
+
return _context.stop();
|
|
422
|
+
}
|
|
423
|
+
}, _loop);
|
|
424
|
+
});
|
|
425
|
+
i = 0;
|
|
426
|
+
case 12:
|
|
427
|
+
if (!(i < metas.length)) {
|
|
428
|
+
_context2.next = 17;
|
|
429
|
+
break;
|
|
430
|
+
}
|
|
431
|
+
return _context2.delegateYield(_loop(), "t0", 14);
|
|
432
|
+
case 14:
|
|
433
|
+
i++;
|
|
434
|
+
_context2.next = 12;
|
|
435
|
+
break;
|
|
436
|
+
case 17:
|
|
437
|
+
// images
|
|
438
|
+
$.querySelectorAll("img").every(function (el) {
|
|
439
|
+
var src = el.getAttribute("src");
|
|
440
|
+
if (src) {
|
|
441
|
+
meta.image = new URL(src, url).href;
|
|
442
|
+
return false;
|
|
443
|
+
}
|
|
444
|
+
return true;
|
|
445
|
+
});
|
|
446
|
+
metadata = _extends({
|
|
447
|
+
hostname: getHostname(),
|
|
448
|
+
title: getTitle()
|
|
449
|
+
}, meta);
|
|
450
|
+
return _context2.abrupt("return", metadata);
|
|
451
|
+
case 20:
|
|
452
|
+
case "end":
|
|
453
|
+
return _context2.stop();
|
|
454
|
+
}
|
|
455
|
+
}, _callee);
|
|
456
|
+
}));
|
|
457
|
+
return function getMetadata(_x) {
|
|
458
|
+
return _ref.apply(this, arguments);
|
|
459
|
+
};
|
|
460
|
+
}();
|
|
461
|
+
|
|
462
|
+
var LinkPreview = function LinkPreview(_ref) {
|
|
463
|
+
var _metadata$title;
|
|
464
|
+
var url = _ref.url,
|
|
465
|
+
children = _ref.children,
|
|
466
|
+
loadingMessage = _ref.loadingMessage,
|
|
467
|
+
noPreviewMessage = _ref.noPreviewMessage,
|
|
468
|
+
showLoading = _ref.showLoading,
|
|
469
|
+
showNoPreview = _ref.showNoPreview;
|
|
470
|
+
var _isMounted = React.useRef(true);
|
|
471
|
+
var _useState = React.useState({}),
|
|
472
|
+
metadata = _useState[0],
|
|
473
|
+
setMetadata = _useState[1];
|
|
474
|
+
var _useState2 = React.useState(false),
|
|
475
|
+
isLoading = _useState2[0],
|
|
476
|
+
setIsLoading = _useState2[1];
|
|
477
|
+
var isEditMode = !!host.usePlasmicCanvasContext();
|
|
478
|
+
var resetMetadata = React.useCallback(function () {
|
|
479
|
+
setMetadata({
|
|
480
|
+
title: "",
|
|
481
|
+
description: "",
|
|
482
|
+
image: "",
|
|
483
|
+
siteName: "",
|
|
484
|
+
hostname: ""
|
|
485
|
+
});
|
|
486
|
+
}, []);
|
|
487
|
+
React.useEffect(function () {
|
|
488
|
+
_isMounted.current = true;
|
|
489
|
+
if (!url) return;
|
|
490
|
+
setIsLoading(true);
|
|
491
|
+
resetMetadata();
|
|
492
|
+
getMetadata(url).then(function (res) {
|
|
493
|
+
if (_isMounted.current) {
|
|
494
|
+
setMetadata(res);
|
|
495
|
+
setIsLoading(false);
|
|
496
|
+
}
|
|
497
|
+
})["catch"](function (err) {
|
|
498
|
+
console.error(err);
|
|
499
|
+
console.error("No metadata could be found for the given URL.");
|
|
500
|
+
if (_isMounted.current) {
|
|
501
|
+
resetMetadata();
|
|
502
|
+
setIsLoading(false);
|
|
503
|
+
}
|
|
504
|
+
});
|
|
505
|
+
return function () {
|
|
506
|
+
_isMounted.current = false;
|
|
507
|
+
};
|
|
508
|
+
}, [resetMetadata, url]);
|
|
509
|
+
var showLoadingProp = isEditMode ? showLoading : false;
|
|
510
|
+
var showNoPreviewProp = isEditMode ? showNoPreview : false;
|
|
511
|
+
var hasChildren = children == null ? void 0 : children.props.children;
|
|
512
|
+
var hasMetadata = (metadata == null || (_metadata$title = metadata.title) == null ? void 0 : _metadata$title.length) && !metadata.title.startsWith("Origin DNS error");
|
|
513
|
+
var body = hasChildren ? React__default.createElement(React__default.Fragment, null, children) : React__default.createElement("p", null, metadata.title);
|
|
514
|
+
var hidePreview = isLoading || showLoadingProp || showNoPreviewProp || !hasMetadata;
|
|
515
|
+
var hasNoPreview = !isLoading && !hasMetadata;
|
|
516
|
+
return React__default.createElement("div", null, React__default.createElement(host.DataProvider, {
|
|
517
|
+
name: "metadata",
|
|
518
|
+
data: metadata
|
|
519
|
+
}, React__default.createElement("div", {
|
|
520
|
+
style: hidePreview ? {
|
|
521
|
+
display: "none"
|
|
522
|
+
} : {}
|
|
523
|
+
}, body), (hasNoPreview || showNoPreviewProp) && noPreviewMessage, (isLoading || showLoadingProp) && loadingMessage));
|
|
524
|
+
};
|
|
525
|
+
var rlpComponentName = "plasmic-link-preview";
|
|
526
|
+
function registerLinkPreview(loader) {
|
|
527
|
+
registerComponentHelper(loader, LinkPreview, {
|
|
528
|
+
name: rlpComponentName,
|
|
529
|
+
providesData: true,
|
|
530
|
+
displayName: "Link Preview",
|
|
531
|
+
props: {
|
|
532
|
+
url: {
|
|
533
|
+
type: "string",
|
|
534
|
+
displayName: "URL",
|
|
535
|
+
defaultValue: "https://plasmic.app",
|
|
536
|
+
defaultValueHint: "https://example.com",
|
|
537
|
+
validator: function validator(value) {
|
|
538
|
+
if (isValidUrl(value)) return true;
|
|
539
|
+
return "Invalid URL";
|
|
540
|
+
},
|
|
541
|
+
description: "The URL for which you want to generate the link preview."
|
|
542
|
+
},
|
|
543
|
+
children: {
|
|
544
|
+
type: "slot",
|
|
545
|
+
hidePlaceholder: true
|
|
546
|
+
},
|
|
547
|
+
noPreviewMessage: {
|
|
548
|
+
type: "slot",
|
|
549
|
+
displayName: "'No Preview' Message",
|
|
550
|
+
hidePlaceholder: true,
|
|
551
|
+
defaultValue: [{
|
|
552
|
+
type: "text",
|
|
553
|
+
value: "no preview..."
|
|
554
|
+
}]
|
|
555
|
+
},
|
|
556
|
+
showLoading: {
|
|
557
|
+
type: "boolean",
|
|
558
|
+
description: "You can enable this prop to show the loading message, so you can easily customize it. This prop has no effect in the live app."
|
|
559
|
+
},
|
|
560
|
+
showNoPreview: {
|
|
561
|
+
type: "boolean",
|
|
562
|
+
description: "You can enable this prop to show the 'No Preview' message, so you can easily customize it. This prop has no effect in the live app."
|
|
563
|
+
},
|
|
564
|
+
loadingMessage: {
|
|
565
|
+
type: "slot",
|
|
566
|
+
displayName: "Loading Message",
|
|
567
|
+
hidePlaceholder: true,
|
|
568
|
+
defaultValue: [{
|
|
569
|
+
type: "text",
|
|
570
|
+
value: "loading preview..."
|
|
571
|
+
}]
|
|
572
|
+
}
|
|
573
|
+
},
|
|
574
|
+
importPath: "@plasmicpkgs/plasmic-link-preview",
|
|
575
|
+
importName: "LinkPreview"
|
|
576
|
+
});
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
exports.LinkPreview = LinkPreview;
|
|
580
|
+
exports.registerLinkPreview = registerLinkPreview;
|
|
581
|
+
exports.rlpComponentName = rlpComponentName;
|
|
582
|
+
//# sourceMappingURL=plasmic-link-preview.cjs.development.js.map
|