@mujian/js-sdk 0.0.6-beta.17 → 0.0.6-beta.18

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.
@@ -6,4 +6,4 @@ export declare const replaceVhInContent: (content: string) => string;
6
6
  * @returns 转义后的值
7
7
  */
8
8
  export declare function escapeHtmlAttribute(value: string): string;
9
- export declare function createSrcContent(content: string, use_blob_url?: boolean): string;
9
+ export declare function createSrcContent(content: string): string;
@@ -0,0 +1,4 @@
1
+ export declare const iframeDOMLoaded = "\n(function () {\n function emit_loaded_event() {\n window.parent.postMessage({ type: 'MJ_DOM_CONTENT_LOADED', iframeId: '123' }, '*');\n }\n\n if (window.document.readyState === 'loading') {\n window.document.addEventListener('DOMContentLoaded', emit_loaded_event, { once: true });\n } else {\n emit_loaded_event();\n }\n})();\n";
2
+ export declare const iframeAdjustViewport: string;
3
+ export declare const init = "\n(function () {\n\nwindow.$mujian = window.parent.$mujian;\n$mujian?.init().then(() => {\n $mujian?.ai.chat.project.getInfo().then((result) => {\n console.log('result', result);\n });\n});\n\n})();\n";
4
+ export declare const thirdParty = "\n<link rel=\"stylesheet\" href=\"https://testingcf.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css\" />\n<script src=\"https://testingcf.jsdelivr.net/gh/N0VI028/JS-Slash-Runner/lib/tailwindcss.min.js\"></script>\n<script src=\"https://testingcf.jsdelivr.net/npm/jquery/dist/jquery.min.js\"></script>\n<script src=\"https://testingcf.jsdelivr.net/npm/jquery-ui/dist/jquery-ui.min.js\"></script>\n<link rel=\"stylesheet\" href=\"https://testingcf.jsdelivr.net/npm/jquery-ui/themes/base/theme.min.css\" />\n<script src=\"https://testingcf.jsdelivr.net/npm/jquery-ui-touch-punch\"></script>\n";
package/dist/react.js CHANGED
@@ -235,6 +235,27 @@ function messageFormatting(mes, sanitizerOverrides = {}) {
235
235
  });
236
236
  return mes;
237
237
  }
238
+ window.parent.innerHeight, window.parent.innerHeight;
239
+ const init = `
240
+ (function () {
241
+
242
+ window.$mujian = window.parent.$mujian;
243
+ $mujian?.init().then(() => {
244
+ $mujian?.ai.chat.project.getInfo().then((result) => {
245
+ console.log('result', result);
246
+ });
247
+ });
248
+
249
+ })();
250
+ `;
251
+ const thirdParty = `
252
+ <link rel="stylesheet" href="https://testingcf.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" />
253
+ <script src="https://testingcf.jsdelivr.net/gh/N0VI028/JS-Slash-Runner/lib/tailwindcss.min.js"></script>
254
+ <script src="https://testingcf.jsdelivr.net/npm/jquery/dist/jquery.min.js"></script>
255
+ <script src="https://testingcf.jsdelivr.net/npm/jquery-ui/dist/jquery-ui.min.js"></script>
256
+ <link rel="stylesheet" href="https://testingcf.jsdelivr.net/npm/jquery-ui/themes/base/theme.min.css" />
257
+ <script src="https://testingcf.jsdelivr.net/npm/jquery-ui-touch-punch"></script>
258
+ `;
238
259
  const unescapeHTML = (str)=>{
239
260
  const named = {
240
261
  amp: "&",
@@ -291,14 +312,10 @@ const replaceVhInContent = (content)=>{
291
312
  function escapeHtmlAttribute(value) {
292
313
  return value.replace(/"/g, "&quot;").replace(/'/g, "&#39;");
293
314
  }
294
- function createSrcContent(content, use_blob_url = false) {
315
+ function createSrcContent(content) {
295
316
  content = replaceVhInContent(content);
296
317
  const getUserAvatarPath = ()=>"https://www.mujian.com/avatar.png";
297
318
  const getCharAvatarPath = ()=>"https://www.mujian.com/avatar.png";
298
- const third_party = "";
299
- const predefine_url = "";
300
- const emit_loaded_event_url = "";
301
- const adjust_viewport_url = "";
302
319
  return `
303
320
  <html>
304
321
  <head>
@@ -307,11 +324,10 @@ html,body{margin:0;padding:0;overflow:hidden!important;max-width:100%!important;
307
324
  .user_avatar,.user-avatar{background-image:url('${getUserAvatarPath()}')}
308
325
  .char_avatar,.char-avatar{background-image:url('${getCharAvatarPath()}')}
309
326
  </style>
310
- ${third_party}
311
- ${use_blob_url ? `<base href="${window.location.origin}"/>` : ""}
312
- <script src="${predefine_url}"></script>
313
- <script src="${emit_loaded_event_url}"></script>
314
- <script src="${adjust_viewport_url}"></script>
327
+ ${thirdParty}
328
+ <script>
329
+ ${init}
330
+ </script>
315
331
  </head>
316
332
  <body>
317
333
  ${content}
@@ -356,7 +372,6 @@ function useHeightObserver() {
356
372
  }
357
373
  const MdRendererBase = ({ content })=>{
358
374
  const containerRef = useRef(null);
359
- useRef([]);
360
375
  const [iframeIdList, setIframeIdList] = useState([]);
361
376
  const { observe, unobserve } = useHeightObserver();
362
377
  useEffect(()=>{
@@ -365,10 +380,10 @@ const MdRendererBase = ({ content })=>{
365
380
  const code = match.replace("<code>", "").replace("</code>", "");
366
381
  const srcdoc = createSrcContent(unescapeHTML(code));
367
382
  const id = v4();
368
- setIframeIdList([
369
- ...iframeIdList,
370
- id
371
- ]);
383
+ setIframeIdList((prev)=>[
384
+ ...prev,
385
+ id
386
+ ]);
372
387
  const escapedSrcdoc = escapeHtmlAttribute(srcdoc);
373
388
  return `
374
389
  <div class="MJ-iframe-container" id="MJ-iframe-container-${id}" style="display:flex;width:100%;height:100%;position:relative;">
@@ -384,7 +399,6 @@ const MdRendererBase = ({ content })=>{
384
399
  content
385
400
  ]);
386
401
  useEffect(()=>{
387
- console.log("iframeIdList", iframeIdList);
388
402
  iframeIdList.forEach((id)=>{
389
403
  const iframe = document.getElementById("MJ-iframe-" + id);
390
404
  if (!iframe) return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mujian/js-sdk",
3
- "version": "0.0.6-beta.17",
3
+ "version": "0.0.6-beta.18",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
File without changes