Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 0 additions & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ module.exports = {
env: {
'jest/globals': true,
},
globals: {
wpApiSettings: true,
Copy link
Member

Choose a reason for hiding this comment

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

Aside: I was excited for a moment that we'd removed our last global. Then I saw we still have wp in eslint/config.js. Looking at remaining usage, I'm inclined to think we should just update those remaining few to at least point to window.wp so we can remove / discourage any other use of the global.

Copy link
Contributor Author

@youknowriad youknowriad Aug 20, 2018

Choose a reason for hiding this comment

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

Actually, it looks like there's no direct wp global usage anymore.

Edit: There is but it's not being caught by eslint when I removed the config

Copy link
Member

Choose a reason for hiding this comment

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

I still see some wp.oldEditor and wp.codeEditor?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, not sure why eslint is not catching them when I remove the global from eslint/config.js

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Notice that I removed the global from the config and the test is still passing. Any idea why?

Copy link
Member

Choose a reason for hiding this comment

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

I think it's eslint-config-wordpress:

https://github.com/WordPress-Coding-Standards/eslint-config-wordpress/blob/73a8d0a67ef714159b2df2aa16ce4d9180162761/index.js#L13

The false value is a bit misleading. It means that the variable is considered a global, but it's not allowed to be replaced:

https://eslint.org/docs/user-guide/configuring#specifying-globals

Copy link
Member

Choose a reason for hiding this comment

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

The behavior of false is a bit frustrating as well because it makes it unclear how a project like ours could override the default config to disallow the global. Maybe worth discussing in tomorrow's JS chat?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We already said we'd provide a new eslint package in Gutenberg with the updated guidelines discussed in previous meetings. We can remove these globals entirely from this new package.

We can discuss removing the globals altogether (as part of our new JS coding standards for ESnext)

Copy link
Member

Choose a reason for hiding this comment

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

We already said we'd provide a new eslint package in Gutenberg with the updated guidelines discussed in previous meetings.

It's still an open question as to whether wp would be a global we want to include in the default configuration, assuming a plugin might expect to use those globals rather than import from npm packages.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's true, maybe we should keep it and just override it in Gutenberg (if possible).

},
plugins: [
'jest',
],
Expand Down
18 changes: 16 additions & 2 deletions components/code-editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,20 @@ import CodeEditor from './editor';
import Placeholder from '../../packages/components/src/placeholder';
import Spinner from '../../packages/components/src/spinner';

/**
* @var {string?} siteURL WordPRess Site URL
*/
let siteURL;

/**
* Configure the site's URL to lazy load scripts and styles.
*
* @param {string} url Site url.
*/
export function unstable__setSiteURL( url ) { // eslint-disable-line camelcase
Copy link
Member

@oandregal oandregal Aug 20, 2018

Choose a reason for hiding this comment

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

Just a thought: I wish there was an easy way to package the unstable pieces in one place, ala python's __future__ module. The more I think about that, the more convinced I am using the unstable__* prefix is the right trade-off, though.

Publishing a @wordpress/unstable package could lead to some potential conflicts due the dependance on other @wordpress packages to implement the unstable features. Publishing @wordpress/components-unstable for every package we maintain is a logistic burden (and suffers from the same problems than @wordpress/unstable approach). Package those APIs in subpaths such as components/unstable, data/unstable, etc would expose them at the root level path anyway.

Copy link
Member

Choose a reason for hiding this comment

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

Just a thought: I wish there was an easy way to package the unstable pieces in one place, ala python's __future__ module.

What would be the proposed advantage of this pattern?

Copy link
Member

@oandregal oandregal Aug 20, 2018

Choose a reason for hiding this comment

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

To centralize the unstable APIs in a way that's clearly communicated and maintained. At the moment, we are using different name patterns (unstable__SomeThing, unstableSomething, and can see how in the future someone could also add unstable_SomeThing) which doesn't scale well.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Has already happened! 😅

siteURL = url;
}

function loadScript() {
return new Promise( ( resolve, reject ) => {
const handles = [ 'wp-codemirror', 'code-editor', 'htmlhint', 'csslint', 'jshint' ];
Expand All @@ -21,7 +35,7 @@ function loadScript() {
}

const script = document.createElement( 'script' );
script.src = `${ wpApiSettings.schema.url }/wp-admin/load-scripts.php?load=${ handles.join( ',' ) }`;
script.src = `${ siteURL }/wp-admin/load-scripts.php?load=${ handles.join( ',' ) }`;
script.onload = resolve;
script.onerror = reject;

Expand All @@ -35,7 +49,7 @@ function loadStyle() {

const style = document.createElement( 'link' );
style.rel = 'stylesheet';
style.href = `${ wpApiSettings.schema.url }/wp-admin/load-styles.php?load=${ handles.join( ',' ) }`;
style.href = `${ siteURL }/wp-admin/load-styles.php?load=${ handles.join( ',' ) }`;
style.onload = resolve;
style.onerror = reject;

Expand Down
2 changes: 1 addition & 1 deletion components/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Components
export { default as CodeEditor } from './code-editor';
export { default as CodeEditor, unstable__setSiteURL } from './code-editor'; // eslint-disable-line camelcase
export * from '../packages/components/src';

import '../packages/components/src/style.scss';
62 changes: 0 additions & 62 deletions docs/data/data-core.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,54 +2,6 @@

## Selectors

### getTerms

Returns all the available terms for the given taxonomy.

*Parameters*

* state: Data state.
* taxonomy: Taxonomy name.

### getCategories

Returns all the available categories.

*Parameters*

* state: Data state.

*Returns*

Categories list.

### isRequestingTerms

Returns true if a request is in progress for terms data of a given taxonomy,
or false otherwise.

*Parameters*

* state: Data state.
* taxonomy: Taxonomy name.

*Returns*

Whether a request is in progress for taxonomy's terms.

### isRequestingCategories

Returns true if a request is in progress for categories data, or false
otherwise.

*Parameters*

* state: Data state.

*Returns*

Whether a request is in progress for categories.

### isRequestingEmbedPreview

Returns true if a request is in progress for embed preview data, or false
Expand All @@ -60,10 +12,6 @@ otherwise.
* state: Data state.
* url: URL the preview would be for.

*Returns*

Whether a request is in progress for an embed preview.

### getAuthors

Returns all available authors.
Expand Down Expand Up @@ -177,16 +125,6 @@ Is the preview for the URL an oEmbed link fallback.

## Actions

### receiveTerms

Returns an action object used in signalling that terms have been received
for a given taxonomy.

*Parameters*

* taxonomy: Taxonomy name.
* terms: Terms received.

### receiveUserQuery

Returns an action object used in signalling that authors have been received.
Expand Down
6 changes: 4 additions & 2 deletions docs/reference/deprecated.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ Gutenberg's deprecation policy is intended to support backwards-compatibility fo

- `wp.components.withAPIData` has been removed. Please use the Core Data module or `wp.apiFetch` directly instead.
- `wp.data.dispatch("core").receiveTerms` has been deprecated. Please use `wp.data.dispatch("core").receiveEntityRecords` instead.
- `getCategories` resolvers has been deprecated. Please use `getEntityRecords` resolver instead.
- `getCategories` resolver has been deprecated. Please use `getEntityRecords` resolver instead.
- `wp.data.select("core").getTerms` has been deprecated. Please use `wp.data.select("core").getEntityRecords` instead.
- `wp.data.select("core").getCategories` has been deprecated. Please use `wp.data.select("core").getEntityRecords` instead.
- `wp.data.select("core").isRequestingTerms` has been deprecated. Please use `wp.data.select("core").getEntitiesByKind` instead.
- `wp.data.select("core").isRequestingCategories` has been deprecated. Please use `wp.data.select("core/data").isResolving` instead.
- `wp.data.select("core").isRequestingTerms` has been deprecated. Please use `wp.data.select("core").isResolving` instead.
- `wp.data.restrictPersistence`, `wp.data.setPersistenceStorage` and `wp.data.setupPersistence` has been removed. Please use the data persistence plugin instead.

## 3.6.0

Expand Down
1 change: 0 additions & 1 deletion eslint/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ module.exports = {
},
},
globals: {
wp: true,
window: true,
document: true,
},
Expand Down
62 changes: 6 additions & 56 deletions lib/client-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,6 @@ function gutenberg_register_scripts_and_styles() {
'wp-data',
gutenberg_url( 'build/data/index.js' ),
array(
'wp-deprecated',
'wp-element',
'wp-compose',
'wp-is-shallow-equal',
Expand All @@ -252,15 +251,9 @@ function gutenberg_register_scripts_and_styles() {
implode(
"\n",
array(
// TODO: Transferring old storage should be removed at v3.7.
'( function() {',
' var userId = window.userSettings.uid;',
' var oldStorageKey = "WP_EDIT_POST_DATA_" + userId;',
' var storageKey = "WP_DATA_USER_" + userId;',
' if ( localStorage[ oldStorageKey ] ) {',
' localStorage[ storageKey ] = localStorage[ oldStorageKey ];',
' delete localStorage[ oldStorageKey ];',
' }',
' wp.data',
' .use( wp.data.plugins.persistence, { storageKey: storageKey } )',
' .use( wp.data.plugins.controls );',
Expand Down Expand Up @@ -368,7 +361,6 @@ function gutenberg_register_scripts_and_styles() {
'lodash',
'moment',
'wp-a11y',
'wp-api',
'wp-api-fetch',
'wp-compose',
'wp-deprecated',
Expand All @@ -384,6 +376,10 @@ function gutenberg_register_scripts_and_styles() {
filemtime( gutenberg_dir_path() . 'build/components/index.js' ),
true
);
wp_add_inline_script(
'wp-components',
sprintf( 'wp.components.unstable__setSiteURL(%s);', json_encode( site_url() ) )
);
wp_register_script(
'wp-blocks',
gutenberg_url( 'build/blocks/index.js' ),
Expand Down Expand Up @@ -612,7 +608,6 @@ function gutenberg_register_scripts_and_styles() {
'media-models',
'media-views',
'wp-a11y',
'wp-api',
'wp-api-fetch',
'wp-components',
'wp-compose',
Expand Down Expand Up @@ -965,47 +960,6 @@ function gutenberg_register_vendor_script( $handle, $src, $deps = array() ) {
);
}

/**
* Provide the components script with the required config to make withAPIData work.
*/
function gutenberg_prepare_wp_components_script() {
$schema_response = rest_do_request( new WP_REST_Request( 'GET', '/' ) );
if ( ! $schema_response->is_error() ) {
wp_add_inline_script(
'wp-components',
sprintf(
'wpApiSettings.cacheSchema = true; wpApiSettings.schema = %s;',
wp_json_encode( $schema_response->get_data() )
),
'before'
);
}

// Post Types Mapping.
$post_type_rest_base_mapping = array();
foreach ( get_post_types( array(), 'objects' ) as $post_type_object ) {
$rest_base = ! empty( $post_type_object->rest_base ) ? $post_type_object->rest_base : $post_type_object->name;
$post_type_rest_base_mapping[ $post_type_object->name ] = $rest_base;
}

// Taxonomies Mapping.
$taxonomy_rest_base_mapping = array();
foreach ( get_taxonomies( array(), 'objects' ) as $taxonomy_object ) {
$rest_base = ! empty( $taxonomy_object->rest_base ) ? $taxonomy_object->rest_base : $taxonomy_object->name;
$taxonomy_rest_base_mapping[ $taxonomy_object->name ] = $rest_base;
}

wp_add_inline_script(
'wp-components',
sprintf(
'wp.components.unstable__setApiSettings( wpApiSettings.schema, %s, %s )',
wp_json_encode( $post_type_rest_base_mapping ),
wp_json_encode( $taxonomy_rest_base_mapping )
),
'after'
);
}

/**
* Prepares server-registered blocks for JavaScript, returning an associative
* array of registered block data keyed by block name. Data includes properties
Expand Down Expand Up @@ -1218,8 +1172,6 @@ function get_block_categories( $post ) {
function gutenberg_editor_scripts_and_styles( $hook ) {
$is_demo = isset( $_GET['gutenberg-demo'] );

gutenberg_prepare_wp_components_script();

global $wp_scripts;

// Add "wp-hooks" as dependency of "heartbeat".
Expand Down Expand Up @@ -1446,10 +1398,8 @@ function gutenberg_editor_scripts_and_styles( $hook ) {
( function() {
var editorSettings = %s;
window._wpLoadGutenbergEditor = new Promise( function( resolve ) {
wp.api.init().then( function() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pretty happy about this one :)

Copy link
Member

Choose a reason for hiding this comment

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

Next to eliminate domReady and the promise altogether 😉

wp.domReady( function() {
resolve( wp.editPost.initializeEditor( 'editor', "%s", %d, editorSettings, window._wpGutenbergDefaultPost ) );
} );
wp.domReady( function() {
resolve( wp.editPost.initializeEditor( 'editor', "%s", %d, editorSettings, window._wpGutenbergDefaultPost ) );
} );
} );
} )();
Expand Down
21 changes: 6 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions packages/a11y/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
## 1.1.0 (2018-07-12)

### New feature

- Updated build to work with Babel 7 ([#7832](https://github.com/WordPress/gutenberg/pull/7832))

### Polish

- Moved `@WordPress/packages` repository to `@WordPress/gutenberg` ([#7805](https://github.com/WordPress/gutenberg/pull/7805))
7 changes: 7 additions & 0 deletions packages/autop/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
## 1.1.0 (2018-07-12)

### New Feature

- Updated build to work with Babel 7 ([#7832](https://github.com/WordPress/gutenberg/pull/7832))

### Internal

- Moved `@WordPress/packages` repository to `@WordPress/gutenberg` ([#7805](https://github.com/WordPress/gutenberg/pull/7805))

## 1.0.6 (2018-05-08)

### Polish

- Documentation: Fix API method typo for `removep`. ([#120](https://github.com/WordPress/packages/pull/120))
9 changes: 8 additions & 1 deletion packages/babel-plugin-makepot/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
## 2.0.0 (2018-07-12)

- Breaking: Updated code to work with Babel 7 ([#7832](https://github.com/WordPress/gutenberg/pull/7832))
### Breaking Change

- Updated code to work with Babel 7 ([#7832](https://github.com/WordPress/gutenberg/pull/7832))

### Internal

- Moved `@WordPress/packages` repository to `@WordPress/gutenberg` ([#7805](https://github.com/WordPress/gutenberg/pull/7805))

## 1.0.1 (2018-05-18)

### Polish

- Fix: Standardized `package.json` format ([#119](https://github.com/WordPress/packages/pull/119))
Loading