qureal-editor 1.0.17 → 1.0.19
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/dist/index.es.js +81 -1
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +81 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.es.js
CHANGED
|
@@ -6,6 +6,35 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
|
|
|
6
6
|
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
|
7
7
|
};
|
|
8
8
|
|
|
9
|
+
var asyncToGenerator = function (fn) {
|
|
10
|
+
return function () {
|
|
11
|
+
var gen = fn.apply(this, arguments);
|
|
12
|
+
return new Promise(function (resolve, reject) {
|
|
13
|
+
function step(key, arg) {
|
|
14
|
+
try {
|
|
15
|
+
var info = gen[key](arg);
|
|
16
|
+
var value = info.value;
|
|
17
|
+
} catch (error) {
|
|
18
|
+
reject(error);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (info.done) {
|
|
23
|
+
resolve(value);
|
|
24
|
+
} else {
|
|
25
|
+
return Promise.resolve(value).then(function (value) {
|
|
26
|
+
step("next", value);
|
|
27
|
+
}, function (err) {
|
|
28
|
+
step("throw", err);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return step("next");
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
|
|
9
38
|
var _extends = Object.assign || function (target) {
|
|
10
39
|
for (var i = 1; i < arguments.length; i++) {
|
|
11
40
|
var source = arguments[i];
|
|
@@ -83,7 +112,8 @@ function QurealiFrame(_ref) {
|
|
|
83
112
|
height: "100vh",
|
|
84
113
|
outline: "none",
|
|
85
114
|
border: "1px solid #777"
|
|
86
|
-
}, style)
|
|
115
|
+
}, style),
|
|
116
|
+
allow: "web-share"
|
|
87
117
|
})
|
|
88
118
|
);
|
|
89
119
|
}
|
|
@@ -93,6 +123,53 @@ var QurealiFrame$1 = React.memo(QurealiFrame, function () {
|
|
|
93
123
|
return true;
|
|
94
124
|
});
|
|
95
125
|
|
|
126
|
+
var share = function () {
|
|
127
|
+
var _ref = asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(data) {
|
|
128
|
+
return regeneratorRuntime.wrap(function _callee$(_context) {
|
|
129
|
+
while (1) {
|
|
130
|
+
switch (_context.prev = _context.next) {
|
|
131
|
+
case 0:
|
|
132
|
+
_context.prev = 0;
|
|
133
|
+
|
|
134
|
+
if (!(navigator.share && navigator.canShare(data))) {
|
|
135
|
+
_context.next = 6;
|
|
136
|
+
break;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
_context.next = 4;
|
|
140
|
+
return navigator.share(data);
|
|
141
|
+
|
|
142
|
+
case 4:
|
|
143
|
+
_context.next = 8;
|
|
144
|
+
break;
|
|
145
|
+
|
|
146
|
+
case 6:
|
|
147
|
+
console.error("Can't share");
|
|
148
|
+
alert("Share only available for mobile devices");
|
|
149
|
+
|
|
150
|
+
case 8:
|
|
151
|
+
_context.next = 13;
|
|
152
|
+
break;
|
|
153
|
+
|
|
154
|
+
case 10:
|
|
155
|
+
_context.prev = 10;
|
|
156
|
+
_context.t0 = _context["catch"](0);
|
|
157
|
+
|
|
158
|
+
console.error(_context.t0);
|
|
159
|
+
|
|
160
|
+
case 13:
|
|
161
|
+
case "end":
|
|
162
|
+
return _context.stop();
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}, _callee, this, [[0, 10]]);
|
|
166
|
+
}));
|
|
167
|
+
|
|
168
|
+
return function share(_x) {
|
|
169
|
+
return _ref.apply(this, arguments);
|
|
170
|
+
};
|
|
171
|
+
}();
|
|
172
|
+
|
|
96
173
|
var ALLOWED_ORIGINS = ["https://show.qureal.com", "http://localhost:3201"];
|
|
97
174
|
|
|
98
175
|
function QurealViewer(_ref) {
|
|
@@ -177,6 +254,9 @@ function QurealViewer(_ref) {
|
|
|
177
254
|
case "FORM_SUBMIT":
|
|
178
255
|
onFormSubmit(ev.data.data);
|
|
179
256
|
break;
|
|
257
|
+
case "SHARE":
|
|
258
|
+
share(ev.data.data);
|
|
259
|
+
break;
|
|
180
260
|
default:
|
|
181
261
|
console.log("No event type found");
|
|
182
262
|
console.log(ev.data);
|
package/dist/index.es.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.es.js","sources":["../src/QurealiFrame.js","../src/QurealViewer.js","../src/use-action.js"],"sourcesContent":["import React, { Fragment, useEffect, useRef } from \"react\";\n\n\nfunction QurealiFrame({ slug, preview, query, type = \"creation\", style = {} }) {\n\n\n return (\n <Fragment>\n <iframe\n id=\"qureal_iframe\"\n title=\"Qureal\"\n // src={`http://localhost:3201/embed/${creation_slug}`}\n // src={type === \"creation\" ? `https://show.qureal.com/embed/${slug}?${preview ? \"preview&\" : \"\"}${query}` : `https://show.qureal.com/ts/${slug}?${preview ? \"preview&\" : \"\"}${query}`}\n src={`https://show.qureal.com/${type === \"creation\" ? \"embed\" : \"ts\"}/${slug}?${preview ? \"preview&\" : \"\"}${query}`}\n // src={type === \"creation\" ? `http://localhost:3201/embed/${slug}?${preview ? \"preview&\" : \"\"}${query}` : `https://show.qureal.com/ts/${slug}`}\n style={{\n width: \"100%\",\n height: \"100vh\",\n outline: \"none\",\n border: \"1px solid #777\",\n ...style\n }}\n />\n </Fragment>\n );\n}\n\n// export default QurealiFrame;\nexport default React.memo(QurealiFrame, () => true)\n","import React, { Fragment, useEffect, useRef } from \"react\";\nimport QurealiFrame from \"./QurealiFrame\";\n\nconst ALLOWED_ORIGINS = [\"https://show.qureal.com\", \"http://localhost:3201\"];\n\nfunction QurealViewer({\n slug = \"qi_sample\",\n preview = false,\n prefill = {},\n type = \"creation\", // creation or template \n onFormSubmit = () => { },\n style = {},\n actionRef = {},\n organization = null,\n person = null,\n background = null,\n fit = false,\n}) {\n\n const sendToIFrame = (msg) => {\n console.log(\"Sending data to iFrame\")\n const qureal_element = document.getElementById(\"qureal_iframe\");\n\n const qureal_window = qureal_element ? qureal_element.contentWindow : null;\n if (qureal_window) {\n qureal_window.postMessage(msg, \"*\");\n console.log(\"Data sent to iframe\")\n }\n }\n\n useEffect(() => {\n sendToIFrame({\n message_type: \"OPEN_CREATION\",\n data: {\n slug: slug,\n preview: preview,\n prefill: prefill\n }\n })\n }, [slug, preview])\n\n useEffect(() => {\n sendToIFrame({\n message_type: \"PREFILL\",\n data: {\n prefill: prefill\n }\n })\n }, [prefill])\n\n useEffect(() => {\n if ([\"DOWNLOAD\", \"SHARE\"].includes(actionRef.type)) {\n sendToIFrame({\n message_type: actionRef.type,\n data: actionRef.data || {}\n })\n }\n }, [actionRef])\n\n useEffect(() => {\n sendToIFrame({\n message_type: \"SET_ICTX\",\n data: {\n organization: organization,\n person: person\n }\n })\n }, [organization, person])\n\n useEffect(() => {\n const handler = (ev) => {\n if (ALLOWED_ORIGINS.includes(ev.origin) && typeof ev.data === \"object\") {\n switch (ev.data.event_type) {\n case \"FORM_SUBMIT\":\n onFormSubmit(ev.data.data);\n break;\n default:\n console.log(\"No event type found\");\n console.log(ev.data);\n }\n }\n };\n\n window.addEventListener(\"message\", handler);\n return () => window.removeEventListener(\"message\", handler);\n }, []);\n\n return (\n <QurealiFrame\n slug={slug}\n preview={preview}\n query={`${queryfy(prefill)}${organization ? `&qi_organization=${organization}` : \"\"}${person ? `&qi_person=${person}` : \"\"}${background ? `&qi_background=${background}` : \"\"}${fit ? \"&qi_fit\" : \"\"}`}\n type={type}\n style={style}\n />\n );\n}\n\n// export default QurealiFrame;\nexport default QurealViewer\n\n\nfunction queryfy(obj) {\n const buildQuery = (prefix, obj) => {\n return Object.keys(obj)\n .map(key => {\n const value = obj[key];\n const prefixedKey = prefix ? `${prefix}.${key}` : key;\n if (typeof value === 'object' && value !== null) {\n return buildQuery(prefixedKey, value);\n } else {\n return `${prefixedKey}=${value}`;\n }\n })\n .join(\"&\");\n };\n\n return buildQuery(\"\", obj);\n}","import { useState } from \"react\"\n\nfunction useQurealActions() {\n const [actionRef, setActionRef] = useState({});\n\n function download() {\n setActionRef({\n type: \"DOWNLOAD\",\n data: {}\n })\n }\n\n\n function share() {\n setActionRef({\n type: \"SHARE\",\n data: {}\n })\n }\n\n return { actionRef, download, share }\n}\n\nexport default useQurealActions;"],"names":["QurealiFrame","slug","preview","query","type","style","React","memo","ALLOWED_ORIGINS","QurealViewer","prefill","onFormSubmit","actionRef","organization","person","background","fit","sendToIFrame","msg","log","qureal_element","document","getElementById","qureal_window","contentWindow","postMessage","includes","
|
|
1
|
+
{"version":3,"file":"index.es.js","sources":["../src/QurealiFrame.js","../src/utils.js","../src/QurealViewer.js","../src/use-action.js"],"sourcesContent":["import React, { Fragment, useEffect, useRef } from \"react\";\n\n\nfunction QurealiFrame({ slug, preview, query, type = \"creation\", style = {} }) {\n\n\n return (\n <Fragment>\n <iframe\n id=\"qureal_iframe\"\n title=\"Qureal\"\n // src={`http://localhost:3201/embed/${creation_slug}`}\n // src={type === \"creation\" ? `https://show.qureal.com/embed/${slug}?${preview ? \"preview&\" : \"\"}${query}` : `https://show.qureal.com/ts/${slug}?${preview ? \"preview&\" : \"\"}${query}`}\n src={`https://show.qureal.com/${type === \"creation\" ? \"embed\" : \"ts\"}/${slug}?${preview ? \"preview&\" : \"\"}${query}`}\n // src={type === \"creation\" ? `http://localhost:3201/embed/${slug}?${preview ? \"preview&\" : \"\"}${query}` : `https://show.qureal.com/ts/${slug}`}\n style={{\n width: \"100%\",\n height: \"100vh\",\n outline: \"none\",\n border: \"1px solid #777\",\n ...style\n }}\n allow=\"web-share\"\n />\n </Fragment>\n );\n}\n\n// export default QurealiFrame;\nexport default React.memo(QurealiFrame, () => true)\n","export async function share(data) {\n try {\n if (navigator.share && navigator.canShare(data)) {\n await navigator.share(data);\n } else {\n console.error(\"Can't share\");\n alert(\"Share only available for mobile devices\")\n }\n } catch (err) {\n console.error(err);\n }\n}","import React, { Fragment, useEffect, useRef } from \"react\";\nimport QurealiFrame from \"./QurealiFrame\";\nimport { share } from \"./utils\";\n\nconst ALLOWED_ORIGINS = [\"https://show.qureal.com\", \"http://localhost:3201\"];\n\nfunction QurealViewer({\n slug = \"qi_sample\",\n preview = false,\n prefill = {},\n type = \"creation\", // creation or template \n onFormSubmit = () => { },\n style = {},\n actionRef = {},\n organization = null,\n person = null,\n background = null,\n fit = false,\n}) {\n\n const sendToIFrame = (msg) => {\n console.log(\"Sending data to iFrame\")\n const qureal_element = document.getElementById(\"qureal_iframe\");\n\n const qureal_window = qureal_element ? qureal_element.contentWindow : null;\n if (qureal_window) {\n qureal_window.postMessage(msg, \"*\");\n console.log(\"Data sent to iframe\")\n }\n }\n\n useEffect(() => {\n sendToIFrame({\n message_type: \"OPEN_CREATION\",\n data: {\n slug: slug,\n preview: preview,\n prefill: prefill\n }\n })\n }, [slug, preview])\n\n useEffect(() => {\n sendToIFrame({\n message_type: \"PREFILL\",\n data: {\n prefill: prefill\n }\n })\n }, [prefill])\n\n useEffect(() => {\n if ([\"DOWNLOAD\", \"SHARE\"].includes(actionRef.type)) {\n sendToIFrame({\n message_type: actionRef.type,\n data: actionRef.data || {}\n })\n }\n }, [actionRef])\n\n useEffect(() => {\n sendToIFrame({\n message_type: \"SET_ICTX\",\n data: {\n organization: organization,\n person: person\n }\n })\n }, [organization, person])\n\n useEffect(() => {\n const handler = (ev) => {\n if (ALLOWED_ORIGINS.includes(ev.origin) && typeof ev.data === \"object\") {\n switch (ev.data.event_type) {\n case \"FORM_SUBMIT\":\n onFormSubmit(ev.data.data);\n break;\n case \"SHARE\":\n share(ev.data.data);\n break;\n default:\n console.log(\"No event type found\");\n console.log(ev.data);\n }\n }\n };\n\n window.addEventListener(\"message\", handler);\n return () => window.removeEventListener(\"message\", handler);\n }, []);\n\n return (\n <QurealiFrame\n slug={slug}\n preview={preview}\n query={`${queryfy(prefill)}${organization ? `&qi_organization=${organization}` : \"\"}${person ? `&qi_person=${person}` : \"\"}${background ? `&qi_background=${background}` : \"\"}${fit ? \"&qi_fit\" : \"\"}`}\n type={type}\n style={style}\n />\n );\n}\n\n// export default QurealiFrame;\nexport default QurealViewer\n\n\nfunction queryfy(obj) {\n const buildQuery = (prefix, obj) => {\n return Object.keys(obj)\n .map(key => {\n const value = obj[key];\n const prefixedKey = prefix ? `${prefix}.${key}` : key;\n if (typeof value === 'object' && value !== null) {\n return buildQuery(prefixedKey, value);\n } else {\n return `${prefixedKey}=${value}`;\n }\n })\n .join(\"&\");\n };\n\n return buildQuery(\"\", obj);\n}","import { useState } from \"react\"\n\nfunction useQurealActions() {\n const [actionRef, setActionRef] = useState({});\n\n function download() {\n setActionRef({\n type: \"DOWNLOAD\",\n data: {}\n })\n }\n\n\n function share() {\n setActionRef({\n type: \"SHARE\",\n data: {}\n })\n }\n\n return { actionRef, download, share }\n}\n\nexport default useQurealActions;"],"names":["QurealiFrame","slug","preview","query","type","style","React","memo","data","navigator","share","canShare","error","ALLOWED_ORIGINS","QurealViewer","prefill","onFormSubmit","actionRef","organization","person","background","fit","sendToIFrame","msg","log","qureal_element","document","getElementById","qureal_window","contentWindow","postMessage","includes","handler","ev","origin","babelHelpers.typeof","event_type","addEventListener","window","removeEventListener","queryfy","obj","buildQuery","prefix","Object","keys","map","value","key","prefixedKey","join","useQurealActions","useState","setActionRef","download"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,SAASA,YAAT,OAA+E;QAAvDC,IAAuD,QAAvDA,IAAuD;QAAjDC,OAAiD,QAAjDA,OAAiD;QAAxCC,KAAwC,QAAxCA,KAAwC;yBAAjCC,IAAiC;QAAjCA,IAAiC,6BAA1B,UAA0B;0BAAdC,KAAc;QAAdA,KAAc,8BAAN,EAAM;;;WAIvE;gBAAA;;;gBAEW,eADP;mBAEU;;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,GAAoD,EAAjF,KAAsFC,yBAAuBA,MAAvB,GAAkC,EAAxH,KAA6HC,iCAA+BA,UAA/B,GAA8C,EAA3K,KAAgLC,MAAM,SAAN,GAAkB,EAAlM,CAHJ;cAIUjB,IAJV;eAKWC;MANf;;;AAeJ,SAASmC,OAAT,CAAiBC,GAAjB,EAAsB;QACZC,aAAa,SAAbA,UAAa,CAACC,MAAD,EAASF,GAAT,EAAiB;eACzBG,OAAOC,IAAP,CAAYJ,GAAZ,EACFK,GADE,CACE,eAAO;gBACFC,QAAQN,IAAIO,GAAJ,CAAd;gBACMC,cAAcN,SAAYA,MAAZ,SAAsBK,GAAtB,GAA8BA,GAAlD;gBACI,QAAOD,KAAP,yCAAOA,KAAP,OAAiB,QAAjB,IAA6BA,UAAU,IAA3C,EAAiD;uBACtCL,WAAWO,WAAX,EAAwBF,KAAxB,CAAP;aADJ,MAEO;uBACOE,WAAV,SAAyBF,KAAzB;;SAPL,EAUFG,IAVE,CAUG,GAVH,CAAP;KADJ;;WAcOR,WAAW,EAAX,EAAeD,GAAf,CAAP;;;ACvHJ,SAASU,gBAAT,GAA4B;oBACUC,SAAS,EAAT,CADV;;QACjBnC,SADiB;QACNoC,YADM;;aAGfC,QAAT,GAAoB;qBACH;kBACH,UADG;kBAEH;SAFV;;;aAOK5C,KAAT,GAAiB;qBACA;kBACH,OADG;kBAEH;SAFV;;;WAMG,EAAEO,oBAAF,EAAaqC,kBAAb,EAAuB5C,YAAvB,EAAP;;;;;"}
|
package/dist/index.js
CHANGED
|
@@ -13,6 +13,35 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
|
|
|
13
13
|
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
+
var asyncToGenerator = function (fn) {
|
|
17
|
+
return function () {
|
|
18
|
+
var gen = fn.apply(this, arguments);
|
|
19
|
+
return new Promise(function (resolve, reject) {
|
|
20
|
+
function step(key, arg) {
|
|
21
|
+
try {
|
|
22
|
+
var info = gen[key](arg);
|
|
23
|
+
var value = info.value;
|
|
24
|
+
} catch (error) {
|
|
25
|
+
reject(error);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (info.done) {
|
|
30
|
+
resolve(value);
|
|
31
|
+
} else {
|
|
32
|
+
return Promise.resolve(value).then(function (value) {
|
|
33
|
+
step("next", value);
|
|
34
|
+
}, function (err) {
|
|
35
|
+
step("throw", err);
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return step("next");
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
|
|
16
45
|
var _extends = Object.assign || function (target) {
|
|
17
46
|
for (var i = 1; i < arguments.length; i++) {
|
|
18
47
|
var source = arguments[i];
|
|
@@ -90,7 +119,8 @@ function QurealiFrame(_ref) {
|
|
|
90
119
|
height: "100vh",
|
|
91
120
|
outline: "none",
|
|
92
121
|
border: "1px solid #777"
|
|
93
|
-
}, style)
|
|
122
|
+
}, style),
|
|
123
|
+
allow: "web-share"
|
|
94
124
|
})
|
|
95
125
|
);
|
|
96
126
|
}
|
|
@@ -100,6 +130,53 @@ var QurealiFrame$1 = React__default.memo(QurealiFrame, function () {
|
|
|
100
130
|
return true;
|
|
101
131
|
});
|
|
102
132
|
|
|
133
|
+
var share = function () {
|
|
134
|
+
var _ref = asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(data) {
|
|
135
|
+
return regeneratorRuntime.wrap(function _callee$(_context) {
|
|
136
|
+
while (1) {
|
|
137
|
+
switch (_context.prev = _context.next) {
|
|
138
|
+
case 0:
|
|
139
|
+
_context.prev = 0;
|
|
140
|
+
|
|
141
|
+
if (!(navigator.share && navigator.canShare(data))) {
|
|
142
|
+
_context.next = 6;
|
|
143
|
+
break;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
_context.next = 4;
|
|
147
|
+
return navigator.share(data);
|
|
148
|
+
|
|
149
|
+
case 4:
|
|
150
|
+
_context.next = 8;
|
|
151
|
+
break;
|
|
152
|
+
|
|
153
|
+
case 6:
|
|
154
|
+
console.error("Can't share");
|
|
155
|
+
alert("Share only available for mobile devices");
|
|
156
|
+
|
|
157
|
+
case 8:
|
|
158
|
+
_context.next = 13;
|
|
159
|
+
break;
|
|
160
|
+
|
|
161
|
+
case 10:
|
|
162
|
+
_context.prev = 10;
|
|
163
|
+
_context.t0 = _context["catch"](0);
|
|
164
|
+
|
|
165
|
+
console.error(_context.t0);
|
|
166
|
+
|
|
167
|
+
case 13:
|
|
168
|
+
case "end":
|
|
169
|
+
return _context.stop();
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}, _callee, this, [[0, 10]]);
|
|
173
|
+
}));
|
|
174
|
+
|
|
175
|
+
return function share(_x) {
|
|
176
|
+
return _ref.apply(this, arguments);
|
|
177
|
+
};
|
|
178
|
+
}();
|
|
179
|
+
|
|
103
180
|
var ALLOWED_ORIGINS = ["https://show.qureal.com", "http://localhost:3201"];
|
|
104
181
|
|
|
105
182
|
function QurealViewer(_ref) {
|
|
@@ -184,6 +261,9 @@ function QurealViewer(_ref) {
|
|
|
184
261
|
case "FORM_SUBMIT":
|
|
185
262
|
onFormSubmit(ev.data.data);
|
|
186
263
|
break;
|
|
264
|
+
case "SHARE":
|
|
265
|
+
share(ev.data.data);
|
|
266
|
+
break;
|
|
187
267
|
default:
|
|
188
268
|
console.log("No event type found");
|
|
189
269
|
console.log(ev.data);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/QurealiFrame.js","../src/QurealViewer.js","../src/use-action.js"],"sourcesContent":["import React, { Fragment, useEffect, useRef } from \"react\";\n\n\nfunction QurealiFrame({ slug, preview, query, type = \"creation\", style = {} }) {\n\n\n return (\n <Fragment>\n <iframe\n id=\"qureal_iframe\"\n title=\"Qureal\"\n // src={`http://localhost:3201/embed/${creation_slug}`}\n // src={type === \"creation\" ? `https://show.qureal.com/embed/${slug}?${preview ? \"preview&\" : \"\"}${query}` : `https://show.qureal.com/ts/${slug}?${preview ? \"preview&\" : \"\"}${query}`}\n src={`https://show.qureal.com/${type === \"creation\" ? \"embed\" : \"ts\"}/${slug}?${preview ? \"preview&\" : \"\"}${query}`}\n // src={type === \"creation\" ? `http://localhost:3201/embed/${slug}?${preview ? \"preview&\" : \"\"}${query}` : `https://show.qureal.com/ts/${slug}`}\n style={{\n width: \"100%\",\n height: \"100vh\",\n outline: \"none\",\n border: \"1px solid #777\",\n ...style\n }}\n />\n </Fragment>\n );\n}\n\n// export default QurealiFrame;\nexport default React.memo(QurealiFrame, () => true)\n","import React, { Fragment, useEffect, useRef } from \"react\";\nimport QurealiFrame from \"./QurealiFrame\";\n\nconst ALLOWED_ORIGINS = [\"https://show.qureal.com\", \"http://localhost:3201\"];\n\nfunction QurealViewer({\n slug = \"qi_sample\",\n preview = false,\n prefill = {},\n type = \"creation\", // creation or template \n onFormSubmit = () => { },\n style = {},\n actionRef = {},\n organization = null,\n person = null,\n background = null,\n fit = false,\n}) {\n\n const sendToIFrame = (msg) => {\n console.log(\"Sending data to iFrame\")\n const qureal_element = document.getElementById(\"qureal_iframe\");\n\n const qureal_window = qureal_element ? qureal_element.contentWindow : null;\n if (qureal_window) {\n qureal_window.postMessage(msg, \"*\");\n console.log(\"Data sent to iframe\")\n }\n }\n\n useEffect(() => {\n sendToIFrame({\n message_type: \"OPEN_CREATION\",\n data: {\n slug: slug,\n preview: preview,\n prefill: prefill\n }\n })\n }, [slug, preview])\n\n useEffect(() => {\n sendToIFrame({\n message_type: \"PREFILL\",\n data: {\n prefill: prefill\n }\n })\n }, [prefill])\n\n useEffect(() => {\n if ([\"DOWNLOAD\", \"SHARE\"].includes(actionRef.type)) {\n sendToIFrame({\n message_type: actionRef.type,\n data: actionRef.data || {}\n })\n }\n }, [actionRef])\n\n useEffect(() => {\n sendToIFrame({\n message_type: \"SET_ICTX\",\n data: {\n organization: organization,\n person: person\n }\n })\n }, [organization, person])\n\n useEffect(() => {\n const handler = (ev) => {\n if (ALLOWED_ORIGINS.includes(ev.origin) && typeof ev.data === \"object\") {\n switch (ev.data.event_type) {\n case \"FORM_SUBMIT\":\n onFormSubmit(ev.data.data);\n break;\n default:\n console.log(\"No event type found\");\n console.log(ev.data);\n }\n }\n };\n\n window.addEventListener(\"message\", handler);\n return () => window.removeEventListener(\"message\", handler);\n }, []);\n\n return (\n <QurealiFrame\n slug={slug}\n preview={preview}\n query={`${queryfy(prefill)}${organization ? `&qi_organization=${organization}` : \"\"}${person ? `&qi_person=${person}` : \"\"}${background ? `&qi_background=${background}` : \"\"}${fit ? \"&qi_fit\" : \"\"}`}\n type={type}\n style={style}\n />\n );\n}\n\n// export default QurealiFrame;\nexport default QurealViewer\n\n\nfunction queryfy(obj) {\n const buildQuery = (prefix, obj) => {\n return Object.keys(obj)\n .map(key => {\n const value = obj[key];\n const prefixedKey = prefix ? `${prefix}.${key}` : key;\n if (typeof value === 'object' && value !== null) {\n return buildQuery(prefixedKey, value);\n } else {\n return `${prefixedKey}=${value}`;\n }\n })\n .join(\"&\");\n };\n\n return buildQuery(\"\", obj);\n}","import { useState } from \"react\"\n\nfunction useQurealActions() {\n const [actionRef, setActionRef] = useState({});\n\n function download() {\n setActionRef({\n type: \"DOWNLOAD\",\n data: {}\n })\n }\n\n\n function share() {\n setActionRef({\n type: \"SHARE\",\n data: {}\n })\n }\n\n return { actionRef, download, share }\n}\n\nexport default useQurealActions;"],"names":["QurealiFrame","slug","preview","query","type","style","React","memo","ALLOWED_ORIGINS","QurealViewer","prefill","onFormSubmit","actionRef","organization","person","background","fit","sendToIFrame","msg","log","qureal_element","document","getElementById","qureal_window","contentWindow","postMessage","includes","
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/QurealiFrame.js","../src/utils.js","../src/QurealViewer.js","../src/use-action.js"],"sourcesContent":["import React, { Fragment, useEffect, useRef } from \"react\";\n\n\nfunction QurealiFrame({ slug, preview, query, type = \"creation\", style = {} }) {\n\n\n return (\n <Fragment>\n <iframe\n id=\"qureal_iframe\"\n title=\"Qureal\"\n // src={`http://localhost:3201/embed/${creation_slug}`}\n // src={type === \"creation\" ? `https://show.qureal.com/embed/${slug}?${preview ? \"preview&\" : \"\"}${query}` : `https://show.qureal.com/ts/${slug}?${preview ? \"preview&\" : \"\"}${query}`}\n src={`https://show.qureal.com/${type === \"creation\" ? \"embed\" : \"ts\"}/${slug}?${preview ? \"preview&\" : \"\"}${query}`}\n // src={type === \"creation\" ? `http://localhost:3201/embed/${slug}?${preview ? \"preview&\" : \"\"}${query}` : `https://show.qureal.com/ts/${slug}`}\n style={{\n width: \"100%\",\n height: \"100vh\",\n outline: \"none\",\n border: \"1px solid #777\",\n ...style\n }}\n allow=\"web-share\"\n />\n </Fragment>\n );\n}\n\n// export default QurealiFrame;\nexport default React.memo(QurealiFrame, () => true)\n","export async function share(data) {\n try {\n if (navigator.share && navigator.canShare(data)) {\n await navigator.share(data);\n } else {\n console.error(\"Can't share\");\n alert(\"Share only available for mobile devices\")\n }\n } catch (err) {\n console.error(err);\n }\n}","import React, { Fragment, useEffect, useRef } from \"react\";\nimport QurealiFrame from \"./QurealiFrame\";\nimport { share } from \"./utils\";\n\nconst ALLOWED_ORIGINS = [\"https://show.qureal.com\", \"http://localhost:3201\"];\n\nfunction QurealViewer({\n slug = \"qi_sample\",\n preview = false,\n prefill = {},\n type = \"creation\", // creation or template \n onFormSubmit = () => { },\n style = {},\n actionRef = {},\n organization = null,\n person = null,\n background = null,\n fit = false,\n}) {\n\n const sendToIFrame = (msg) => {\n console.log(\"Sending data to iFrame\")\n const qureal_element = document.getElementById(\"qureal_iframe\");\n\n const qureal_window = qureal_element ? qureal_element.contentWindow : null;\n if (qureal_window) {\n qureal_window.postMessage(msg, \"*\");\n console.log(\"Data sent to iframe\")\n }\n }\n\n useEffect(() => {\n sendToIFrame({\n message_type: \"OPEN_CREATION\",\n data: {\n slug: slug,\n preview: preview,\n prefill: prefill\n }\n })\n }, [slug, preview])\n\n useEffect(() => {\n sendToIFrame({\n message_type: \"PREFILL\",\n data: {\n prefill: prefill\n }\n })\n }, [prefill])\n\n useEffect(() => {\n if ([\"DOWNLOAD\", \"SHARE\"].includes(actionRef.type)) {\n sendToIFrame({\n message_type: actionRef.type,\n data: actionRef.data || {}\n })\n }\n }, [actionRef])\n\n useEffect(() => {\n sendToIFrame({\n message_type: \"SET_ICTX\",\n data: {\n organization: organization,\n person: person\n }\n })\n }, [organization, person])\n\n useEffect(() => {\n const handler = (ev) => {\n if (ALLOWED_ORIGINS.includes(ev.origin) && typeof ev.data === \"object\") {\n switch (ev.data.event_type) {\n case \"FORM_SUBMIT\":\n onFormSubmit(ev.data.data);\n break;\n case \"SHARE\":\n share(ev.data.data);\n break;\n default:\n console.log(\"No event type found\");\n console.log(ev.data);\n }\n }\n };\n\n window.addEventListener(\"message\", handler);\n return () => window.removeEventListener(\"message\", handler);\n }, []);\n\n return (\n <QurealiFrame\n slug={slug}\n preview={preview}\n query={`${queryfy(prefill)}${organization ? `&qi_organization=${organization}` : \"\"}${person ? `&qi_person=${person}` : \"\"}${background ? `&qi_background=${background}` : \"\"}${fit ? \"&qi_fit\" : \"\"}`}\n type={type}\n style={style}\n />\n );\n}\n\n// export default QurealiFrame;\nexport default QurealViewer\n\n\nfunction queryfy(obj) {\n const buildQuery = (prefix, obj) => {\n return Object.keys(obj)\n .map(key => {\n const value = obj[key];\n const prefixedKey = prefix ? `${prefix}.${key}` : key;\n if (typeof value === 'object' && value !== null) {\n return buildQuery(prefixedKey, value);\n } else {\n return `${prefixedKey}=${value}`;\n }\n })\n .join(\"&\");\n };\n\n return buildQuery(\"\", obj);\n}","import { useState } from \"react\"\n\nfunction useQurealActions() {\n const [actionRef, setActionRef] = useState({});\n\n function download() {\n setActionRef({\n type: \"DOWNLOAD\",\n data: {}\n })\n }\n\n\n function share() {\n setActionRef({\n type: \"SHARE\",\n data: {}\n })\n }\n\n return { actionRef, download, share }\n}\n\nexport default useQurealActions;"],"names":["QurealiFrame","slug","preview","query","type","style","React","memo","data","navigator","share","canShare","error","ALLOWED_ORIGINS","QurealViewer","prefill","onFormSubmit","actionRef","organization","person","background","fit","sendToIFrame","msg","log","qureal_element","document","getElementById","qureal_window","contentWindow","postMessage","includes","handler","ev","origin","babelHelpers.typeof","event_type","addEventListener","window","removeEventListener","queryfy","obj","buildQuery","prefix","Object","keys","map","value","key","prefixedKey","join","useQurealActions","useState","setActionRef","download"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,SAASA,YAAT,OAA+E;QAAvDC,IAAuD,QAAvDA,IAAuD;QAAjDC,OAAiD,QAAjDA,OAAiD;QAAxCC,KAAwC,QAAxCA,KAAwC;yBAAjCC,IAAiC;QAAjCA,IAAiC,6BAA1B,UAA0B;0BAAdC,KAAc;QAAdA,KAAc,8BAAN,EAAM;;;WAIvEC;sBAAA;;;gBAEW,eADP;mBAEU;;;cAGN,mCAAgCF,SAAS,UAAT,GAAsB,OAAtB,GAAgC,IAAhE,UAAwEH,IAAxE,UAAgFC,UAAU,UAAV,GAAuB,EAAvG,IAA4GC;;cAE5G;uBACW,MADX;wBAEY,OAFZ;yBAGa,MAHb;wBAIY;eACLE,KALP,CAPJ;mBAcU;;KAhBlB;;;;AAuBJ,qBAAeC,eAAMC,IAAN,CAAWP,YAAX,EAAyB;WAAM,IAAN;CAAzB,CAAf;;;sEC7BO,iBAAqBQ,IAArB;;;;;;;8BAEKC,UAAUC,KAAV,IAAmBD,UAAUE,QAAV,CAAmBH,IAAnB,CAFxB;;;;;;+BAGWC,UAAUC,KAAV,CAAgBF,IAAhB,CAHX;;;;;;;gCAKaI,KAAR,CAAc,aAAd;8BACM,yCAAN;;;;;;;;;;gCAGIA,KAAR;;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