Skip to content

Commit 2bd3a21

Browse files
authored
Merge pull request #143 from Automattic/components
React components
2 parents d981044 + aac73cc commit 2bd3a21

File tree

108 files changed

+1082
-640
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+1082
-640
lines changed

Makefile

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ node_modules: package.json yarn.lock
77
yarn install
88

99
build/frontend: frontend
10-
yarn build:popup
11-
yarn build:block
10+
yarn build
1211

13-
build/block: block
14-
yarn build:block-internal
12+
build/block: frontend/block
13+
yarn build:block

bin/prepare-release.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ else
3939
fi
4040

4141
# Substitute version in all relevant files.
42-
for file in package.json composer.json block/block.json
42+
for file in package.json composer.json frontend/block/block.json
4343
do
4444
jq ".version = \"$VERSION\"" $file > $file.tmp
4545
mv $file.tmp $file

block/iframe.tsx

Lines changed: 0 additions & 60 deletions
This file was deleted.

block/style.scss

Lines changed: 0 additions & 14 deletions
This file was deleted.
File renamed without changes.

frontend/app.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { BlockProps } from "./components/block";
2+
3+
import { render as renderBlockInternal } from "./components/block/render";
4+
import { PopupProps } from "./components/popup";
5+
import { render as renderPopupInternal } from "./components/popup/render";
6+
7+
export function renderBlock(containerId: string, props: BlockProps) {
8+
props.iframeUrl = getIframeUrl();
9+
return renderBlockInternal(containerId, props);
10+
}
11+
12+
export function renderPopup(containerId: string, props: PopupProps) {
13+
props.iframeUrl = getIframeUrl();
14+
return renderPopupInternal(containerId, props);
15+
}
16+
17+
export function getIframeUrl(): URL {
18+
let rootUrl = window.origin;
19+
const config = window.ChatrixConfig ?? null;
20+
if (config && config.rootUrl) {
21+
rootUrl = config.rootUrl;
22+
}
23+
24+
return new URL("iframe.html", rootUrl);
25+
}
26+
27+
declare global {
28+
interface Window {
29+
ChatrixConfig: {
30+
rootUrl: string;
31+
};
32+
}
33+
}
File renamed without changes.

block/edit.tsx renamed to frontend/block/edit.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { useBlockProps } from "@wordpress/block-editor";
22
import { ResizableBox } from "@wordpress/components";
33
import { WPElement } from '@wordpress/element';
4-
import { parseAttributes } from "./attributes";
4+
import { getIframeUrl } from "../app";
5+
import { Block, BlockProps, parseAttributes } from "../components/block";
56
import './editor.scss';
6-
import IFrame, { IframeProps } from "./iframe";
77
import InspectorControls from "./inspector/InspectorControls";
88

99
interface Props {
@@ -12,12 +12,13 @@ interface Props {
1212
}
1313

1414
export default function Edit(props: Props): WPElement {
15-
const { setAttributes } = props;
16-
const attributes = parseAttributes(props.attributes);
15+
const { attributes, setAttributes } = props;
16+
const parsedAttributes = parseAttributes(attributes);
1717

18-
const iframeProps: IframeProps = {
18+
const blockProps: BlockProps = {
1919
focusable: true,
20-
...attributes
20+
attributes,
21+
iframeUrl: getIframeUrl(),
2122
};
2223

2324
return (
@@ -27,7 +28,7 @@ export default function Edit(props: Props): WPElement {
2728
<ResizableBox
2829
size={{
2930
width: "100%",
30-
height: attributes.height.toString(),
31+
height: parsedAttributes.height ? parsedAttributes.height.toString() : "600px",
3132
}}
3233
enable={{
3334
top: false,
@@ -43,7 +44,7 @@ export default function Edit(props: Props): WPElement {
4344
setAttributes({ height: { value: elt.clientHeight, unit: "px" } });
4445
}}
4546
>
46-
<IFrame {...iframeProps}/>
47+
<Block {...blockProps}/>
4748
</ResizableBox>
4849
</div>
4950
</>
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)