From 7fbf73d447b211c31d75585c46fb3f08e6267582 Mon Sep 17 00:00:00 2001 From: Adam Zielinski Date: Sat, 11 Feb 2023 14:14:20 +0100 Subject: [PATCH] Rename the "experiments" export to "privateApis" (#47975) * Rename the "experiments" export to "privateApis" * Fix a typo * minor missing renames --------- Co-authored-by: ntsekouras --- docs/contributors/code/coding-guidelines.md | 7 +- packages/block-editor/README.md | 8 +- .../src/components/url-popover/index.js | 4 +- packages/block-editor/src/hooks/position.js | 4 +- packages/block-editor/src/index.js | 2 +- packages/block-editor/src/private-apis.js | 6 +- .../block-editor/src/private-apis.native.js | 6 +- .../edit/menu-inspector-controls.js | 4 +- packages/components/src/index.js | 4 +- packages/components/src/private-apis.js | 4 +- .../sidebar-editor-provider.js | 4 +- packages/edit-post/src/editor.js | 4 +- .../src/components/block-editor/index.js | 4 +- .../global-styles-renderer/index.js | 4 +- .../components/global-styles/border-panel.js | 4 +- .../global-styles/color-palette-panel.js | 4 +- .../components/global-styles/context-menu.js | 4 +- .../components/global-styles/custom-css.js | 4 +- .../global-styles/dimensions-panel.js | 4 +- .../global-styles/global-styles-provider.js | 4 +- .../global-styles/gradients-palette-panel.js | 4 +- .../src/components/global-styles/hooks.js | 4 +- .../src/components/global-styles/palette.js | 4 +- .../src/components/global-styles/preview.js | 4 +- .../global-styles/screen-background-color.js | 4 +- .../global-styles/screen-block-list.js | 4 +- .../global-styles/screen-button-color.js | 4 +- .../components/global-styles/screen-colors.js | 4 +- .../global-styles/screen-heading-color.js | 4 +- .../global-styles/screen-link-color.js | 4 +- .../components/global-styles/screen-root.js | 4 +- .../global-styles/screen-style-variations.js | 4 +- .../global-styles/screen-text-color.js | 4 +- .../global-styles/screen-typography.js | 4 +- .../components/global-styles/shadow-panel.js | 4 +- .../global-styles/typography-panel.js | 4 +- .../global-styles/typography-preview.js | 4 +- .../src/components/global-styles/ui.js | 4 +- .../navigation-inspector/navigation-menu.js | 4 +- .../src/components/style-book/index.js | 4 +- .../push-changes-to-global-styles/index.js | 4 +- .../index.js | 4 +- .../editor/src/components/provider/index.js | 4 +- packages/editor/src/private-apis.js | 4 +- packages/private-apis/README.md | 8 +- packages/private-apis/src/implementation.js | 52 +++---- packages/private-apis/src/test/index.js | 137 +++++++++--------- 47 files changed, 189 insertions(+), 193 deletions(-) diff --git a/docs/contributors/code/coding-guidelines.md b/docs/contributors/code/coding-guidelines.md index 281ace04b141cd..d9d62450c94bf9 100644 --- a/docs/contributors/code/coding-guidelines.md +++ b/docs/contributors/code/coding-guidelines.md @@ -293,7 +293,6 @@ You can attach private selectors and actions to a public store: ```js // In packages/package1/store.js: -import { experiments as dataExperiments } from '@wordpress/data'; import { __experimentalHasContentRoleAttribute, ...selectors } from './selectors'; import { __experimentalToggleFeature, ...actions } from './selectors'; // The `lock` function is exported from the internal experiments.js file where @@ -340,9 +339,9 @@ function MyComponent() { // In packages/package1/index.js: import { lock } from './private-apis'; -export const experiments = {}; +export const privateApis = {}; /* Attach private data to the exported object */ -lock( experiments, { +lock( privateApis, { __experimentalCallback: function () {}, __experimentalReactComponent: function ExperimentalComponent() { return
; @@ -352,7 +351,7 @@ lock( experiments, { } ); // In packages/package2/index.js: -import { experiments } from '@wordpress/package1'; +import { privateApis } from '@wordpress/package1'; import { unlock } from './private-apis'; const { diff --git a/packages/block-editor/README.md b/packages/block-editor/README.md index 19433e516f4f5d..18c2c2cfbce521 100644 --- a/packages/block-editor/README.md +++ b/packages/block-editor/README.md @@ -348,10 +348,6 @@ _Returns_ Undocumented declaration. -### experiments - -Experimental @wordpress/block-editor APIs. - ### FontSizePicker _Related_ @@ -639,6 +635,10 @@ _Related_ - +### privateApis + +Private @wordpress/block-editor APIs. + ### RichText _Related_ diff --git a/packages/block-editor/src/components/url-popover/index.js b/packages/block-editor/src/components/url-popover/index.js index 8c2bbec69c5de6..071d2c7e00b8bd 100644 --- a/packages/block-editor/src/components/url-popover/index.js +++ b/packages/block-editor/src/components/url-popover/index.js @@ -6,7 +6,7 @@ import { useState } from '@wordpress/element'; import { Button, Popover, - experiments as componentsExperiments, + privateApis as componentsPrivateApis, } from '@wordpress/components'; import { chevronDown } from '@wordpress/icons'; import deprecated from '@wordpress/deprecated'; @@ -19,7 +19,7 @@ import LinkEditor from './link-editor'; import { unlock } from '../../lock-unlock'; const { __experimentalPopoverLegacyPositionToPlacement } = unlock( - componentsExperiments + componentsPrivateApis ); const DEFAULT_PLACEMENT = 'bottom'; diff --git a/packages/block-editor/src/hooks/position.js b/packages/block-editor/src/hooks/position.js index c5176304fb958d..2c5589c1920bbd 100644 --- a/packages/block-editor/src/hooks/position.js +++ b/packages/block-editor/src/hooks/position.js @@ -10,7 +10,7 @@ import { __, sprintf } from '@wordpress/i18n'; import { getBlockSupport, hasBlockSupport } from '@wordpress/blocks'; import { BaseControl, - experiments as componentsExperiments, + privateApis as componentsPrivateApis, } from '@wordpress/components'; import { createHigherOrderComponent, useInstanceId } from '@wordpress/compose'; import { useSelect } from '@wordpress/data'; @@ -32,7 +32,7 @@ import { cleanEmptyObject } from './utils'; import { unlock } from '../lock-unlock'; import { store as blockEditorStore } from '../store'; -const { CustomSelectControl } = unlock( componentsExperiments ); +const { CustomSelectControl } = unlock( componentsPrivateApis ); const POSITION_SUPPORT_KEY = 'position'; diff --git a/packages/block-editor/src/index.js b/packages/block-editor/src/index.js index 82ef4f30e53958..e272043c7ebab5 100644 --- a/packages/block-editor/src/index.js +++ b/packages/block-editor/src/index.js @@ -20,4 +20,4 @@ export * from './elements'; export * from './utils'; export { storeConfig, store } from './store'; export { SETTINGS_DEFAULTS } from './store/defaults'; -export { experiments } from './private-apis'; +export { privateApis } from './private-apis'; diff --git a/packages/block-editor/src/private-apis.js b/packages/block-editor/src/private-apis.js index a624480bbcce1a..b5b6c5d934cd4f 100644 --- a/packages/block-editor/src/private-apis.js +++ b/packages/block-editor/src/private-apis.js @@ -8,10 +8,10 @@ import OffCanvasEditor from './components/off-canvas-editor'; import LeafMoreMenu from './components/off-canvas-editor/leaf-more-menu'; /** - * Experimental @wordpress/block-editor APIs. + * Private @wordpress/block-editor APIs. */ -export const experiments = {}; -lock( experiments, { +export const privateApis = {}; +lock( privateApis, { ...globalStyles, ExperimentalBlockEditorProvider, LeafMoreMenu, diff --git a/packages/block-editor/src/private-apis.native.js b/packages/block-editor/src/private-apis.native.js index 39400dbe105932..5555e00477e7b5 100644 --- a/packages/block-editor/src/private-apis.native.js +++ b/packages/block-editor/src/private-apis.native.js @@ -6,10 +6,10 @@ import { ExperimentalBlockEditorProvider } from './components/provider'; import { lock } from './lock-unlock'; /** - * Experimental @wordpress/block-editor APIs. + * Private @wordpress/block-editor APIs. */ -export const experiments = {}; -lock( experiments, { +export const privateApis = {}; +lock( privateApis, { ...globalStyles, ExperimentalBlockEditorProvider, } ); diff --git a/packages/block-library/src/navigation/edit/menu-inspector-controls.js b/packages/block-library/src/navigation/edit/menu-inspector-controls.js index 26bf21168ee889..9b6c1456a37261 100644 --- a/packages/block-library/src/navigation/edit/menu-inspector-controls.js +++ b/packages/block-library/src/navigation/edit/menu-inspector-controls.js @@ -2,7 +2,7 @@ * WordPress dependencies */ import { - experiments as blockEditorExperiments, + privateApis as blockEditorPrivateApis, InspectorControls, store as blockEditorStore, } from '@wordpress/block-editor'; @@ -33,7 +33,7 @@ const MainContent = ( { isNavigationMenuMissing, onCreateNew, } ) => { - const { OffCanvasEditor, LeafMoreMenu } = unlock( blockEditorExperiments ); + const { OffCanvasEditor, LeafMoreMenu } = unlock( blockEditorPrivateApis ); // Provide a hierarchy of clientIds for the given Navigation block (clientId). // This is required else the list view will display the entire block tree. const clientIdsTree = useSelect( diff --git a/packages/components/src/index.js b/packages/components/src/index.js index 203469ccb1be36..a97682c3e49761 100644 --- a/packages/components/src/index.js +++ b/packages/components/src/index.js @@ -212,5 +212,5 @@ export { export { default as withNotices } from './higher-order/with-notices'; export { default as withSpokenMessages } from './higher-order/with-spoken-messages'; -// Experiments. -export { experiments } from './private-apis'; +// Private APIs. +export { privateApis } from './private-apis'; diff --git a/packages/components/src/private-apis.js b/packages/components/src/private-apis.js index 8798ea10785158..07efc6f6a039b5 100644 --- a/packages/components/src/private-apis.js +++ b/packages/components/src/private-apis.js @@ -15,8 +15,8 @@ export const { lock, unlock } = '@wordpress/components' ); -export const experiments = {}; -lock( experiments, { +export const privateApis = {}; +lock( privateApis, { CustomSelectControl, __experimentalPopoverLegacyPositionToPlacement, } ); diff --git a/packages/customize-widgets/src/components/sidebar-block-editor/sidebar-editor-provider.js b/packages/customize-widgets/src/components/sidebar-block-editor/sidebar-editor-provider.js index da9a278a42b862..25b541c3d16dbe 100644 --- a/packages/customize-widgets/src/components/sidebar-block-editor/sidebar-editor-provider.js +++ b/packages/customize-widgets/src/components/sidebar-block-editor/sidebar-editor-provider.js @@ -1,7 +1,7 @@ /** * WordPress dependencies */ -import { experiments as blockEditorExperiments } from '@wordpress/block-editor'; +import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor'; /** * Internal dependencies @@ -11,7 +11,7 @@ import useBlocksFocusControl from '../focus-control/use-blocks-focus-control'; import { unlock } from '../../private-apis'; -const { ExperimentalBlockEditorProvider } = unlock( blockEditorExperiments ); +const { ExperimentalBlockEditorProvider } = unlock( blockEditorPrivateApis ); export default function SidebarEditorProvider( { sidebar, diff --git a/packages/edit-post/src/editor.js b/packages/edit-post/src/editor.js index ec5b8a531cf60e..79bd55317f91f3 100644 --- a/packages/edit-post/src/editor.js +++ b/packages/edit-post/src/editor.js @@ -7,7 +7,7 @@ import { ErrorBoundary, PostLockedModal, store as editorStore, - experiments as editorExperiments, + privateApis as editorPrivateApis, } from '@wordpress/editor'; import { useMemo } from '@wordpress/element'; import { SlotFillProvider } from '@wordpress/components'; @@ -23,7 +23,7 @@ import EditorInitialization from './components/editor-initialization'; import { store as editPostStore } from './store'; import { unlock } from './private-apis'; -const { ExperimentalEditorProvider } = unlock( editorExperiments ); +const { ExperimentalEditorProvider } = unlock( editorPrivateApis ); function Editor( { postId, postType, settings, initialEdits, ...props } ) { const { diff --git a/packages/edit-site/src/components/block-editor/index.js b/packages/edit-site/src/components/block-editor/index.js index fe80f3b14ade28..ac6f762ded6c89 100644 --- a/packages/edit-site/src/components/block-editor/index.js +++ b/packages/edit-site/src/components/block-editor/index.js @@ -17,7 +17,7 @@ import { __unstableUseTypingObserver as useTypingObserver, BlockEditorKeyboardShortcuts, store as blockEditorStore, - experiments as blockEditorExperiments, + privateApis as blockEditorPrivateApis, } from '@wordpress/block-editor'; import { useMergeRefs, @@ -39,7 +39,7 @@ import EditorCanvas from './editor-canvas'; import StyleBook from '../style-book'; import { unlock } from '../../private-apis'; -const { ExperimentalBlockEditorProvider } = unlock( blockEditorExperiments ); +const { ExperimentalBlockEditorProvider } = unlock( blockEditorPrivateApis ); const LAYOUT = { type: 'default', diff --git a/packages/edit-site/src/components/global-styles-renderer/index.js b/packages/edit-site/src/components/global-styles-renderer/index.js index c9e258a0f4efba..3d0df911685cbb 100644 --- a/packages/edit-site/src/components/global-styles-renderer/index.js +++ b/packages/edit-site/src/components/global-styles-renderer/index.js @@ -3,7 +3,7 @@ */ import { useEffect } from '@wordpress/element'; import { useSelect, useDispatch } from '@wordpress/data'; -import { experiments as blockEditorExperiments } from '@wordpress/block-editor'; +import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor'; /** * Internal dependencies @@ -11,7 +11,7 @@ import { experiments as blockEditorExperiments } from '@wordpress/block-editor'; import { store as editSiteStore } from '../../store'; import { unlock } from '../../private-apis'; -const { useGlobalStylesOutput } = unlock( blockEditorExperiments ); +const { useGlobalStylesOutput } = unlock( blockEditorPrivateApis ); function useGlobalStylesRenderer() { const [ styles, settings, svgFilters ] = useGlobalStylesOutput(); diff --git a/packages/edit-site/src/components/global-styles/border-panel.js b/packages/edit-site/src/components/global-styles/border-panel.js index a59b9bfb58d103..a32ad024295957 100644 --- a/packages/edit-site/src/components/global-styles/border-panel.js +++ b/packages/edit-site/src/components/global-styles/border-panel.js @@ -3,7 +3,7 @@ */ import { __experimentalBorderRadiusControl as BorderRadiusControl, - experiments as blockEditorExperiments, + privateApis as blockEditorPrivateApis, } from '@wordpress/block-editor'; import { __experimentalBorderBoxControl as BorderBoxControl, @@ -21,7 +21,7 @@ import { __ } from '@wordpress/i18n'; import { useSupportedStyles, useColorsPerOrigin } from './hooks'; import { unlock } from '../../private-apis'; -const { useGlobalSetting, useGlobalStyle } = unlock( blockEditorExperiments ); +const { useGlobalSetting, useGlobalStyle } = unlock( blockEditorPrivateApis ); export function useHasBorderPanel( name ) { const controls = [ diff --git a/packages/edit-site/src/components/global-styles/color-palette-panel.js b/packages/edit-site/src/components/global-styles/color-palette-panel.js index efe5ccb55b2e72..7bf422b878e01a 100644 --- a/packages/edit-site/src/components/global-styles/color-palette-panel.js +++ b/packages/edit-site/src/components/global-styles/color-palette-panel.js @@ -6,14 +6,14 @@ import { __experimentalVStack as VStack, } from '@wordpress/components'; import { __ } from '@wordpress/i18n'; -import { experiments as blockEditorExperiments } from '@wordpress/block-editor'; +import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor'; /** * Internal dependencies */ import { unlock } from '../../private-apis'; -const { useGlobalSetting } = unlock( blockEditorExperiments ); +const { useGlobalSetting } = unlock( blockEditorPrivateApis ); export default function ColorPalettePanel( { name } ) { const [ themeColors, setThemeColors ] = useGlobalSetting( diff --git a/packages/edit-site/src/components/global-styles/context-menu.js b/packages/edit-site/src/components/global-styles/context-menu.js index f1128117e59c8d..04ab8e65f403f0 100644 --- a/packages/edit-site/src/components/global-styles/context-menu.js +++ b/packages/edit-site/src/components/global-styles/context-menu.js @@ -21,7 +21,7 @@ import { import { isRTL, __ } from '@wordpress/i18n'; import { useSelect } from '@wordpress/data'; import { store as coreStore } from '@wordpress/core-data'; -import { experiments as blockEditorExperiments } from '@wordpress/block-editor'; +import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor'; /** * Internal dependencies @@ -37,7 +37,7 @@ import { useHasShadowControl } from './shadow-panel'; import { unlock } from '../../private-apis'; const { useHasTypographyPanel, useGlobalSetting } = unlock( - blockEditorExperiments + blockEditorPrivateApis ); function ContextMenu( { name, parentMenu = '' } ) { diff --git a/packages/edit-site/src/components/global-styles/custom-css.js b/packages/edit-site/src/components/global-styles/custom-css.js index 71fd594e3336fe..afc721b81d5e02 100644 --- a/packages/edit-site/src/components/global-styles/custom-css.js +++ b/packages/edit-site/src/components/global-styles/custom-css.js @@ -12,7 +12,7 @@ import { } from '@wordpress/components'; import { __ } from '@wordpress/i18n'; import { - experiments as blockEditorExperiments, + privateApis as blockEditorPrivateApis, transformStyles, } from '@wordpress/block-editor'; import { info } from '@wordpress/icons'; @@ -23,7 +23,7 @@ import { info } from '@wordpress/icons'; import { unlock } from '../../private-apis'; import Subtitle from './subtitle'; -const { useGlobalStyle } = unlock( blockEditorExperiments ); +const { useGlobalStyle } = unlock( blockEditorPrivateApis ); function CustomCSSControl( { blockName } ) { // If blockName is defined, we are customizing CSS at the block level: // styles.blocks.blockName.css diff --git a/packages/edit-site/src/components/global-styles/dimensions-panel.js b/packages/edit-site/src/components/global-styles/dimensions-panel.js index e1e3b8714fefa9..c0b4bae554bd66 100644 --- a/packages/edit-site/src/components/global-styles/dimensions-panel.js +++ b/packages/edit-site/src/components/global-styles/dimensions-panel.js @@ -20,7 +20,7 @@ import { __experimentalUseCustomSides as useCustomSides, HeightControl, __experimentalSpacingSizesControl as SpacingSizesControl, - experiments as blockEditorExperiments, + privateApis as blockEditorPrivateApis, } from '@wordpress/block-editor'; import { Icon, positionCenter, stretchWide } from '@wordpress/icons'; @@ -30,7 +30,7 @@ import { Icon, positionCenter, stretchWide } from '@wordpress/icons'; import { useSupportedStyles } from './hooks'; import { unlock } from '../../private-apis'; -const { useGlobalSetting, useGlobalStyle } = unlock( blockEditorExperiments ); +const { useGlobalSetting, useGlobalStyle } = unlock( blockEditorPrivateApis ); const AXIAL_SIDES = [ 'horizontal', 'vertical' ]; diff --git a/packages/edit-site/src/components/global-styles/global-styles-provider.js b/packages/edit-site/src/components/global-styles/global-styles-provider.js index 08828e8a53a5ad..20e3d03c54d1fc 100644 --- a/packages/edit-site/src/components/global-styles/global-styles-provider.js +++ b/packages/edit-site/src/components/global-styles/global-styles-provider.js @@ -9,7 +9,7 @@ import { mergeWith, isEmpty, mapValues } from 'lodash'; import { useMemo, useCallback } from '@wordpress/element'; import { useSelect, useDispatch } from '@wordpress/data'; import { store as coreStore } from '@wordpress/core-data'; -import { experiments as blockEditorExperiments } from '@wordpress/block-editor'; +import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor'; /** * Internal dependencies @@ -17,7 +17,7 @@ import { experiments as blockEditorExperiments } from '@wordpress/block-editor'; import CanvasSpinner from '../canvas-spinner'; import { unlock } from '../../private-apis'; -const { GlobalStylesContext } = unlock( blockEditorExperiments ); +const { GlobalStylesContext } = unlock( blockEditorPrivateApis ); function mergeTreesCustomizer( _, srcValue ) { // We only pass as arrays the presets, diff --git a/packages/edit-site/src/components/global-styles/gradients-palette-panel.js b/packages/edit-site/src/components/global-styles/gradients-palette-panel.js index 0169ce56b500fd..747534993c5933 100644 --- a/packages/edit-site/src/components/global-styles/gradients-palette-panel.js +++ b/packages/edit-site/src/components/global-styles/gradients-palette-panel.js @@ -8,7 +8,7 @@ import { DuotonePicker, } from '@wordpress/components'; import { __ } from '@wordpress/i18n'; -import { experiments as blockEditorExperiments } from '@wordpress/block-editor'; +import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor'; /** * Internal dependencies @@ -16,7 +16,7 @@ import { experiments as blockEditorExperiments } from '@wordpress/block-editor'; import Subtitle from './subtitle'; import { unlock } from '../../private-apis'; -const { useGlobalSetting } = unlock( blockEditorExperiments ); +const { useGlobalSetting } = unlock( blockEditorPrivateApis ); const noop = () => {}; diff --git a/packages/edit-site/src/components/global-styles/hooks.js b/packages/edit-site/src/components/global-styles/hooks.js index 00b9fc958e8a4e..e1c5370cd630a1 100644 --- a/packages/edit-site/src/components/global-styles/hooks.js +++ b/packages/edit-site/src/components/global-styles/hooks.js @@ -10,7 +10,7 @@ import a11yPlugin from 'colord/plugins/a11y'; import { _x } from '@wordpress/i18n'; import { useMemo } from '@wordpress/element'; import { store as blocksStore } from '@wordpress/blocks'; -import { experiments as blockEditorExperiments } from '@wordpress/block-editor'; +import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor'; /** * Internal dependencies @@ -18,7 +18,7 @@ import { experiments as blockEditorExperiments } from '@wordpress/block-editor'; import { unlock } from '../../private-apis'; import { useSelect } from '@wordpress/data'; -const { useGlobalSetting } = unlock( blockEditorExperiments ); +const { useGlobalSetting } = unlock( blockEditorPrivateApis ); // Enable colord's a11y plugin. extend( [ a11yPlugin ] ); diff --git a/packages/edit-site/src/components/global-styles/palette.js b/packages/edit-site/src/components/global-styles/palette.js index 60a293682e0098..c5f71cc987f043 100644 --- a/packages/edit-site/src/components/global-styles/palette.js +++ b/packages/edit-site/src/components/global-styles/palette.js @@ -13,7 +13,7 @@ import { import { __, _n, sprintf } from '@wordpress/i18n'; import { shuffle } from '@wordpress/icons'; import { useMemo } from '@wordpress/element'; -import { experiments as blockEditorExperiments } from '@wordpress/block-editor'; +import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor'; /** * Internal dependencies @@ -24,7 +24,7 @@ import { useColorRandomizer } from './hooks'; import ColorIndicatorWrapper from './color-indicator-wrapper'; import { unlock } from '../../private-apis'; -const { useGlobalSetting } = unlock( blockEditorExperiments ); +const { useGlobalSetting } = unlock( blockEditorPrivateApis ); const EMPTY_COLORS = []; diff --git a/packages/edit-site/src/components/global-styles/preview.js b/packages/edit-site/src/components/global-styles/preview.js index 7b262a0632f2b6..ec8740c3453334 100644 --- a/packages/edit-site/src/components/global-styles/preview.js +++ b/packages/edit-site/src/components/global-styles/preview.js @@ -4,7 +4,7 @@ import { __unstableIframe as Iframe, __unstableEditorStyles as EditorStyles, - experiments as blockEditorExperiments, + privateApis as blockEditorPrivateApis, } from '@wordpress/block-editor'; import { __unstableMotion as motion, @@ -20,7 +20,7 @@ import { useState, useMemo } from '@wordpress/element'; import { unlock } from '../../private-apis'; const { useGlobalSetting, useGlobalStyle, useGlobalStylesOutput } = unlock( - blockEditorExperiments + blockEditorPrivateApis ); const firstFrame = { diff --git a/packages/edit-site/src/components/global-styles/screen-background-color.js b/packages/edit-site/src/components/global-styles/screen-background-color.js index b89d9ef41bb32f..6a072185b91e21 100644 --- a/packages/edit-site/src/components/global-styles/screen-background-color.js +++ b/packages/edit-site/src/components/global-styles/screen-background-color.js @@ -9,7 +9,7 @@ import classnames from 'classnames'; import { __ } from '@wordpress/i18n'; import { __experimentalColorGradientControl as ColorGradientControl, - experiments as blockEditorExperiments, + privateApis as blockEditorPrivateApis, } from '@wordpress/block-editor'; /** @@ -23,7 +23,7 @@ import { } from './hooks'; import { unlock } from '../../private-apis'; -const { useGlobalSetting, useGlobalStyle } = unlock( blockEditorExperiments ); +const { useGlobalSetting, useGlobalStyle } = unlock( blockEditorPrivateApis ); function ScreenBackgroundColor( { name, variation = '' } ) { const prefix = variation ? `variations.${ variation }.` : ''; diff --git a/packages/edit-site/src/components/global-styles/screen-block-list.js b/packages/edit-site/src/components/global-styles/screen-block-list.js index 9cdb3fb2a5fc6f..cba14553338982 100644 --- a/packages/edit-site/src/components/global-styles/screen-block-list.js +++ b/packages/edit-site/src/components/global-styles/screen-block-list.js @@ -12,7 +12,7 @@ import { useSelect } from '@wordpress/data'; import { useState, useMemo, useEffect, useRef } from '@wordpress/element'; import { BlockIcon, - experiments as blockEditorExperiments, + privateApis as blockEditorPrivateApis, } from '@wordpress/block-editor'; import { useDebounce } from '@wordpress/compose'; import { speak } from '@wordpress/a11y'; @@ -29,7 +29,7 @@ import { NavigationButtonAsItem } from './navigation-button'; import { unlock } from '../../private-apis'; const { useHasTypographyPanel, useGlobalSetting } = unlock( - blockEditorExperiments + blockEditorPrivateApis ); function useSortedBlockTypes() { diff --git a/packages/edit-site/src/components/global-styles/screen-button-color.js b/packages/edit-site/src/components/global-styles/screen-button-color.js index 4b4b2e796b5ebf..010095d024c622 100644 --- a/packages/edit-site/src/components/global-styles/screen-button-color.js +++ b/packages/edit-site/src/components/global-styles/screen-button-color.js @@ -4,7 +4,7 @@ import { __ } from '@wordpress/i18n'; import { __experimentalColorGradientControl as ColorGradientControl, - experiments as blockEditorExperiments, + privateApis as blockEditorPrivateApis, } from '@wordpress/block-editor'; /** @@ -14,7 +14,7 @@ import ScreenHeader from './header'; import { useSupportedStyles, useColorsPerOrigin } from './hooks'; import { unlock } from '../../private-apis'; -const { useGlobalSetting, useGlobalStyle } = unlock( blockEditorExperiments ); +const { useGlobalSetting, useGlobalStyle } = unlock( blockEditorPrivateApis ); function ScreenButtonColor( { name, variation = '' } ) { const prefix = variation ? `variations.${ variation }.` : ''; diff --git a/packages/edit-site/src/components/global-styles/screen-colors.js b/packages/edit-site/src/components/global-styles/screen-colors.js index e88892ac362640..dc40ca155b3387 100644 --- a/packages/edit-site/src/components/global-styles/screen-colors.js +++ b/packages/edit-site/src/components/global-styles/screen-colors.js @@ -10,7 +10,7 @@ import { FlexItem, ColorIndicator, } from '@wordpress/components'; -import { experiments as blockEditorExperiments } from '@wordpress/block-editor'; +import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor'; /** * Internal dependencies @@ -25,7 +25,7 @@ import BlockPreviewPanel from './block-preview-panel'; import { getVariationClassName } from './utils'; import { unlock } from '../../private-apis'; -const { useGlobalStyle } = unlock( blockEditorExperiments ); +const { useGlobalStyle } = unlock( blockEditorPrivateApis ); function BackgroundColorItem( { name, parentMenu, variation = '' } ) { const prefix = variation ? `variations.${ variation }.` : ''; diff --git a/packages/edit-site/src/components/global-styles/screen-heading-color.js b/packages/edit-site/src/components/global-styles/screen-heading-color.js index aa35e74851135d..859659092200f0 100644 --- a/packages/edit-site/src/components/global-styles/screen-heading-color.js +++ b/packages/edit-site/src/components/global-styles/screen-heading-color.js @@ -8,7 +8,7 @@ import { } from '@wordpress/components'; import { __experimentalColorGradientControl as ColorGradientControl, - experiments as blockEditorExperiments, + privateApis as blockEditorPrivateApis, } from '@wordpress/block-editor'; import { useState } from '@wordpress/element'; @@ -23,7 +23,7 @@ import { } from './hooks'; import { unlock } from '../../private-apis'; -const { useGlobalSetting, useGlobalStyle } = unlock( blockEditorExperiments ); +const { useGlobalSetting, useGlobalStyle } = unlock( blockEditorPrivateApis ); function ScreenHeadingColor( { name, variation = '' } ) { const prefix = variation ? `variations.${ variation }.` : ''; diff --git a/packages/edit-site/src/components/global-styles/screen-link-color.js b/packages/edit-site/src/components/global-styles/screen-link-color.js index 50e0c7ee34a4bd..fa2759dc0a19ec 100644 --- a/packages/edit-site/src/components/global-styles/screen-link-color.js +++ b/packages/edit-site/src/components/global-styles/screen-link-color.js @@ -4,7 +4,7 @@ import { __ } from '@wordpress/i18n'; import { __experimentalColorGradientControl as ColorGradientControl, - experiments as blockEditorExperiments, + privateApis as blockEditorPrivateApis, } from '@wordpress/block-editor'; import { TabPanel } from '@wordpress/components'; @@ -15,7 +15,7 @@ import ScreenHeader from './header'; import { useSupportedStyles, useColorsPerOrigin } from './hooks'; import { unlock } from '../../private-apis'; -const { useGlobalSetting, useGlobalStyle } = unlock( blockEditorExperiments ); +const { useGlobalSetting, useGlobalStyle } = unlock( blockEditorPrivateApis ); function ScreenLinkColor( { name, variation = '' } ) { const prefix = variation ? `variations.${ variation }.` : ''; diff --git a/packages/edit-site/src/components/global-styles/screen-root.js b/packages/edit-site/src/components/global-styles/screen-root.js index d015c5a5aff46d..3ec02647b62826 100644 --- a/packages/edit-site/src/components/global-styles/screen-root.js +++ b/packages/edit-site/src/components/global-styles/screen-root.js @@ -16,7 +16,7 @@ import { isRTL, __ } from '@wordpress/i18n'; import { chevronLeft, chevronRight } from '@wordpress/icons'; import { useSelect } from '@wordpress/data'; import { store as coreStore } from '@wordpress/core-data'; -import { experiments as blockEditorExperiments } from '@wordpress/block-editor'; +import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor'; /** * Internal dependencies @@ -28,7 +28,7 @@ import StylesPreview from './preview'; import { unlock } from '../../private-apis'; function ScreenRoot() { - const { useGlobalStyle } = unlock( blockEditorExperiments ); + const { useGlobalStyle } = unlock( blockEditorPrivateApis ); const [ customCSS ] = useGlobalStyle( 'css' ); const { variations, canEditCSS } = useSelect( ( select ) => { diff --git a/packages/edit-site/src/components/global-styles/screen-style-variations.js b/packages/edit-site/src/components/global-styles/screen-style-variations.js index 7d2347dc77b4cc..10a5b66aa27bc6 100644 --- a/packages/edit-site/src/components/global-styles/screen-style-variations.js +++ b/packages/edit-site/src/components/global-styles/screen-style-variations.js @@ -25,7 +25,7 @@ import { import { __ } from '@wordpress/i18n'; import { store as blockEditorStore, - experiments as blockEditorExperiments, + privateApis as blockEditorPrivateApis, } from '@wordpress/block-editor'; /** @@ -36,7 +36,7 @@ import StylesPreview from './preview'; import ScreenHeader from './header'; import { unlock } from '../../private-apis'; -const { GlobalStylesContext } = unlock( blockEditorExperiments ); +const { GlobalStylesContext } = unlock( blockEditorPrivateApis ); function compareVariations( a, b ) { return ( diff --git a/packages/edit-site/src/components/global-styles/screen-text-color.js b/packages/edit-site/src/components/global-styles/screen-text-color.js index 8ae2689fb83672..72b7e25fa8a3b4 100644 --- a/packages/edit-site/src/components/global-styles/screen-text-color.js +++ b/packages/edit-site/src/components/global-styles/screen-text-color.js @@ -4,7 +4,7 @@ import { __ } from '@wordpress/i18n'; import { __experimentalColorGradientControl as ColorGradientControl, - experiments as blockEditorExperiments, + privateApis as blockEditorPrivateApis, } from '@wordpress/block-editor'; /** @@ -14,7 +14,7 @@ import ScreenHeader from './header'; import { useSupportedStyles, useColorsPerOrigin } from './hooks'; import { unlock } from '../../private-apis'; -const { useGlobalSetting, useGlobalStyle } = unlock( blockEditorExperiments ); +const { useGlobalSetting, useGlobalStyle } = unlock( blockEditorPrivateApis ); function ScreenTextColor( { name, variation = '' } ) { const prefix = variation ? `variations.${ variation }.` : ''; diff --git a/packages/edit-site/src/components/global-styles/screen-typography.js b/packages/edit-site/src/components/global-styles/screen-typography.js index b169206535388b..96df1ff9d656ea 100644 --- a/packages/edit-site/src/components/global-styles/screen-typography.js +++ b/packages/edit-site/src/components/global-styles/screen-typography.js @@ -8,7 +8,7 @@ import { __experimentalHStack as HStack, FlexItem, } from '@wordpress/components'; -import { experiments as blockEditorExperiments } from '@wordpress/block-editor'; +import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor'; /** * Internal dependencies @@ -21,7 +21,7 @@ import BlockPreviewPanel from './block-preview-panel'; import { getVariationClassName } from './utils'; import { unlock } from '../../private-apis'; -const { useGlobalStyle } = unlock( blockEditorExperiments ); +const { useGlobalStyle } = unlock( blockEditorPrivateApis ); function Item( { name, parentMenu, element, label } ) { const hasSupport = ! name; diff --git a/packages/edit-site/src/components/global-styles/shadow-panel.js b/packages/edit-site/src/components/global-styles/shadow-panel.js index a0c8251dfa5434..8272d907264432 100644 --- a/packages/edit-site/src/components/global-styles/shadow-panel.js +++ b/packages/edit-site/src/components/global-styles/shadow-panel.js @@ -22,7 +22,7 @@ import { import { __ } from '@wordpress/i18n'; import { shadow as shadowIcon, Icon, check } from '@wordpress/icons'; import { useCallback } from '@wordpress/element'; -import { experiments as blockEditorExperiments } from '@wordpress/block-editor'; +import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor'; /** * Internal dependencies @@ -31,7 +31,7 @@ import { useSupportedStyles } from './hooks'; import { IconWithCurrentColor } from './icon-with-current-color'; import { unlock } from '../../private-apis'; -const { useGlobalSetting, useGlobalStyle } = unlock( blockEditorExperiments ); +const { useGlobalSetting, useGlobalStyle } = unlock( blockEditorPrivateApis ); export function useHasShadowControl( name ) { const supports = useSupportedStyles( name ); diff --git a/packages/edit-site/src/components/global-styles/typography-panel.js b/packages/edit-site/src/components/global-styles/typography-panel.js index 10b8b1e1bb6b46..d77594b13663f8 100644 --- a/packages/edit-site/src/components/global-styles/typography-panel.js +++ b/packages/edit-site/src/components/global-styles/typography-panel.js @@ -1,7 +1,7 @@ /** * WordPress dependencies */ -import { experiments as blockEditorExperiments } from '@wordpress/block-editor'; +import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor'; /** * Internal dependencies @@ -12,7 +12,7 @@ const { useGlobalStyle, useGlobalSetting, TypographyPanel: StylesTypographyPanel, -} = unlock( blockEditorExperiments ); +} = unlock( blockEditorPrivateApis ); export default function TypographyPanel( { name, diff --git a/packages/edit-site/src/components/global-styles/typography-preview.js b/packages/edit-site/src/components/global-styles/typography-preview.js index 3f394d2c50bd77..34a64e23fc1c79 100644 --- a/packages/edit-site/src/components/global-styles/typography-preview.js +++ b/packages/edit-site/src/components/global-styles/typography-preview.js @@ -1,14 +1,14 @@ /** * WordPress dependencies */ -import { experiments as blockEditorExperiments } from '@wordpress/block-editor'; +import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor'; /** * Internal dependencies */ import { unlock } from '../../private-apis'; -const { useGlobalStyle } = unlock( blockEditorExperiments ); +const { useGlobalStyle } = unlock( blockEditorPrivateApis ); export default function TypographyPreview( { name, element, headingLevel } ) { let prefix = ''; diff --git a/packages/edit-site/src/components/global-styles/ui.js b/packages/edit-site/src/components/global-styles/ui.js index c11e3f05923bcf..157ed92e2efabf 100644 --- a/packages/edit-site/src/components/global-styles/ui.js +++ b/packages/edit-site/src/components/global-styles/ui.js @@ -10,7 +10,7 @@ import { } from '@wordpress/components'; import { getBlockTypes, store as blocksStore } from '@wordpress/blocks'; import { useSelect, useDispatch } from '@wordpress/data'; -import { experiments as blockEditorExperiments } from '@wordpress/block-editor'; +import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor'; import { __ } from '@wordpress/i18n'; import { store as preferencesStore } from '@wordpress/preferences'; import { moreVertical } from '@wordpress/icons'; @@ -60,7 +60,7 @@ function GlobalStylesActionMenu() { !! globalStyles?._links?.[ 'wp:action-edit-css' ] ?? false, }; }, [] ); - const { useGlobalStylesReset } = unlock( blockEditorExperiments ); + const { useGlobalStylesReset } = unlock( blockEditorPrivateApis ); const [ canReset, onReset ] = useGlobalStylesReset(); const { goTo } = useNavigator(); const loadCustomCSS = () => goTo( '/css' ); diff --git a/packages/edit-site/src/components/navigation-inspector/navigation-menu.js b/packages/edit-site/src/components/navigation-inspector/navigation-menu.js index e261fdaa4030d0..44acc24da62cf9 100644 --- a/packages/edit-site/src/components/navigation-inspector/navigation-menu.js +++ b/packages/edit-site/src/components/navigation-inspector/navigation-menu.js @@ -2,7 +2,7 @@ * WordPress dependencies */ import { - experiments as blockEditorExperiments, + privateApis as blockEditorPrivateApis, store as blockEditorStore, } from '@wordpress/block-editor'; import { useEffect } from '@wordpress/element'; @@ -39,7 +39,7 @@ const ALLOWED_BLOCKS = { export default function NavigationMenu( { innerBlocks, onSelect } ) { const { updateBlockListSettings } = useDispatch( blockEditorStore ); - const { OffCanvasEditor, LeafMoreMenu } = unlock( blockEditorExperiments ); + const { OffCanvasEditor, LeafMoreMenu } = unlock( blockEditorPrivateApis ); //TODO: Block settings are normally updated as a side effect of rendering InnerBlocks in BlockList //Think through a better way of doing this, possible with adding allowed blocks to block library metadata diff --git a/packages/edit-site/src/components/style-book/index.js b/packages/edit-site/src/components/style-book/index.js index dfeb1d419c9348..b4f55ad1de2715 100644 --- a/packages/edit-site/src/components/style-book/index.js +++ b/packages/edit-site/src/components/style-book/index.js @@ -21,7 +21,7 @@ import { } from '@wordpress/blocks'; import { BlockPreview, - experiments as blockEditorExperiments, + privateApis as blockEditorPrivateApis, } from '@wordpress/block-editor'; import { closeSmall } from '@wordpress/icons'; import { useResizeObserver } from '@wordpress/compose'; @@ -32,7 +32,7 @@ import { useMemo, memo } from '@wordpress/element'; */ import { unlock } from '../../private-apis'; -const { useGlobalStyle } = unlock( blockEditorExperiments ); +const { useGlobalStyle } = unlock( blockEditorPrivateApis ); const SLOT_FILL_NAME = 'EditSiteStyleBook'; const { Slot: StyleBookSlot, Fill: StyleBookFill } = diff --git a/packages/edit-site/src/hooks/push-changes-to-global-styles/index.js b/packages/edit-site/src/hooks/push-changes-to-global-styles/index.js index 24b71c8aaffaf7..815aa6f6b20c32 100644 --- a/packages/edit-site/src/hooks/push-changes-to-global-styles/index.js +++ b/packages/edit-site/src/hooks/push-changes-to-global-styles/index.js @@ -11,7 +11,7 @@ import { createHigherOrderComponent } from '@wordpress/compose'; import { InspectorAdvancedControls, store as blockEditorStore, - experiments as blockEditorExperiments, + privateApis as blockEditorPrivateApis, } from '@wordpress/block-editor'; import { BaseControl, Button } from '@wordpress/components'; import { __, sprintf } from '@wordpress/i18n'; @@ -29,7 +29,7 @@ import { store as noticesStore } from '@wordpress/notices'; import { useSupportedStyles } from '../../components/global-styles/hooks'; import { unlock } from '../../private-apis'; -const { GlobalStylesContext } = unlock( blockEditorExperiments ); +const { GlobalStylesContext } = unlock( blockEditorPrivateApis ); // TODO: Temporary duplication of constant in @wordpress/block-editor. Can be // removed by moving PushChangesToGlobalStylesControl to diff --git a/packages/edit-widgets/src/components/widget-areas-block-editor-provider/index.js b/packages/edit-widgets/src/components/widget-areas-block-editor-provider/index.js index 42d8117c14234c..042cd0dc9c6177 100644 --- a/packages/edit-widgets/src/components/widget-areas-block-editor-provider/index.js +++ b/packages/edit-widgets/src/components/widget-areas-block-editor-provider/index.js @@ -13,7 +13,7 @@ import { useMemo } from '@wordpress/element'; import { BlockEditorKeyboardShortcuts, CopyHandler, - experiments as blockEditorExperiments, + privateApis as blockEditorPrivateApis, } from '@wordpress/block-editor'; import { ReusableBlocksMenuItems } from '@wordpress/reusable-blocks'; import { ShortcutProvider } from '@wordpress/keyboard-shortcuts'; @@ -29,7 +29,7 @@ import { store as editWidgetsStore } from '../../store'; import { ALLOW_REUSABLE_BLOCKS } from '../../constants'; import { unlock } from '../../private-apis'; -const { ExperimentalBlockEditorProvider } = unlock( blockEditorExperiments ); +const { ExperimentalBlockEditorProvider } = unlock( blockEditorPrivateApis ); export default function WidgetAreasBlockEditorProvider( { blockEditorSettings, diff --git a/packages/editor/src/components/provider/index.js b/packages/editor/src/components/provider/index.js index eaf9b1bf7d19dd..1cff19c7daae7f 100644 --- a/packages/editor/src/components/provider/index.js +++ b/packages/editor/src/components/provider/index.js @@ -8,7 +8,7 @@ import { EntityProvider, useEntityBlockEditor } from '@wordpress/core-data'; import { BlockEditorProvider, BlockContextProvider, - experiments as blockEditorExperiments, + privateApis as blockEditorPrivateApis, } from '@wordpress/block-editor'; import { ReusableBlocksMenuItems } from '@wordpress/reusable-blocks'; import { store as noticesStore } from '@wordpress/notices'; @@ -21,7 +21,7 @@ import { store as editorStore } from '../../store'; import useBlockEditorSettings from './use-block-editor-settings'; import { unlock } from '../../lockUnlock'; -const { ExperimentalBlockEditorProvider } = unlock( blockEditorExperiments ); +const { ExperimentalBlockEditorProvider } = unlock( blockEditorPrivateApis ); export const ExperimentalEditorProvider = withRegistryProvider( ( { diff --git a/packages/editor/src/private-apis.js b/packages/editor/src/private-apis.js index c54c895d961a03..edfc3045f1100d 100644 --- a/packages/editor/src/private-apis.js +++ b/packages/editor/src/private-apis.js @@ -4,7 +4,7 @@ import { ExperimentalEditorProvider } from './components/provider'; import { lock } from './lockUnlock'; -export const experiments = {}; -lock( experiments, { +export const privateApis = {}; +lock( privateApis, { ExperimentalEditorProvider, } ); diff --git a/packages/private-apis/README.md b/packages/private-apis/README.md index a57e5e339e4be7..828663dc760de6 100644 --- a/packages/private-apis/README.md +++ b/packages/private-apis/README.md @@ -58,17 +58,17 @@ Use `lock()` and `unlock()` to privately distribute the `__experimental` APIs ac // In packages/package1/index.js: import { lock } from './private-apis'; -export const experiments = {}; +export const privateApis = {}; /* Attach private data to the exported object */ -lock( experiments, { +lock( privateApis, { __experimentalFunction: function () {}, } ); // In packages/package2/index.js: -import { experiments } from '@wordpress/package1'; +import { privateApis } from '@wordpress/package1'; import { unlock } from './private-apis'; -const { __experimentalFunction } = unlock( experiments ); +const { __experimentalFunction } = unlock( privateApis ); ``` ## Shipping experimental APIs diff --git a/packages/private-apis/src/implementation.js b/packages/private-apis/src/implementation.js index 26502a47231112..6a88e9812ca8c0 100644 --- a/packages/private-apis/src/implementation.js +++ b/packages/private-apis/src/implementation.js @@ -1,15 +1,15 @@ /** - * wordpress/experimental – the utilities to enable private cross-package - * exports of experimental APIs. + * wordpress/private-apis – the utilities to enable private cross-package + * exports of private APIs. * * This "implementation.js" file is needed for the sake of the unit tests. It * exports more than the public API of the package to aid in testing. */ /** - * The list of core modules allowed to opt-in to the experimental APIs. + * The list of core modules allowed to opt-in to the private APIs. */ -const CORE_MODULES_USING_EXPERIMENTS = [ +const CORE_MODULES_USING_PRIVATE_APIS = [ '@wordpress/block-editor', '@wordpress/block-library', '@wordpress/blocks', @@ -24,21 +24,21 @@ const CORE_MODULES_USING_EXPERIMENTS = [ /** * A list of core modules that already opted-in to - * the experiments package. + * the privateApis package. * * @type {string[]} */ -const registeredExperiments = []; +const registeredPrivateApis = []; /* * Warning for theme and plugin developers. * - * The use of experimental developer APIs is intended for use by WordPress Core + * The use of private developer APIs is intended for use by WordPress Core * and the Gutenberg plugin exclusively. * * Dangerously opting in to using these APIs is NOT RECOMMENDED. Furthermore, * the WordPress Core philosophy to strive to maintain backward compatibility - * for third-party developers DOES NOT APPLY to experimental APIs. + * for third-party developers DOES NOT APPLY to private APIs. * * THE CONSENT STRING FOR OPTING IN TO THESE APIS MAY CHANGE AT ANY TIME AND * WITHOUT NOTICE. THIS CHANGE WILL BREAK EXISTING THIRD-PARTY CODE. SUCH A @@ -59,7 +59,7 @@ try { /** * Called by a @wordpress package wishing to opt-in to accessing or exposing - * private experimental APIs. + * private private APIs. * * @param {string} consent The consent string. * @param {string} moduleName The name of the module that is opting in. @@ -69,7 +69,7 @@ export const __dangerousOptInToUnstableAPIsOnlyForCoreModules = ( consent, moduleName ) => { - if ( ! CORE_MODULES_USING_EXPERIMENTS.includes( moduleName ) ) { + if ( ! CORE_MODULES_USING_PRIVATE_APIS.includes( moduleName ) ) { throw new Error( `You tried to opt-in to unstable APIs as module "${ moduleName }". ` + 'This feature is only for JavaScript modules shipped with WordPress core. ' + @@ -80,7 +80,7 @@ export const __dangerousOptInToUnstableAPIsOnlyForCoreModules = ( } if ( ! allowReRegistration && - registeredExperiments.includes( moduleName ) + registeredPrivateApis.includes( moduleName ) ) { // This check doesn't play well with Story Books / Hot Module Reloading // and isn't included in the Gutenberg plugin. It only matters in the @@ -102,7 +102,7 @@ export const __dangerousOptInToUnstableAPIsOnlyForCoreModules = ( 'your product will inevitably break on the next WordPress release.' ); } - registeredExperiments.push( moduleName ); + registeredPrivateApis.push( moduleName ); return { lock, @@ -138,10 +138,10 @@ function lock( object, privateData ) { if ( ! object ) { throw new Error( 'Cannot lock an undefined object.' ); } - if ( ! ( __experiment in object ) ) { - object[ __experiment ] = {}; + if ( ! ( __private in object ) ) { + object[ __private ] = {}; } - lockedData.set( object[ __experiment ], privateData ); + lockedData.set( object[ __private ], privateData ); } /** @@ -171,13 +171,13 @@ function unlock( object ) { if ( ! object ) { throw new Error( 'Cannot unlock an undefined object.' ); } - if ( ! ( __experiment in object ) ) { + if ( ! ( __private in object ) ) { throw new Error( 'Cannot unlock an object that was not locked before. ' ); } - return lockedData.get( object[ __experiment ] ); + return lockedData.get( object[ __private ] ); } const lockedData = new WeakMap(); @@ -186,18 +186,18 @@ const lockedData = new WeakMap(); * Used by lock() and unlock() to uniquely identify the private data * related to a containing object. */ -const __experiment = Symbol( 'Experiment ID' ); +const __private = Symbol( 'Private API ID' ); // Unit tests utilities: /** * Private function to allow the unit tests to allow - * a mock module to access the experimental APIs. + * a mock module to access the private APIs. * * @param {string} name The name of the module. */ export function allowCoreModule( name ) { - CORE_MODULES_USING_EXPERIMENTS.push( name ); + CORE_MODULES_USING_PRIVATE_APIS.push( name ); } /** @@ -205,16 +205,16 @@ export function allowCoreModule( name ) { * a custom list of allowed modules. */ export function resetAllowedCoreModules() { - while ( CORE_MODULES_USING_EXPERIMENTS.length ) { - CORE_MODULES_USING_EXPERIMENTS.pop(); + while ( CORE_MODULES_USING_PRIVATE_APIS.length ) { + CORE_MODULES_USING_PRIVATE_APIS.pop(); } } /** * Private function to allow the unit tests to reset - * the list of registered experiments. + * the list of registered private apis. */ -export function resetRegisteredExperiments() { - while ( registeredExperiments.length ) { - registeredExperiments.pop(); +export function resetRegisteredPrivateApis() { + while ( registeredPrivateApis.length ) { + registeredPrivateApis.pop(); } } diff --git a/packages/private-apis/src/test/index.js b/packages/private-apis/src/test/index.js index 2456d5ca5039d9..2e73a1a58eaa1f 100644 --- a/packages/private-apis/src/test/index.js +++ b/packages/private-apis/src/test/index.js @@ -3,16 +3,16 @@ */ import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '../'; import { - resetRegisteredExperiments, + resetRegisteredPrivateApis, resetAllowedCoreModules, allowCoreModule, } from '../implementation'; beforeEach( () => { - resetRegisteredExperiments(); + resetRegisteredPrivateApis(); resetAllowedCoreModules(); - allowCoreModule( '@experiments/test' ); - allowCoreModule( '@experiments/test-consumer' ); + allowCoreModule( '@privateApis/test' ); + allowCoreModule( '@privateApis/test-consumer' ); } ); const requiredConsent = @@ -23,7 +23,7 @@ describe( '__dangerousOptInToUnstableAPIsOnlyForCoreModules', () => { expect( () => { __dangerousOptInToUnstableAPIsOnlyForCoreModules( '', - '@experiments/test' + '@privateApis/test' ); } ).toThrow( /without confirming you know the consequences/ ); } ); @@ -41,18 +41,18 @@ describe( '__dangerousOptInToUnstableAPIsOnlyForCoreModules', () => { expect( () => { __dangerousOptInToUnstableAPIsOnlyForCoreModules( requiredConsent, - '@experiments/test' + '@privateApis/test' ); __dangerousOptInToUnstableAPIsOnlyForCoreModules( requiredConsent, - '@experiments/test' + '@privateApis/test' ); } ).toThrow( /is already registered/ ); } ); it( 'Should grant access to unstable APIs when passed both a consent string and a previously unregistered package name', () => { const unstableAPIs = __dangerousOptInToUnstableAPIsOnlyForCoreModules( requiredConsent, - '@experiments/test' + '@privateApis/test' ); expect( unstableAPIs.lock ).toEqual( expect.any( Function ) ); expect( unstableAPIs.unlock ).toEqual( expect.any( Function ) ); @@ -62,14 +62,14 @@ describe( '__dangerousOptInToUnstableAPIsOnlyForCoreModules', () => { describe( 'lock(), unlock()', () => { let lock, unlock; beforeEach( () => { - // This would live in @experiments/test: - // Opt-in to experimental APIs - const experimentsAPI = __dangerousOptInToUnstableAPIsOnlyForCoreModules( + // This would live in @privateApis/test: + // Opt-in to private APIs + const privateApisAPI = __dangerousOptInToUnstableAPIsOnlyForCoreModules( requiredConsent, - '@experiments/test' + '@privateApis/test' ); - lock = experimentsAPI.lock; - unlock = experimentsAPI.unlock; + lock = privateApisAPI.lock; + unlock = privateApisAPI.unlock; } ); it( 'Should lock and unlock objects "inside" other objects', () => { @@ -120,95 +120,95 @@ describe( 'lock(), unlock()', () => { lock( object, privateData ); // This would live in @wordpress/core-data: - // Register the experimental APIs - const coreDataExperiments = + // Register the private APIs + const coreDataPrivateApis = __dangerousOptInToUnstableAPIsOnlyForCoreModules( requiredConsent, - '@experiments/test-consumer' + '@privateApis/test-consumer' ); - // Get the experimental APIs registered by @experiments/test - expect( coreDataExperiments.unlock( object ).secret ).toBe( 'sh' ); + // Get the private APIs registered by @privateApis/test + expect( coreDataPrivateApis.unlock( object ).secret ).toBe( 'sh' ); } ); } ); describe( 'Specific use-cases of sharing private APIs', () => { let lock, unlock; beforeEach( () => { - // This would live in @experiments/test: - // Opt-in to experimental APIs - const experimentsAPI = __dangerousOptInToUnstableAPIsOnlyForCoreModules( + // This would live in @privateApis/test: + // Opt-in to private APIs + const privateApisAPI = __dangerousOptInToUnstableAPIsOnlyForCoreModules( requiredConsent, - '@experiments/test' + '@privateApis/test' ); - lock = experimentsAPI.lock; - unlock = experimentsAPI.unlock; + lock = privateApisAPI.lock; + unlock = privateApisAPI.unlock; } ); - it( 'Should enable privately exporting experimental functions', () => { + it( 'Should enable privately exporting private functions', () => { /** - * Problem: The private __experimentalFunction should not be publicly + * Problem: The private __privateFunction should not be publicly * exposed to the consumers of package1. */ - function __experimentalFunction() {} + function __privateFunction() {} /** * Solution: Privately lock it inside a publicly exported object. * * In `package1/index.js` we'd say: * * ```js - * export const experiments = {}; - * lock(experiments, { - * __experimentalFunction + * export const privateApis = {}; + * lock(privateApis, { + * __privateFunction * }); * ``` * * Let's simulate in the test code: */ - const experiments = {}; + const privateApis = {}; const package1Exports = { - experiments, + privateApis, }; - lock( experiments, { __experimentalFunction } ); + lock( privateApis, { __privateFunction } ); /** * Then, in the consumer package we'd say: * * ```js - * import { experiments } from 'package1'; - * const { __experimentalFunction } = unlock( experiments ); + * import { privateApis } from 'package1'; + * const { __privateFunction } = unlock( privateApis ); * ``` * * Let's simulate that, too: */ const unlockedFunction = unlock( - package1Exports.experiments - ).__experimentalFunction; - expect( unlockedFunction ).toBe( __experimentalFunction ); + package1Exports.privateApis + ).__privateFunction; + expect( unlockedFunction ).toBe( __privateFunction ); } ); - it( 'Should enable exporting functions with private experimental arguments', () => { + it( 'Should enable exporting functions with private private arguments', () => { /** - * The publicly exported function does not have any experimental + * The publicly exported function does not have any private * arguments. * * @param {any} data The data to log */ function logData( data ) { - // Internally, it calls the experimental version of the function - // with fixed default values for the experimental arguments. - __experimentalLogData( data, 'plain' ); + // Internally, it calls the private version of the function + // with fixed default values for the private arguments. + __privateLogData( data, 'plain' ); } /** - * The private experimental function is not publicly exported. Instead, it's + * The private private function is not publicly exported. Instead, it's * "locked" inside of the public logData function. It can be unlocked by any * participant of the private importing system. * - * @param {any} data The data to log - * @param {string} __experimentalFormat The logging format to use. + * @param {any} data The data to log + * @param {string} __privateFormat The logging format to use. */ - function __experimentalLogData( data, __experimentalFormat ) { - if ( __experimentalFormat === 'table' ) { + function __privateLogData( data, __privateFormat ) { + if ( __privateFormat === 'table' ) { // eslint-disable-next-line no-console console.table( data ); } else { @@ -216,12 +216,12 @@ describe( 'Specific use-cases of sharing private APIs', () => { console.log( data ); } } - lock( logData, __experimentalLogData ); + lock( logData, __privateLogData ); /** * In package/log-data.js: * * ```js - * lock( logData, __experimentalLogData ); + * lock( logData, __privateLogData ); * export logData; * ``` * @@ -232,43 +232,40 @@ describe( 'Specific use-cases of sharing private APIs', () => { * ``` * * And that's it! The public function is publicly exported, and the - * experimental function is available via unlock( logData ): + * private function is available via unlock( logData ): * * ```js * import { logData } from 'package1'; * const experimenalLogData = unlock( logData ); * ``` */ - expect( unlock( logData ) ).toBe( __experimentalLogData ); + expect( unlock( logData ) ).toBe( __privateLogData ); } ); - it( 'Should enable exporting React Components with private experimental properties', () => { + it( 'Should enable exporting React Components with private private properties', () => { // eslint-disable-next-line jsdoc/require-param /** - * The publicly exported component does not have any experimental + * The publicly exported component does not have any private * properties. */ function DataTable( { data } ) { - // Internally, it calls the experimental version of the function - // with fixed default values for the experimental arguments. + // Internally, it calls the private version of the function + // with fixed default values for the private arguments. return ( - ); } // eslint-disable-next-line jsdoc/require-param /** - * The private experimental component is not publicly exported. Instead, it's + * The private private component is not publicly exported. Instead, it's * "locked" inside of the public logData function. It can be unlocked by any * participant of the private importing system. */ - function ExperimentalDataTable( { - data, - __experimentalFancyFormatting, - } ) { - const className = __experimentalFancyFormatting + function PrivateDataTable( { data, __privateFancyFormatting } ) { + const className = __privateFancyFormatting ? 'savage-css' : 'regular-css'; return ( @@ -283,12 +280,12 @@ describe( 'Specific use-cases of sharing private APIs', () => { ); } - lock( DataTable, ExperimentalDataTable ); + lock( DataTable, PrivateDataTable ); /** * In package/data-table.js: * * ```js - * lock( DataTable, ExperimentalDataTable ); + * lock( DataTable, PrivateDataTable ); * export DataTable; * ``` * @@ -299,13 +296,13 @@ describe( 'Specific use-cases of sharing private APIs', () => { * ``` * * And that's it! The public function is publicly exported, and the - * experimental function is available via unlock( logData ): + * private function is available via unlock( logData ): * * ```js * import { DataTable } from 'package1'; - * const ExperimentalDataTable = unlock( DataTable ); + * const PrivateDataTable = unlock( DataTable ); * ``` */ - expect( unlock( DataTable ) ).toBe( ExperimentalDataTable ); + expect( unlock( DataTable ) ).toBe( PrivateDataTable ); } ); } );