-
Notifications
You must be signed in to change notification settings - Fork 3
React Native Support #15
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
Changes from all commits
2e465e0
1e4a357
f14f042
8eab268
7b1948b
d6d9a82
0ecc870
a4c96c0
457ba4e
9f86661
b2b3feb
b2d8d01
8cf3197
7138415
ed738d5
0353d06
9d69be5
347abcf
8e1ea6e
501f70a
4e892d8
718c65a
f6f9076
c9917fd
461c221
4bed648
f5e6197
8b6204a
23ee7ae
b10596b
2944de6
b231b2e
ef702f3
c1092e4
9314ad7
ab05952
ed2bd6c
9ee68a2
a04bd67
f0b66aa
98edfb9
3bacb68
d7bef2a
931587d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,28 @@ | ||
// @ts-check | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to re-investigate splitting
|
||
import React, { useEffect } from "react"; | ||
import { EditmodeContext } from "./EditmodeContext"; | ||
import { Platform } from 'react-native'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can't safely depend on |
||
|
||
export function Editmode({ children, projectId }) { | ||
if (!projectId) { | ||
throw new Error("<Editmode projectId={...}> is missing a valid projectId"); | ||
} | ||
|
||
useEffect(() => { | ||
window["chunksProjectIdentifier"] = projectId; | ||
let branch; | ||
|
||
const script = document.createElement("script"); | ||
script.src = "https://static.editmode.com/editmode@^1.0.0/dist/editmode.js"; | ||
script.async = true; | ||
document.body.append(script); | ||
}, []); | ||
if (Platform.OS === 'web') { | ||
useEffect(() => { | ||
window["chunksProjectIdentifier"] = projectId; | ||
|
||
let params = new URL(document.location.href).searchParams; | ||
let branch = params.get("em_branch"); | ||
const script = document.createElement("script"); | ||
script.src = "https://static.editmode.com/editmode@^1.0.0/dist/editmode.js"; | ||
script.async = true; | ||
document.body.append(script); | ||
}, []); | ||
|
||
let params = new URL(document.location.href).searchParams; | ||
branch = params.get("em_branch"); | ||
} | ||
|
||
return ( | ||
<EditmodeContext.Provider value={{ branch, projectId }}> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,68 @@ | ||
import DOMpurify from "dompurify"; | ||
import React from "react"; | ||
import { Platform, Text, Image } from 'react-native'; | ||
|
||
export const renderChunk = (cnk, props) => { | ||
let chunk = { ...cnk, content: DOMpurify.sanitize(cnk.content) }; | ||
const sanitizedContent = Platform.OS === 'web' | ||
? DOMpurify.sanitize(cnk.content) | ||
: cnk.content; | ||
|
||
let chunk = { ...cnk, content: sanitizedContent }; | ||
switch (chunk.chunk_type) { | ||
case "single_line_text": | ||
return ( | ||
<em-span | ||
data-chunk={chunk.identifier} | ||
data-chunk-editable={true} | ||
data-chunk-content-key={chunk.content_key} | ||
data-chunk-type="single_line_text" | ||
key={chunk.identifier} | ||
{...props} | ||
> | ||
{chunk.content} | ||
</em-span> | ||
); | ||
case "long_text": | ||
return ( | ||
<em-span | ||
data-chunk={chunk.identifier} | ||
data-chunk-editable={true} | ||
data-chunk-content-key={chunk.content_key} | ||
data-chunk-type="long_text" | ||
key={chunk.identifier} | ||
{...props} | ||
> | ||
{chunk.content} | ||
</em-span> | ||
) | ||
return Platform.OS === 'web' | ||
? (<em-span | ||
data-chunk={chunk.identifier} | ||
data-chunk-editable={true} | ||
data-chunk-content-key={chunk.content_key} | ||
data-chunk-type={chunk.chunk_type} | ||
key={chunk.identifier} | ||
{...props} | ||
> | ||
{chunk.content} | ||
</em-span>) | ||
: (<Text | ||
key={chunk.identifier} | ||
{...props} | ||
> | ||
{chunk.content} | ||
</Text>); | ||
case "rich_text": | ||
return ( | ||
<em-span | ||
class="editmode-richtext-editor" | ||
data-chunk={chunk.identifier} | ||
data-chunk-editable={true} | ||
data-chunk-content-key={chunk.content_key} | ||
data-chunk-type="rich_text" | ||
key={chunk.identifier} | ||
dangerouslySetInnerHTML={{__html: chunk.content}} | ||
{...props} | ||
> | ||
</em-span> | ||
) | ||
return Platform.OS === 'web' | ||
? (<em-span | ||
class="editmode-richtext-editor" | ||
data-chunk={chunk.identifier} | ||
data-chunk-editable={true} | ||
data-chunk-content-key={chunk.content_key} | ||
data-chunk-type="rich_text" | ||
key={chunk.identifier} | ||
dangerouslySetInnerHTML={{__html: chunk.content}} | ||
{...props} | ||
> | ||
</em-span>) | ||
: null; | ||
case "image": | ||
return ( | ||
<img | ||
src={chunk.content} | ||
data-chunk={chunk.identifier} | ||
data-chunk-editable={false} | ||
data-chunk-content-key={chunk.content_key} | ||
data-chunk-type="image" | ||
alt="" | ||
key={chunk.identifier} | ||
{...props} | ||
/> | ||
); | ||
return Platform.OS === 'web' | ||
? (<img | ||
src={chunk.content} | ||
data-chunk={chunk.identifier} | ||
data-chunk-editable={false} | ||
data-chunk-content-key={chunk.content_key} | ||
data-chunk-type="image" | ||
alt="" | ||
key={chunk.identifier} | ||
{...props} | ||
/>) | ||
: (<Image | ||
source={{ | ||
uri: 'https:' + chunk.content, | ||
isStatic: true, | ||
}} | ||
/>); | ||
default: | ||
return <span {...props}>{chunk.content}</span>; | ||
return Platform.OS === 'web' | ||
? <span {...props}>{chunk.content}</span> | ||
: <Text {...props}>{chunk.content}</Text>; | ||
} | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
react
should be both indevDependencies
andpeerDepenencies
because we depend on it for local development directly (e.g.import React from "react"
) and consumers should have it in their project.react-dom
should be apeerDependencies
because consumers should have it in their project.react-native
can be adevDependencies
if we're using it for tests or in a local project, but likely won't need it listed anywhere at all.