@mujian/js-sdk 0.0.6-beta.11 → 0.0.6-beta.13

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.
Files changed (2) hide show
  1. package/dist/react.js +17 -11
  2. package/package.json +1 -1
package/dist/react.js CHANGED
@@ -325,6 +325,9 @@ function adjustIframeHeight(iframe) {
325
325
  const height = Math.max(document1.body.offsetHeight, document1.documentElement.offsetHeight);
326
326
  if (!Number.isFinite(height) || height <= 0) return;
327
327
  iframe.style.height = `${height}px`;
328
+ iframe.contentWindow.postMessage({
329
+ type: "MJ_UPDATE_VIEWPORT_HEIGHT"
330
+ }, "*");
328
331
  }
329
332
  const observed_elements = new Map();
330
333
  const observer = new ResizeObserver((entries)=>{
@@ -337,14 +340,14 @@ const observer = new ResizeObserver((entries)=>{
337
340
  function useHeightObserver() {
338
341
  return {
339
342
  observe: (iframe)=>{
340
- if (!iframe.contentWindow || !iframe.contentWindow.document || !iframe.contentWindow.document.body) return;
343
+ if (!iframe?.contentWindow?.document?.body) return;
341
344
  const body = iframe.contentWindow.document.body;
342
345
  observed_elements.set(body, iframe);
343
346
  observer.observe(body);
344
347
  adjustIframeHeight(iframe);
345
348
  },
346
349
  unobserve: (iframe)=>{
347
- if (!iframe.contentWindow || !iframe.contentWindow.document || !iframe.contentWindow.document.body) return;
350
+ if (!iframe.contentWindow?.document?.body) return;
348
351
  const body = iframe.contentWindow.document.body;
349
352
  observed_elements.delete(body);
350
353
  observer.unobserve(body);
@@ -359,7 +362,6 @@ const MdRendererBase = ({ content })=>{
359
362
  useEffect(()=>{
360
363
  let mes = messageFormatting(content);
361
364
  mes = mes.replace(/<code(.*)>[\s\S]*?<\/code>/g, (match)=>{
362
- console.log("match");
363
365
  const code = match.replace("<code>", "").replace("</code>", "");
364
366
  const srcdoc = createSrcContent(unescapeHTML(code));
365
367
  const id = v4();
@@ -374,27 +376,32 @@ const MdRendererBase = ({ content })=>{
374
376
  </div>
375
377
  `;
376
378
  });
377
- console.log("mes", mes);
378
379
  if (containerRef.current) containerRef.current.innerHTML = mes;
379
380
  }, [
380
381
  content
381
382
  ]);
382
383
  useEffect(()=>{
384
+ document.documentElement.style.setProperty("--MJ-iframe-height", `${window.parent.innerHeight}px`);
385
+ window.addEventListener("message", function(event) {
386
+ console.log("event", event);
387
+ if (event.data?.type === "MJ_UPDATE_VIEWPORT_HEIGHT") document.documentElement.style.setProperty("--MJ-iframe-height", `${window.parent.innerHeight}px`);
388
+ });
389
+ }, []);
390
+ useEffect(()=>{
391
+ console.log("iframeIdList", iframeIdList.current);
383
392
  iframeIdList.current.forEach((id)=>{
384
393
  const iframe = document.getElementById("MJ-iframe-" + id);
385
- observe(iframe);
394
+ if (!iframe) return;
386
395
  iframe.addEventListener("load", ()=>{
387
- console.log("iframe loaded", id);
396
+ observe(iframe);
388
397
  const spinElement = iframe.parentElement?.querySelector("#MJ-spin-" + id);
389
398
  if (spinElement) spinElement.remove();
390
- var iframeDoc = iframe.contentDocument || iframe.contentWindow?.document;
391
- var height = iframeDoc?.body?.scrollHeight || 0;
392
- iframe.style.height = height + "px";
393
399
  });
394
400
  });
395
401
  return ()=>{
396
402
  iframeIdList.current.forEach((id)=>{
397
403
  const iframe = document.getElementById("MJ-iframe-" + id);
404
+ if (!iframe) return;
398
405
  unobserve(iframe);
399
406
  const spinElement = iframe.parentElement?.querySelector("#MJ-spin-" + iframe.id);
400
407
  if (spinElement) spinElement.remove();
@@ -404,8 +411,7 @@ const MdRendererBase = ({ content })=>{
404
411
  });
405
412
  };
406
413
  }, [
407
- observe,
408
- unobserve
414
+ iframeIdList.current
409
415
  ]);
410
416
  return /*#__PURE__*/ jsx("div", {
411
417
  className: "mes_text",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mujian/js-sdk",
3
- "version": "0.0.6-beta.11",
3
+ "version": "0.0.6-beta.13",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {