Skip to content

Commit

Permalink
Experiment using a Native Editor that reuses the gutenberg store
Browse files Browse the repository at this point in the history
  • Loading branch information
Tug committed Nov 5, 2018
1 parent 0bfa3a6 commit c0ddc7e
Show file tree
Hide file tree
Showing 34 changed files with 15,137 additions and 1,094 deletions.
2 changes: 1 addition & 1 deletion gutenberg
13,041 changes: 13,041 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"@babel/plugin-transform-runtime": "^7.1.0",
"@wordpress/babel-preset-default": "^1.1.2",
"@wordpress/block-serialization-spec-parser": "^1.0.0",
"@wordpress/scripts": "^2.4.0",
"babel-core": "^7.0.0-bridge.0",
"babel-eslint": "^8.2.2",
"babel-jest": "^23.6.0",
Expand Down Expand Up @@ -71,8 +72,8 @@
"clean:metro": "rm -rf $TMPDIR/metro-cache-*;",
"clean:react": "rm -rf $TMPDIR/react-*",
"clean:node": "rm -rf node_modules",
"clean:watchman": "command -v watchman >/dev/null 2>&1 && watchman watch-del-all; true",
"clean:babel-cache": "rm -rf ./node_modules/.cache/babel-loader/*",
"clean:watchman": "command -v watchman >/dev/null 2>&1 && watchman watch-del-all; true",
"clean:babel-cache": "rm -rf ./node_modules/.cache/babel-loader/*",
"lint": "eslint . --ext .js",
"lint:fix": "yarn lint --fix"
},
Expand All @@ -88,6 +89,8 @@
"jsdom-jscore": "git+https://github.com/iamcco/jsdom-jscore-rn.git#6eac88dd5d5e7c21ce6382abde7dbc376d7f7f59",
"jsx-to-string": "^1.3.1",
"memize": "^1.0.5",
"moment": "^2.22.1",
"moment-timezone": "^0.5.16",
"node-libs-react-native": "^1.0.2",
"node-sass": "^4.8.3",
"react": "16.5.0",
Expand All @@ -97,6 +100,9 @@
"react-native-svg": "^6.5.2",
"react-redux": "^5.0.7",
"redux": "^3.7.2",
"redux-multi": "^0.1.12",
"redux-optimist": "^1.0.0",
"refx": "^3.0.0",
"rememo": "^3.0.0",
"shallowequal": "^1.0.2",
"simple-html-tokenizer": "^0.5.1",
Expand Down
45 changes: 12 additions & 33 deletions src/app/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,19 @@

import '../globals';

import React from 'react';
import { Provider } from 'react-redux';
import { setupStore, html2State } from '../store';
import AppContainer from './AppContainer';
import { Store } from 'redux';
// Gutenberg imports
import { registerCoreBlocks } from '@wordpress/block-library';
import {
registerBlockType,
setUnregisteredTypeHandlerName,
} from '@wordpress/blocks';

import initialHtml from './initial-html';
import Editor from '../components/editor';

type PropsType = {
initialData: string | Store,
};
type StateType = {
store: Store,
};
import * as UnsupportedBlock from '../block-types/unsupported-block/';

export default class AppProvider extends React.Component<PropsType, StateType> {
state: StateType;
registerCoreBlocks();
registerBlockType( UnsupportedBlock.name, UnsupportedBlock.settings );
setUnregisteredTypeHandlerName( UnsupportedBlock.name );

constructor( props: PropsType ) {
super( props );

this.state = {
store:
typeof props.initialData === 'object' ?
props.initialData :
setupStore( html2State( props.initialData || initialHtml ) ),
};
}

render() {
return (
<Provider store={ this.state.store }>
<AppContainer />
</Provider>
);
}
}
export default Editor;
21 changes: 5 additions & 16 deletions src/app/App.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
import renderer from 'react-test-renderer';

import App from './App';
import initialHtml from './initial-html';
import { html2State, setupStore } from '../store';
import BlockHolder from '../block-management/block-holder';
import BlockListBlock from '../components/editor/block-list/block';

describe( 'App', () => {
it( 'renders without crashing', () => {
Expand All @@ -15,17 +13,8 @@ describe( 'App', () => {
} );

it( 'renders without crashing with a block focused', () => {
// construct a state object with the first block focused
const state = html2State( initialHtml );
const block0 = { ...state.blocks[ 0 ] };
block0.focused = true;
state.blocks[ 0 ] = block0;

// create a Store with the state object
const store = setupStore( state );

// render an App using the specified Store
const app = renderer.create( <App initialData={ store } /> );
// render an App using the default Store
const app = renderer.create( <App /> );
const rendered = app.toJSON();

// App should be rendered OK
Expand All @@ -35,7 +24,7 @@ describe( 'App', () => {
it( 'Code block is a TextInput', () => {
renderer
.create( <App /> )
.root.findAllByType( BlockHolder )
.root.findAllByType( BlockListBlock )
.forEach( ( blockHolder ) => {
if ( 'core/code' === blockHolder.props.name ) {
// TODO: hardcoded indices are ugly and error prone. Can we do better here?
Expand All @@ -52,7 +41,7 @@ describe( 'App', () => {
it( 'Heading block test', () => {
renderer
.create( <App /> )
.root.findAllByType( BlockHolder )
.root.findAllByType( BlockListBlock )
.forEach( ( blockHolder ) => {
if ( 'core/heading' === blockHolder.props.name ) {
const aztec = blockHolder.findByType( 'RCTAztecView' );
Expand Down
48 changes: 0 additions & 48 deletions src/app/AppContainer.js

This file was deleted.

15 changes: 0 additions & 15 deletions src/app/MainApp.js

This file was deleted.

112 changes: 0 additions & 112 deletions src/block-management/block-holder.js

This file was deleted.

0 comments on commit c0ddc7e

Please sign in to comment.