Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
2e465e0
bump the version
BosEriko Jul 23, 2020
1e4a357
change package name
BosEriko Jul 23, 2020
f14f042
move back to default name
BosEriko Jul 23, 2020
8eab268
add react native platform message
BosEriko Jul 23, 2020
7b1948b
bump the version
BosEriko Jul 23, 2020
d6d9a82
add react native to the dependencies
BosEriko Jul 23, 2020
0ecc870
move the platform data to renderChunk
BosEriko Jul 23, 2020
a4c96c0
bump the version
BosEriko Jul 23, 2020
457ba4e
move the react native platform data
BosEriko Jul 23, 2020
9f86661
bump the version
BosEriko Jul 23, 2020
b2b3feb
update code
BosEriko Jul 23, 2020
b2d8d01
update platform call method
BosEriko Jul 23, 2020
8cf3197
move checking of platform on the main file
BosEriko Jul 23, 2020
7138415
declare branch outside of the scope
BosEriko Jul 23, 2020
ed738d5
only use sanitize on the web for now
BosEriko Jul 23, 2020
0353d06
fix error on sanitize variable
BosEriko Jul 23, 2020
9d69be5
use text component for react native
BosEriko Jul 24, 2020
347abcf
bump the version
BosEriko Jul 24, 2020
8e1ea6e
add image
BosEriko Jul 24, 2020
501f70a
bump the version
BosEriko Jul 24, 2020
4e892d8
use source instead of src on image chunk
BosEriko Jul 24, 2020
718c65a
bump
BosEriko Jul 24, 2020
f6f9076
update source of image
BosEriko Jul 24, 2020
c9917fd
bump version
BosEriko Jul 24, 2020
461c221
bump version backwards and remove data-chunk on react native
BosEriko Jul 24, 2020
4bed648
remove props for now
BosEriko Jul 25, 2020
f5e6197
bump the version
BosEriko Jul 25, 2020
8b6204a
update image end remove alt
BosEriko Jul 25, 2020
23ee7ae
bump the version
BosEriko Jul 25, 2020
b10596b
add style
BosEriko Jul 25, 2020
2944de6
bump
BosEriko Jul 25, 2020
b231b2e
update border width
BosEriko Jul 25, 2020
ef702f3
bump
BosEriko Jul 25, 2020
c1092e4
remove unwanted keys
BosEriko Jul 25, 2020
9314ad7
add static on image
BosEriko Jul 25, 2020
ab05952
update
BosEriko Jul 25, 2020
ed2bd6c
add https to file
BosEriko Jul 25, 2020
9ee68a2
remove text from image
BosEriko Jul 25, 2020
a04bd67
bump the version down
BosEriko Jul 26, 2020
f0b66aa
remove image
BosEriko Jul 26, 2020
98edfb9
update ternary operator to multiple lines
BosEriko Jul 26, 2020
3bacb68
Merge master
BosEriko Aug 3, 2020
d7bef2a
fix the version
BosEriko Aug 3, 2020
931587d
remove native files
BosEriko Aug 3, 2020
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
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"dompurify": "^2.0.11",
"lodash-es": "^4.17.15",
"react": "^16.13.1",
Copy link
Contributor

Choose a reason for hiding this comment

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

  • react should be both in devDependencies and peerDepenencies 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 a peerDependencies because consumers should have it in their project.
  • react-native can be a devDependencies if we're using it for tests or in a local project, but likely won't need it listed anywhere at all.

"react-dom": "^16.13.1"
"react-dom": "^16.13.1",
"react-native": "^0.63.2"
},
"devDependencies": {
"@auto-it/all-contributors": "^9.35.1",
Expand Down
23 changes: 14 additions & 9 deletions src/Editmode.jsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
// @ts-check
Copy link
Contributor

Choose a reason for hiding this comment

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

We need to re-investigate splitting Editmode.jsx into 2 files:

  • Editmode.jsx for web
  • Editmode.native.jsx for react-native

import React, { useEffect } from "react";
import { EditmodeContext } from "./EditmodeContext";
import { Platform } from 'react-native';
Copy link
Contributor

Choose a reason for hiding this comment

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

We can't safely depend on react-native within a web environment because of how react-native publishes to NPM (under the expectation that it's bundled via expo or metro bundler)


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 }}>
Expand Down
107 changes: 56 additions & 51 deletions src/utils/renderChunk.jsx
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>;
}
};
Loading