From 376d25d609d30dd20e5338922076eef33720b0c2 Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Mon, 10 Apr 2017 19:49:40 -0400 Subject: [PATCH 1/5] Move block store into nested API directory --- blocks/{ => api}/README.md | 0 blocks/{ => api}/categories.js | 0 blocks/{ => api}/components/editable/index.js | 0 .../{ => api}/components/editable/style.scss | 0 blocks/api/index.js | 18 ++++++++++++++++++ blocks/{ => api}/parser.js | 0 blocks/{ => api}/post.pegjs | 0 blocks/{ => api}/registration.js | 0 blocks/{ => api}/serializer.js | 0 blocks/{ => api}/test/parser.js | 0 blocks/{ => api}/test/registration.js | 0 blocks/{ => api}/test/serializer.js | 0 blocks/index.js | 19 +------------------ 13 files changed, 19 insertions(+), 18 deletions(-) rename blocks/{ => api}/README.md (100%) rename blocks/{ => api}/categories.js (100%) rename blocks/{ => api}/components/editable/index.js (100%) rename blocks/{ => api}/components/editable/style.scss (100%) create mode 100644 blocks/api/index.js rename blocks/{ => api}/parser.js (100%) rename blocks/{ => api}/post.pegjs (100%) rename blocks/{ => api}/registration.js (100%) rename blocks/{ => api}/serializer.js (100%) rename blocks/{ => api}/test/parser.js (100%) rename blocks/{ => api}/test/registration.js (100%) rename blocks/{ => api}/test/serializer.js (100%) diff --git a/blocks/README.md b/blocks/api/README.md similarity index 100% rename from blocks/README.md rename to blocks/api/README.md diff --git a/blocks/categories.js b/blocks/api/categories.js similarity index 100% rename from blocks/categories.js rename to blocks/api/categories.js diff --git a/blocks/components/editable/index.js b/blocks/api/components/editable/index.js similarity index 100% rename from blocks/components/editable/index.js rename to blocks/api/components/editable/index.js diff --git a/blocks/components/editable/style.scss b/blocks/api/components/editable/style.scss similarity index 100% rename from blocks/components/editable/style.scss rename to blocks/api/components/editable/style.scss diff --git a/blocks/api/index.js b/blocks/api/index.js new file mode 100644 index 00000000000000..42a732768df987 --- /dev/null +++ b/blocks/api/index.js @@ -0,0 +1,18 @@ +/** + * External dependencies + */ +import * as query from 'hpq'; + +export { query }; +export { default as Editable } from './components/editable'; +export { default as parse } from './parser'; +export { default as serialize } from './serializer'; +export { getCategories } from './categories'; +export { + registerBlock, + unregisterBlock, + setUnknownTypeHandler, + getUnknownTypeHandler, + getBlockSettings, + getBlocks +} from './registration'; diff --git a/blocks/parser.js b/blocks/api/parser.js similarity index 100% rename from blocks/parser.js rename to blocks/api/parser.js diff --git a/blocks/post.pegjs b/blocks/api/post.pegjs similarity index 100% rename from blocks/post.pegjs rename to blocks/api/post.pegjs diff --git a/blocks/registration.js b/blocks/api/registration.js similarity index 100% rename from blocks/registration.js rename to blocks/api/registration.js diff --git a/blocks/serializer.js b/blocks/api/serializer.js similarity index 100% rename from blocks/serializer.js rename to blocks/api/serializer.js diff --git a/blocks/test/parser.js b/blocks/api/test/parser.js similarity index 100% rename from blocks/test/parser.js rename to blocks/api/test/parser.js diff --git a/blocks/test/registration.js b/blocks/api/test/registration.js similarity index 100% rename from blocks/test/registration.js rename to blocks/api/test/registration.js diff --git a/blocks/test/serializer.js b/blocks/api/test/serializer.js similarity index 100% rename from blocks/test/serializer.js rename to blocks/api/test/serializer.js diff --git a/blocks/index.js b/blocks/index.js index 42a732768df987..b1c13e734067ac 100644 --- a/blocks/index.js +++ b/blocks/index.js @@ -1,18 +1 @@ -/** - * External dependencies - */ -import * as query from 'hpq'; - -export { query }; -export { default as Editable } from './components/editable'; -export { default as parse } from './parser'; -export { default as serialize } from './serializer'; -export { getCategories } from './categories'; -export { - registerBlock, - unregisterBlock, - setUnknownTypeHandler, - getUnknownTypeHandler, - getBlockSettings, - getBlocks -} from './registration'; +export * from './api'; From 4fc3c41fd337dc31c578cf1b5d78fe182ecc7659 Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Mon, 10 Apr 2017 19:55:15 -0400 Subject: [PATCH 2/5] Move editor blocks to top level blocks directory --- blocks/index.js | 5 +++++ .../library}/freeform/index.js | 11 +++++++--- .../blocks => blocks/library}/image/index.js | 10 ++++++--- {editor/blocks => blocks/library}/index.js | 0 .../blocks => blocks/library}/list/index.js | 15 +++++-------- .../blocks => blocks/library}/list/style.scss | 0 .../blocks => blocks/library}/text/index.js | 10 ++++++--- editor/index.js | 1 - languages/gutenberg.pot | 22 +++++++++---------- 9 files changed, 44 insertions(+), 30 deletions(-) rename {editor/blocks => blocks/library}/freeform/index.js (61%) rename {editor/blocks => blocks/library}/image/index.js (85%) rename {editor/blocks => blocks/library}/index.js (100%) rename {editor/blocks => blocks/library}/list/index.js (90%) rename {editor/blocks => blocks/library}/list/style.scss (100%) rename {editor/blocks => blocks/library}/text/index.js (89%) diff --git a/blocks/index.js b/blocks/index.js index b1c13e734067ac..3bd02278deae06 100644 --- a/blocks/index.js +++ b/blocks/index.js @@ -1 +1,6 @@ +/** + * Internal dependencies + */ +import './library'; + export * from './api'; diff --git a/editor/blocks/freeform/index.js b/blocks/library/freeform/index.js similarity index 61% rename from editor/blocks/freeform/index.js rename to blocks/library/freeform/index.js index 0de794755a0763..6869417377fe15 100644 --- a/editor/blocks/freeform/index.js +++ b/blocks/library/freeform/index.js @@ -1,6 +1,11 @@ -const { html } = wp.blocks.query; +/** + * Internal dependencies + */ +import { registerBlock, query, setUnknownTypeHandler } from 'api'; -wp.blocks.registerBlock( 'core/freeform', { +const { html } = query; + +registerBlock( 'core/freeform', { title: wp.i18n.__( 'Freeform' ), icon: 'text', @@ -27,4 +32,4 @@ wp.blocks.registerBlock( 'core/freeform', { } } ); -wp.blocks.setUnknownTypeHandler( 'core/freeform' ); +setUnknownTypeHandler( 'core/freeform' ); diff --git a/editor/blocks/image/index.js b/blocks/library/image/index.js similarity index 85% rename from editor/blocks/image/index.js rename to blocks/library/image/index.js index 5b2f50f4afebf6..72096242e9a4de 100644 --- a/editor/blocks/image/index.js +++ b/blocks/library/image/index.js @@ -1,7 +1,11 @@ -const { attr, html } = wp.blocks.query; -const Editable = wp.blocks.Editable; +/** + * Internal dependencies + */ +import { registerBlock, query, Editable } from 'api'; -wp.blocks.registerBlock( 'core/image', { +const { attr, html } = query; + +registerBlock( 'core/image', { title: wp.i18n.__( 'Image' ), icon: 'format-image', diff --git a/editor/blocks/index.js b/blocks/library/index.js similarity index 100% rename from editor/blocks/index.js rename to blocks/library/index.js diff --git a/editor/blocks/list/index.js b/blocks/library/list/index.js similarity index 90% rename from editor/blocks/list/index.js rename to blocks/library/list/index.js index 668de776b6fceb..37d9ac0216a4ab 100644 --- a/editor/blocks/list/index.js +++ b/blocks/library/list/index.js @@ -2,23 +2,20 @@ * Internal dependencies */ import './style.scss'; +import { registerBlock, query, Editable } from 'api'; -const Editable = wp.blocks.Editable; -const { html, prop } = wp.blocks.query; +const { html, prop } = query; -wp.blocks.registerBlock( 'core/list', { +registerBlock( 'core/list', { title: wp.i18n.__( 'List' ), icon: 'editor-ul', category: 'common', attributes: { listType: prop( 'ol,ul', 'nodeName' ), - items: wp.blocks.query.query( - 'li', - { - value: html() - } - ) + items: query.query( 'li', { + value: html() + } ) }, controls: [ diff --git a/editor/blocks/list/style.scss b/blocks/library/list/style.scss similarity index 100% rename from editor/blocks/list/style.scss rename to blocks/library/list/style.scss diff --git a/editor/blocks/text/index.js b/blocks/library/text/index.js similarity index 89% rename from editor/blocks/text/index.js rename to blocks/library/text/index.js index 9c1aa1c17d92be..34cc25154f58c0 100644 --- a/editor/blocks/text/index.js +++ b/blocks/library/text/index.js @@ -1,7 +1,11 @@ -const { html, prop } = wp.blocks.query; -const Editable = wp.blocks.Editable; +/** + * Internal dependencies + */ +import { registerBlock, query, Editable } from 'api'; -wp.blocks.registerBlock( 'core/text', { +const { html, prop } = query; + +registerBlock( 'core/text', { title: wp.i18n.__( 'Text' ), icon: 'text', diff --git a/editor/index.js b/editor/index.js index f3f748c43f6779..5c9b8ab0d4c4b8 100644 --- a/editor/index.js +++ b/editor/index.js @@ -7,7 +7,6 @@ import { Provider } from 'react-redux'; * Internal dependencies */ import './assets/stylesheets/main.scss'; -import './blocks'; import Layout from './layout'; import { createReduxStore } from './state'; diff --git a/languages/gutenberg.pot b/languages/gutenberg.pot index 9450af1d7e7c10..d2878f2000d756 100644 --- a/languages/gutenberg.pot +++ b/languages/gutenberg.pot @@ -3,38 +3,38 @@ msgstr "" "Content-Type: text/plain; charset=utf-8\n" "X-Generator: babel-plugin-wp-i18n\n" -#: editor/blocks/freeform/index.js:4 +#: blocks/library/freeform/index.js:9 msgid "Freeform" msgstr "" -#: editor/blocks/image/index.js:26 +#: blocks/library/image/index.js:30 msgid "Write caption…" msgstr "" -#: editor/blocks/image/index.js:5 +#: blocks/library/image/index.js:9 msgid "Image" msgstr "" -#: editor/blocks/list/index.js:10 +#: blocks/library/list/index.js:10 msgid "List" msgstr "" -#: editor/blocks/list/index.js:27 -#: editor/blocks/text/index.js:19 +#: blocks/library/list/index.js:24 +#: blocks/library/text/index.js:23 msgid "Align left" msgstr "" -#: editor/blocks/list/index.js:35 -#: editor/blocks/text/index.js:27 +#: blocks/library/list/index.js:32 +#: blocks/library/text/index.js:31 msgid "Align center" msgstr "" -#: editor/blocks/list/index.js:43 -#: editor/blocks/text/index.js:35 +#: blocks/library/list/index.js:40 +#: blocks/library/text/index.js:39 msgid "Align right" msgstr "" -#: editor/blocks/list/index.js:51 +#: blocks/library/list/index.js:48 msgid "Justify" msgstr "" From 2e198ab22d1f7cae4c0c2d967b3779a02ea0304d Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Mon, 10 Apr 2017 19:57:34 -0400 Subject: [PATCH 3/5] Move Editable to blocks components directory --- blocks/api/index.js | 1 - blocks/{api => }/components/editable/index.js | 0 .../{api => }/components/editable/style.scss | 0 blocks/components/index.js | 1 + blocks/index.js | 1 + blocks/library/image/index.js | 3 ++- blocks/library/index.js | 1 - blocks/library/list/index.js | 3 ++- blocks/library/text/index.js | 3 ++- languages/gutenberg.pot | 24 +++++++++---------- 10 files changed, 20 insertions(+), 17 deletions(-) rename blocks/{api => }/components/editable/index.js (100%) rename blocks/{api => }/components/editable/style.scss (100%) create mode 100644 blocks/components/index.js diff --git a/blocks/api/index.js b/blocks/api/index.js index 42a732768df987..3abf5b70d8385a 100644 --- a/blocks/api/index.js +++ b/blocks/api/index.js @@ -4,7 +4,6 @@ import * as query from 'hpq'; export { query }; -export { default as Editable } from './components/editable'; export { default as parse } from './parser'; export { default as serialize } from './serializer'; export { getCategories } from './categories'; diff --git a/blocks/api/components/editable/index.js b/blocks/components/editable/index.js similarity index 100% rename from blocks/api/components/editable/index.js rename to blocks/components/editable/index.js diff --git a/blocks/api/components/editable/style.scss b/blocks/components/editable/style.scss similarity index 100% rename from blocks/api/components/editable/style.scss rename to blocks/components/editable/style.scss diff --git a/blocks/components/index.js b/blocks/components/index.js new file mode 100644 index 00000000000000..c705635de2b5f8 --- /dev/null +++ b/blocks/components/index.js @@ -0,0 +1 @@ +export { default as Editable } from './editable'; diff --git a/blocks/index.js b/blocks/index.js index 3bd02278deae06..c72da46d5c8282 100644 --- a/blocks/index.js +++ b/blocks/index.js @@ -4,3 +4,4 @@ import './library'; export * from './api'; +export * from './components'; diff --git a/blocks/library/image/index.js b/blocks/library/image/index.js index 72096242e9a4de..1705bbcdd0d8cf 100644 --- a/blocks/library/image/index.js +++ b/blocks/library/image/index.js @@ -1,7 +1,8 @@ /** * Internal dependencies */ -import { registerBlock, query, Editable } from 'api'; +import { registerBlock, query } from 'api'; +import Editable from 'components/editable'; const { attr, html } = query; diff --git a/blocks/library/index.js b/blocks/library/index.js index 13820f4777e21f..3402384178f1ec 100644 --- a/blocks/library/index.js +++ b/blocks/library/index.js @@ -2,4 +2,3 @@ import './freeform'; import './image'; import './text'; import './list'; - diff --git a/blocks/library/list/index.js b/blocks/library/list/index.js index 37d9ac0216a4ab..8caae01983dddc 100644 --- a/blocks/library/list/index.js +++ b/blocks/library/list/index.js @@ -2,7 +2,8 @@ * Internal dependencies */ import './style.scss'; -import { registerBlock, query, Editable } from 'api'; +import { registerBlock, query } from 'api'; +import Editable from 'components/editable'; const { html, prop } = query; diff --git a/blocks/library/text/index.js b/blocks/library/text/index.js index 34cc25154f58c0..3d3033d2181933 100644 --- a/blocks/library/text/index.js +++ b/blocks/library/text/index.js @@ -1,7 +1,8 @@ /** * Internal dependencies */ -import { registerBlock, query, Editable } from 'api'; +import { registerBlock, query } from 'api'; +import Editable from 'components/editable'; const { html, prop } = query; diff --git a/languages/gutenberg.pot b/languages/gutenberg.pot index d2878f2000d756..133b80831202d0 100644 --- a/languages/gutenberg.pot +++ b/languages/gutenberg.pot @@ -7,34 +7,34 @@ msgstr "" msgid "Freeform" msgstr "" -#: blocks/library/image/index.js:30 -msgid "Write caption…" +#: blocks/library/image/index.js:10 +msgid "Image" msgstr "" -#: blocks/library/image/index.js:9 -msgid "Image" +#: blocks/library/image/index.js:31 +msgid "Write caption…" msgstr "" -#: blocks/library/list/index.js:10 +#: blocks/library/list/index.js:11 msgid "List" msgstr "" -#: blocks/library/list/index.js:24 -#: blocks/library/text/index.js:23 +#: blocks/library/list/index.js:25 +#: blocks/library/text/index.js:24 msgid "Align left" msgstr "" -#: blocks/library/list/index.js:32 -#: blocks/library/text/index.js:31 +#: blocks/library/list/index.js:33 +#: blocks/library/text/index.js:32 msgid "Align center" msgstr "" -#: blocks/library/list/index.js:40 -#: blocks/library/text/index.js:39 +#: blocks/library/list/index.js:41 +#: blocks/library/text/index.js:40 msgid "Align right" msgstr "" -#: blocks/library/list/index.js:48 +#: blocks/library/list/index.js:49 msgid "Justify" msgstr "" From 8d938432b9f765aaf1ec21e2efae90654d06a059 Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Tue, 11 Apr 2017 10:00:11 -0400 Subject: [PATCH 4/5] Move Blocks README back to top-level directory --- blocks/{api => }/README.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename blocks/{api => }/README.md (100%) diff --git a/blocks/api/README.md b/blocks/README.md similarity index 100% rename from blocks/api/README.md rename to blocks/README.md From a71bea2cb3089a81dbe9ee1cb9540534e4306018 Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Tue, 11 Apr 2017 10:56:05 -0400 Subject: [PATCH 5/5] Avoid runtime transform in test environment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Incompatibillity with “export * from” and runtime transform https://github.com/babel/babel/issues/2877#issuecomment-270700000 A bit uncertain why this would have no impact on non-test environments (would it?) --- .babelrc | 6 +++++- package.json | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.babelrc b/.babelrc index f9678fa8203e2b..13dcd2edfb7efd 100644 --- a/.babelrc +++ b/.babelrc @@ -8,7 +8,6 @@ ], "plugins": [ "lodash", - "transform-runtime", "transform-object-rest-spread", [ "transform-react-jsx", { "pragma": "wp.element.createElement" @@ -18,6 +17,11 @@ } ] ], "env": { + "default": { + "plugins": [ + "transform-runtime" + ] + }, "test": { "presets": [ "latest" ] } diff --git a/package.json b/package.json index 79c0eb1f524e18..11eff61fdee9c0 100644 --- a/package.json +++ b/package.json @@ -12,9 +12,9 @@ ], "scripts": { "test-unit": "cross-env NODE_ENV=test webpack && mocha build --require bootstrap-test.js", - "build": "cross-env NODE_ENV=production webpack", + "build": "cross-env BABEL_ENV=default NODE_ENV=production webpack", "lint": "eslint .", - "dev": "webpack --watch", + "dev": "cross-env BABEL_ENV=default webpack --watch", "test": "npm run lint && npm run test-unit" }, "devDependencies": {