Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support larger rendering input #66

Merged
merged 1 commit into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions src/managers/message-component-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ export async function preloadRenderer() {
embedMessage({messageId: ""}, preloadFrameId);
}

export function loadEmbedComponent(elementId, url, message) {
export function loadEmbedComponent(elementId, url, message, options) {
var element = safelyFetchElement(elementId);
if (element) {
element.classList.add(getMessageElementId(message.instanceId));
var messageElementId = getMessageElementId(message.instanceId);
element.classList.add(messageElementId);
var messageProperties = resolveMessageProperties(message);
var messageWidth = messageProperties.messageWidth + "px";
if (wideOverlayPositions.includes(elementId) && !messageProperties.hasCustomWidth) {
Expand All @@ -45,6 +46,7 @@ export function loadEmbedComponent(elementId, url, message) {
element.style.height = "0px";
}
element.innerHTML = embed(url, message, messageProperties);
attachIframeLoadEvent(messageElementId, options);
} else {
log(`Message could not be embedded, elementId ${elementId} not found.`);
}
Expand Down Expand Up @@ -94,8 +96,25 @@ export function resizeComponent(message, size) {
}
}

export function loadOverlayComponent(url, message) {
export function loadOverlayComponent(url, message, options) {
document.body.insertAdjacentHTML('afterbegin', component(url, message));
attachIframeLoadEvent(getMessageElementId(message.instanceId), options);
}

function attachIframeLoadEvent(elementId, options) {
const iframe = document.getElementById(elementId);
if (iframe) {
iframe.onload = function() {
sendOptionsToIframe(elementId, options); // Send the options when iframe loads
};
}
}

function sendOptionsToIframe(iframeId, options) {
const iframe = document.getElementById(iframeId);
if (iframe && iframe.contentWindow) {
iframe.contentWindow.postMessage({ options: options }, '*');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is where is sends a message to the renderer javascript with the options.

}
}

export function showOverlayComponent(message) {
Expand Down
14 changes: 3 additions & 11 deletions src/managers/message-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,28 +126,20 @@ function loadMessageComponent(message, elementId = null) {
livePreview: false,
properties: message.properties
}
var url = `${settings.GIST_VIEW_ENDPOINT[Gist.config.env]}/index.html?options=${encodeUnicode(JSON.stringify(options))}`
var url = `${settings.GIST_VIEW_ENDPOINT[Gist.config.env]}/index.html`
window.addEventListener('message', handleGistEvents);
window.addEventListener('touchstart', handleTouchStartEvents);

if (elementId) {
if (positions.includes(elementId)) { addPageElement(elementId); }
loadEmbedComponent(elementId, url, message);
loadEmbedComponent(elementId, url, message, options);
} else {
loadOverlayComponent(url, message);
loadOverlayComponent(url, message, options);
}

return message;
}

function encodeUnicode(str) {
var base64Unicode = btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g,
function toSolidBytes(match, p1) {
return String.fromCharCode('0x' + p1);
}));

return encodeURIComponent(base64Unicode);
}

async function reportMessageView(message) {
log(`Message shown, logging view for: ${message.messageId}`);
Expand Down
2 changes: 1 addition & 1 deletion src/services/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const settings = {
},
GIST_VIEW_ENDPOINT: {
"prod": "https://renderer.gist.build/2.0",
"dev": "https://renderer.gist.build/2.0",
"dev": "https://renderer.gist.build/beta",
"local": "http://app.local.gist.build:8080/web"
}
}