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

Remove markdown iframe #949

Merged
merged 74 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
7b9242d
fix solution action
Megha-Dev-19 Dec 7, 2023
a9fee68
Merge branch 'main' of https://github.com/Megha-Dev-19/neardevhub-wid…
Megha-Dev-19 Dec 8, 2023
7c6ee84
Merge branch 'near:main' into main
Megha-Dev-19 Dec 18, 2023
218a120
Merge branch 'NEAR-DevHub:main' into main
Megha-Dev-19 Dec 18, 2023
ac0bd6e
Merge branch 'NEAR-DevHub:main' into main
Megha-Dev-19 Dec 19, 2023
6d31741
Merge branch 'NEAR-DevHub:main' into main
Megha-Dev-19 Dec 29, 2023
1fd7eb1
Merge branch 'NEAR-DevHub:main' into main
Megha-Dev-19 Dec 30, 2023
9a4c7a2
Merge branch 'main' of https://github.com/Megha-Dev-19/neardevhub-wid…
Megha-Dev-19 Jan 3, 2024
07c55a3
Merge branch 'NEAR-DevHub:main' into main
Megha-Dev-19 Jan 4, 2024
fa8d436
Merge branch 'NEAR-DevHub:main' into main
Megha-Dev-19 Jan 5, 2024
4b75fa1
Merge branch 'NEAR-DevHub:main' into main
Megha-Dev-19 Jan 8, 2024
2b5e027
Merge branch 'NEAR-DevHub:main' into main
Megha-Dev-19 Jan 19, 2024
d2bae2d
Merge branch 'NEAR-DevHub:main' into main
Megha-Dev-19 Jan 23, 2024
57b6e52
Merge branch 'NEAR-DevHub:main' into main
Megha-Dev-19 Jan 31, 2024
2d33aef
Merge branch 'NEAR-DevHub:main' into main
Megha-Dev-19 Feb 27, 2024
71a8a62
Merge branch 'NEAR-DevHub:main' into main
Megha-Dev-19 Mar 1, 2024
6cd1c40
Merge branch 'NEAR-DevHub:main' into main
Megha-Dev-19 Mar 4, 2024
8bdc2ce
Merge branch 'NEAR-DevHub:main' into main
Megha-Dev-19 Mar 5, 2024
d6a282d
Merge branch 'NEAR-DevHub:main' into main
Megha-Dev-19 Mar 12, 2024
955cc35
Merge branch 'NEAR-DevHub:main' into main
Megha-Dev-19 Mar 13, 2024
120ac1a
Merge branch 'NEAR-DevHub:main' into main
Megha-Dev-19 Mar 22, 2024
86bed07
Merge branch 'NEAR-DevHub:main' into main
Megha-Dev-19 Mar 23, 2024
3807a10
Merge branch 'NEAR-DevHub:main' into main
Megha-Dev-19 Mar 23, 2024
769373b
Merge branch 'NEAR-DevHub:main' into main
Megha-Dev-19 Mar 25, 2024
8252826
Merge branch 'NEAR-DevHub:main' into main
Megha-Dev-19 Mar 30, 2024
7d59bc0
Merge branch 'NEAR-DevHub:main' into main
Megha-Dev-19 Apr 1, 2024
263522f
Merge branch 'NEAR-DevHub:main' into main
Megha-Dev-19 Apr 2, 2024
ad0520e
Merge branch 'NEAR-DevHub:main' into main
Megha-Dev-19 Apr 4, 2024
b36c120
Merge branch 'NEAR-DevHub:main' into main
Megha-Dev-19 Apr 11, 2024
f91491c
Merge branch 'NEAR-DevHub:main' into main
Megha-Dev-19 Apr 17, 2024
60c60a2
Merge branch 'NEAR-DevHub:main' into main
Megha-Dev-19 Apr 22, 2024
c31e5ca
fix preview for proposals
Megha-Dev-19 Apr 22, 2024
86d21ae
Merge branch 'NEAR-DevHub:main' into main
Megha-Dev-19 Apr 22, 2024
081fe73
Merge branch 'NEAR-DevHub:main' into main
Megha-Dev-19 Apr 24, 2024
951d09f
Merge branch 'NEAR-DevHub:main' into main
Megha-Dev-19 Apr 27, 2024
be358eb
Merge branch 'NEAR-DevHub:main' into main
Megha-Dev-19 May 13, 2024
cabd08c
Merge branch 'NEAR-DevHub:main' into main
Megha-Dev-19 May 21, 2024
97063f2
Merge branch 'NEAR-DevHub:main' into main
Megha-Dev-19 May 30, 2024
4468c0e
Merge branch 'NEAR-DevHub:main' into main
Megha-Dev-19 Jun 4, 2024
214f884
Merge branch 'NEAR-DevHub:main' into main
Megha-Dev-19 Jun 7, 2024
234de81
Merge branch 'NEAR-DevHub:main' into main
Megha-Dev-19 Jun 8, 2024
6c65260
Merge branch 'NEAR-DevHub:main' into main
Megha-Dev-19 Jun 16, 2024
6932cab
Merge branch 'NEAR-DevHub:main' into main
Megha-Dev-19 Jun 26, 2024
552a573
Merge branch 'NEAR-DevHub:main' into main
Megha-Dev-19 Jul 7, 2024
4ce2676
Merge branch 'NEAR-DevHub:main' into main
Megha-Dev-19 Jul 8, 2024
62aa5b5
Merge branch 'NEAR-DevHub:main' into main
Megha-Dev-19 Jul 8, 2024
9b0b1a2
Merge branch 'NEAR-DevHub:main' into main
Megha-Dev-19 Jul 9, 2024
c87e751
Merge branch 'NEAR-DevHub:main' into main
Megha-Dev-19 Jul 10, 2024
77926c2
Merge branch 'NEAR-DevHub:main' into main
Megha-Dev-19 Jul 11, 2024
1f87031
Merge branch 'NEAR-DevHub:main' into main
Megha-Dev-19 Jul 13, 2024
ee2e830
Merge branch 'NEAR-DevHub:main' into main
Megha-Dev-19 Jul 17, 2024
4787c7d
Merge branch 'NEAR-DevHub:main' into main
Megha-Dev-19 Jul 20, 2024
9d2849a
Merge branch 'NEAR-DevHub:main' into main
Megha-Dev-19 Jul 20, 2024
50a5684
Merge branch 'NEAR-DevHub:main' into main
Megha-Dev-19 Jul 20, 2024
1488e93
Merge branch 'NEAR-DevHub:main' into main
Megha-Dev-19 Jul 23, 2024
90d9b91
Merge branch 'NEAR-DevHub:main' into main
Megha-Dev-19 Jul 25, 2024
6fd6e70
Merge branch 'NEAR-DevHub:main' into main
Megha-Dev-19 Jul 26, 2024
9534b54
Merge branch 'NEAR-DevHub:main' into main
Megha-Dev-19 Jul 30, 2024
38d44a0
Merge branch 'NEAR-DevHub:main' into main
Megha-Dev-19 Aug 9, 2024
8e06659
Merge branch 'NEAR-DevHub:main' into main
Megha-Dev-19 Aug 20, 2024
0ec0766
Merge branch 'NEAR-DevHub:main' into main
Megha-Dev-19 Aug 28, 2024
362a643
Merge branch 'NEAR-DevHub:main' into main
Megha-Dev-19 Sep 23, 2024
6d607fc
Merge branch 'NEAR-DevHub:main' into main
Megha-Dev-19 Sep 24, 2024
9c47547
Merge branch 'NEAR-DevHub:main' into main
Megha-Dev-19 Sep 24, 2024
5ec0299
Merge branch 'NEAR-DevHub:main' into main
Megha-Dev-19 Sep 26, 2024
8d8f7a3
Merge branch 'NEAR-DevHub:main' into main
Megha-Dev-19 Sep 29, 2024
b8cdd47
Merge branch 'NEAR-DevHub:main' into main
Megha-Dev-19 Oct 1, 2024
46abb64
Merge branch 'NEAR-DevHub:main' into main
Megha-Dev-19 Oct 8, 2024
910df8c
remove markdown iframe
Megha-Dev-19 Oct 1, 2024
e9db92e
added tests
Megha-Dev-19 Oct 3, 2024
c5bdbf4
fix tests
Megha-Dev-19 Oct 6, 2024
01864a2
fix tests
Megha-Dev-19 Oct 6, 2024
bacd546
fix tests
Megha-Dev-19 Oct 8, 2024
411f4e8
fix conflicts
Megha-Dev-19 Oct 9, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,6 @@ const Compose = ({
src={`${REPL_DEVHUB}/widget/devhub.components.molecule.SimpleMDEViewer`}
props={{
content: state.data,
embeddCSS: `
body{
font-size:14px;
}
`,
}}
/>
</div>
Expand Down Expand Up @@ -189,11 +184,6 @@ const Compose = ({
src={`${REPL_DEVHUB}/widget/devhub.components.molecule.SimpleMDEViewer`}
props={{
content: state.data,
embeddCSS: `
body {
font-size: 14px;
}
`,
}}
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,139 +1,81 @@
const content = props.content ?? "";
const height = props.height;
const embeddCSS = props.embeddCSS;
const [iframeHeight, setIframeHeight] = useState("100px");

const code = `
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/simplemde/latest/simplemde.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/highlight.js/latest/styles/github.min.css">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous">
<style>
body {
margin: 0;
overflow: ${height ? "auto" : "hidden"};
font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", "Noto Sans", "Liberation Sans", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
line-height:1.5;
font-weight:300;
color:#212529;
}
const simplemdeCss = fetch(
"https://cdn.jsdelivr.net/simplemde/latest/simplemde.min.css"
).body;
const githubCss = fetch(
"https://cdn.jsdelivr.net/highlight.js/latest/styles/github.min.css"
).body;

blockquote {
margin: 1em 0;
padding-left: 1.5em;
border-left: 4px solid #ccc;
color: #666;
font-style: italic;
font-size: inherit;
}
const bootstrapCss = fetch(
"https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
).body;

.no-margin {
margin: 0px !important;
}
if (!simplemdeCss || !githubCss || !bootstrapCss) return "";

h1, h2, h3, h4, h5, h6 {
font-weight:500;
margin-block:5px;
}

p {
white-space: pre-wrap;
}

img {
height: 200px;
object-fit:contain;
width: -webkit-fill-available;
}

table {
border: 1px solid #dee2e6;
}
const CssContainer = styled.div`
${githubCss}
${simplemdeCss}

table th, table td {
padding: 0.75rem;
vertical-align: top;
}
font-size:14px;
p {
white-space: normal;
}

table td {
border-top: 1px solid #dee2e6;
}

table thead th {
vertical-align: bottom;
border-bottom: 2px solid #dee2e6;
}

table tbody + tbody {
border-top: 2px solid #dee2e6;
}

/* Zebra-striping */
tbody tr:nth-of-type(odd) {
background-color: rgba(0, 0, 0, 0.05);
}
blockquote {
margin: 1em 0;
padding-left: 1.5em;
border-left: 4px solid #ccc;
color: #666;
font-style: italic;
font-size: inherit;
}

${embeddCSS}
</style>
</head>
<body>
<div id="content"></div>
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
<script>


pre {
background-color: #f4f4f4;
border: 1px solid #ddd;
border-radius: 4px;
padding: 1em;
overflow-x: auto;
font-family: "Courier New", Courier, monospace;
}

function updateContent(content) {
document.getElementById('content').innerHTML = marked.parse(content)
a {
color: #04a46e;
}

const newHeight = Math.max(
document.body.scrollHeight,
document.documentElement.scrollHeight,
document.body.offsetHeight,
document.documentElement.offsetHeight
);

window.parent.postMessage({
handler: 'IFRAME_HEIGHT',
height: newHeight
}, '*');
}
.remove-underline a {
text-decoration: none !important;
}

window.addEventListener('message', (event) => {
if (event.data.content) {
updateContent(event.data.content);
}
});
${embeddCSS}
`;

window.addEventListener('load', () => {
window.parent.postMessage({
handler: 'IFRAME_HEIGHT',
height: document.body.scrollHeight
}, '*');
});
</script>
</body>
</html>
`;
const renderMention =
props.renderMention ??
((accountId) => (
<span
key={accountId}
className="d-inline-flex remove-underline"
style={{ fontWeight: 500 }}
>
<Widget
src="${REPL_DEVHUB}/widget/devhub.components.molecule.ProfileLine"
props={{
accountId: accountId.toLowerCase(),
hideAccountId: true,
tooltip: true,
}}
/>
</span>
));

const processedContent = content
.replace(/<br\s*\/?>/gi, " \n")
.replace(/\n/g, " \n");
return (
<iframe
srcDoc={code}
message={{
content: content,
}}
style={{ height: height ?? iframeHeight }}
className="w-100"
onMessage={(e) => {
switch (e.handler) {
case "IFRAME_HEIGHT": {
setIframeHeight(`${e.height}px`);
break;
}
}
}}
/>
<CssContainer>
<Markdown text={processedContent} onMention={renderMention} />
</CssContainer>
);
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,6 @@ const Comment = ({ commentItem }) => {
src={`${REPL_DEVHUB}/widget/devhub.components.molecule.SimpleMDEViewer`}
props={{
content: content.text,
embeddCSS: `
body {
font-size:14px;
}
`,
}}
/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -870,11 +870,6 @@ return (
src={`${REPL_DEVHUB}/widget/devhub.components.molecule.SimpleMDEViewer`}
props={{
content: snapshot.description,
embeddCSS: `
body {
font-size: 14px;
}
`,
}}
/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,6 @@ const Compose = ({
src={`${REPL_DEVHUB}/widget/devhub.components.molecule.SimpleMDEViewer`}
props={{
content: state.data,
embeddCSS: `
body {
font-size: 14px;
}
`,
}}
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,6 @@ const Comment = ({ commentItem }) => {
src={`${REPL_DEVHUB}/widget/devhub.components.molecule.SimpleMDEViewer`}
props={{
content: content.text,
embeddCSS: `
body {
font-size: 14px;
}
`,
}}
/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -868,11 +868,6 @@ return (
src={`${REPL_DEVHUB}/widget/devhub.components.molecule.SimpleMDEViewer`}
props={{
content: snapshot.description,
embeddCSS: `
body {
font-size: 14px;
}
`,
}}
/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,11 @@ const Compose = ({
/>
</>
) : (
<div className="card-body">
<div className="card-body compose-preview">
<Widget
src={`${REPL_DEVHUB}/widget/devhub.components.molecule.SimpleMDEViewer`}
props={{
content: state.data,
embeddCSS: `
body {
font-size: 14px !important;
}
`,
}}
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -848,11 +848,6 @@ return (
src={`${REPL_DEVHUB}/widget/devhub.components.molecule.SimpleMDEViewer`}
props={{
content: snapshot.description,
embeddCSS: `
body {
font-size: 14px !important;
}
`,
}}
/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -671,11 +671,6 @@ return (
src={`${REPL_DEVHUB}/widget/devhub.components.molecule.SimpleMDEViewer`}
props={{
content: snapshot.description,
embeddCSS: `
body {
font-size: 14px;
}
`,
}}
/>

Expand Down
3 changes: 1 addition & 2 deletions playwright-tests/tests/events/proposals.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,6 @@ test.describe("Wallet is connected", () => {
const delay_milliseconds_between_keypress_when_typing = 0;
const commentEditor = page
.frameLocator("iframe")
.last()
.locator(".CodeMirror textarea");
await commentEditor.focus();
await commentEditor.pressSequentially(
Expand All @@ -492,7 +491,7 @@ test.describe("Wallet is connected", () => {
);

await pauseIfVideoRecording(page);
const iframe = page.frameLocator("iframe").last();
const iframe = page.frameLocator("iframe");
const liFrameLocators = iframe.frameLocator(
'ul[id="mentiondropdown"] > li'
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ test.describe("Wallet is connected", () => {
await expect(aboutHeaderLink).toBeVisible();
await aboutHeaderLink.click();
await expect(
page.frameLocator("iframe").getByRole("heading", { name: "Introduction" })
page.getByRole("heading", { name: "Introduction" })
).toBeVisible();

const proposalsHeaderLink = await page.getByRole("link", {
Expand Down
Loading
Loading