Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
6 changes: 6 additions & 0 deletions docs/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2621,6 +2621,12 @@
"markdown_source": "../packages/jest-preset-default/README.md",
"parent": "packages"
},
{
"title": "@wordpress/kebab-case",
"slug": "packages-kebab-case",
"markdown_source": "../packages/kebab-case/README.md",
"parent": "packages"
},
{
"title": "@wordpress/keyboard-shortcuts",
"slug": "packages-keyboard-shortcuts",
Expand Down
23 changes: 22 additions & 1 deletion package-lock.json

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

4 changes: 4 additions & 0 deletions packages/block-editor/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Internal

- Use the new `@wordpress/kebab-case` package instead of unlocking the `kebabCase` utility from the `@wordpress/components` private APIs ([#81294](https://github.com/WordPress/gutenberg/pull/81294)).

### Enhancements

- Creating a new block next to a sibling of the same type now inherits the sibling's attributes consistently, whether it is created by the appender, the inserter, or Enter at the edge of the text. Everything except the sibling's content (attributes with the `content` role) and its `metadata` is copied. The `attributesToCopy` list of a default block is removed: the copied attributes derive from the block's attribute roles.
Expand Down
1 change: 1 addition & 0 deletions packages/block-editor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
"@wordpress/image-cropper": "file:../image-cropper",
"@wordpress/interactivity": "file:../interactivity",
"@wordpress/is-shallow-equal": "file:../is-shallow-equal",
"@wordpress/kebab-case": "file:../kebab-case",
"@wordpress/keyboard-shortcuts": "file:../keyboard-shortcuts",
"@wordpress/keycodes": "file:../keycodes",
"@wordpress/notices": "file:../notices",
Expand Down
5 changes: 1 addition & 4 deletions packages/block-editor/src/components/colors/utils.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import { colord, extend } from 'colord';
import namesPlugin from 'colord/plugins/names';
import a11yPlugin from 'colord/plugins/a11y';
import { privateApis as componentsPrivateApis } from '@wordpress/components';
import { unlock } from '../../lock-unlock';
import { kebabCase } from '@wordpress/kebab-case';

extend( [ namesPlugin, a11yPlugin ] );

const { kebabCase } = unlock( componentsPrivateApis );

/**
* Provided an array of color objects as set by the theme or by the editor defaults,
* and the values of the defined color or custom color returns a color object describing the color.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import { useMemo, Component } from '@wordpress/element';
import { compose, createHigherOrderComponent } from '@wordpress/compose';
import { privateApis as componentsPrivateApis } from '@wordpress/components';
import { kebabCase } from '@wordpress/kebab-case';
import {
getColorClassName,
getColorObjectByColorValue,
getColorObjectByAttributeValues,
getMostReadableColor,
} from './utils';
import { useSettings } from '../use-settings';
import { unlock } from '../../lock-unlock';

const { kebabCase } = unlock( componentsPrivateApis );

/**
* Capitalizes the first letter in a string.
Expand Down
5 changes: 1 addition & 4 deletions packages/block-editor/src/components/font-sizes/utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import { privateApis as componentsPrivateApis } from '@wordpress/components';
import { unlock } from '../../lock-unlock';

const { kebabCase } = unlock( componentsPrivateApis );
import { kebabCase } from '@wordpress/kebab-case';

/**
* Returns the font size object based on an array of named font sizes and the namedFontSize and customFontSize values.
Expand Down
4 changes: 1 addition & 3 deletions packages/block-editor/src/hooks/font-family.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { addFilter } from '@wordpress/hooks';
import { hasBlockSupport } from '@wordpress/blocks';
import TokenList from '@wordpress/token-list';
import { privateApis as componentsPrivateApis } from '@wordpress/components';
import { kebabCase } from '@wordpress/kebab-case';
import { shouldSkipSerialization } from './utils';
import { TYPOGRAPHY_SUPPORT_KEY } from './typography';
import { unlock } from '../lock-unlock';

export const FONT_FAMILY_SUPPORT_KEY = 'typography.__experimentalFontFamily';
const { kebabCase } = unlock( componentsPrivateApis );

/**
* Filters registered block settings, extending attributes to include
Expand Down
3 changes: 1 addition & 2 deletions packages/block-editor/src/hooks/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import {
__experimentalToggleGroupControlOption as ToggleGroupControlOption,
ToggleControl,
__experimentalToolsPanelItem as ToolsPanelItem,
privateApis as componentsPrivateApis,
} from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { kebabCase } from '@wordpress/kebab-case';
import { store as blockEditorStore } from '../store';
import { InspectorControls } from '../components';
import { useSettings } from '../components/use-settings';
Expand Down Expand Up @@ -47,7 +47,6 @@ const CHILD_LAYOUT_KEYS = [
'rowStart',
'rowSpan',
];
const { kebabCase } = unlock( componentsPrivateApis );
const { getResponsiveMediaQueries } = unlock( globalStylesEnginePrivateApis );

function getDefaultLayout( layoutBlockSupport = {}, blockVariation ) {
Expand Down
5 changes: 1 addition & 4 deletions packages/block-editor/src/hooks/use-typography-props.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import clsx from 'clsx';
import { privateApis as componentsPrivateApis } from '@wordpress/components';
import { getTypographyFontSizeValue } from '@wordpress/global-styles-engine';
import { kebabCase } from '@wordpress/kebab-case';
import { getInlineStyles } from './style';
import { getFontSizeClass } from '../components/font-sizes';
import { unlock } from '../lock-unlock';

const { kebabCase } = unlock( componentsPrivateApis );

/*
* This utility is intended to assist where the serialization of the typography
Expand Down
1 change: 1 addition & 0 deletions packages/block-editor/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
{ "path": "../image-cropper" },
{ "path": "../interactivity" },
{ "path": "../is-shallow-equal" },
{ "path": "../kebab-case" },
{ "path": "../keycodes" },
{ "path": "../keyboard-shortcuts" },
{ "path": "../notices" },
Expand Down
4 changes: 4 additions & 0 deletions packages/block-library/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Internal

- Embed: Use the new `@wordpress/kebab-case` package instead of unlocking the `kebabCase` utility from the `@wordpress/components` private APIs ([#81294](https://github.com/WordPress/gutenberg/pull/81294)).

### Enhancements

- Playlist Track: Use a dedicated icon for the block toolbar. ([#80959](https://github.com/WordPress/gutenberg/pull/80959))
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
"@wordpress/icons": "file:../icons",
"@wordpress/interactivity": "file:../interactivity",
"@wordpress/interactivity-router": "file:../interactivity-router",
"@wordpress/kebab-case": "file:../kebab-case",
"@wordpress/keyboard-shortcuts": "file:../keyboard-shortcuts",
"@wordpress/keycodes": "file:../keycodes",
"@wordpress/latex-to-mathml": "file:../latex-to-mathml",
Expand Down
4 changes: 1 addition & 3 deletions packages/block-library/src/embed/util.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import clsx from 'clsx';
import memoize from 'memize';
import { privateApis as componentsPrivateApis } from '@wordpress/components';
import { renderToString } from '@wordpress/element';
import {
createBlock,
getBlockType,
getBlockVariations,
} from '@wordpress/blocks';
import { getAuthority } from '@wordpress/url';
import { kebabCase } from '@wordpress/kebab-case';
import metadata from './block.json';
import { ASPECT_RATIOS, WP_EMBED_TYPE } from './constants';
import { unlock } from '../lock-unlock';

const { name: DEFAULT_EMBED_BLOCK } = metadata;
const { kebabCase } = unlock( componentsPrivateApis );

/** @typedef {import('@wordpress/blocks').WPBlockVariation} WPBlockVariation */

Expand Down
1 change: 1 addition & 0 deletions packages/block-library/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
{ "path": "../interactivity-router" },
{ "path": "../latex-to-mathml" },
{ "path": "../notices" },
{ "path": "../kebab-case" },
{ "path": "../keycodes" },
{ "path": "../keyboard-shortcuts" },
{ "path": "../primitives" },
Expand Down
2 changes: 2 additions & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
### Internal

- Move `withIgnoreIMEEvents` to `@wordpress/keycodes`, where it is now a public API, and remove it from this package's private APIs ([#81343](https://github.com/WordPress/gutenberg/pull/81343)).
- Extract the private `kebabCase` utility to the new `@wordpress/kebab-case` package and remove it from the private APIs; all consumers now use the package directly ([#81294](https://github.com/WordPress/gutenberg/pull/81294)).
- Remove `normalizeTextString` from the private APIs; the utility remains internal to this package ([#81294](https://github.com/WordPress/gutenberg/pull/81294)).
- Remove obsolete dependency grouping comments as part of the repository-wide separator-free import migration. ([#81248](https://github.com/WordPress/gutenberg/pull/81248))
- `Button`: Expand the Storybook e2e `VariantStates` matrix with compact, small, and with-icon rows ([#80793](https://github.com/WordPress/gutenberg/pull/80793)).
- Update `react-day-picker` to 9.14.0 ([#80792](https://github.com/WordPress/gutenberg/pull/80792)).
Expand Down
1 change: 1 addition & 0 deletions packages/components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
"@wordpress/i18n": "file:../i18n",
"@wordpress/icons": "file:../icons",
"@wordpress/is-shallow-equal": "file:../is-shallow-equal",
"@wordpress/kebab-case": "file:../kebab-case",
"@wordpress/keycodes": "file:../keycodes",
"@wordpress/primitives": "file:../primitives",
"@wordpress/private-apis": "file:../private-apis",
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/palette-edit/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
import { __, sprintf } from '@wordpress/i18n';
import { lineSolid, moreVertical, plus } from '@wordpress/icons';
import { useDebounce } from '@wordpress/compose';
import { kebabCase } from '@wordpress/kebab-case';
import Button from '../button';
import { ColorPicker } from '../color-picker';
import { FlexBlock, FlexItem } from '../flex';
Expand All @@ -33,7 +34,6 @@ import {
import { NavigableMenu } from '../navigable-container';
import { DEFAULT_GRADIENT } from '../custom-gradient-picker/constants';
import CustomGradientPicker from '../custom-gradient-picker';
import { kebabCase } from '../utils/strings';
import type {
Color,
ColorPickerPopoverProps,
Expand Down
3 changes: 0 additions & 3 deletions packages/components/src/private-apis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { positionToPlacement as __experimentalPopoverLegacyPositionToPlacement }
import { Menu } from './menu';
import { ComponentsContext } from './context/context-system-provider';
import { Tabs } from './tabs';
import { kebabCase, normalizeTextString } from './utils/strings';
import { lock } from './lock-unlock';
import Badge from './badge';
import { DateCalendar, DateRangeCalendar, TZDate } from './calendar';
Expand All @@ -30,9 +29,7 @@ lock( privateApis, {
ComponentsContext,
Tabs,
Menu,
kebabCase,
Badge,
normalizeTextString,
DateCalendar,
DateRangeCalendar,
TZDate,
Expand Down
28 changes: 0 additions & 28 deletions packages/components/src/utils/strings.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import removeAccents from 'remove-accents';
import { paramCase } from 'change-case';

@youknowriad youknowriad Aug 7, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What about the other functions here in this file, are they good candidates for the string package?

/**
* All unicode characters that we consider "dash-like":
Expand All @@ -22,33 +21,6 @@ export const normalizeTextString = ( value: string ): string => {
.replace( ALL_UNICODE_DASH_CHARACTERS, '-' );
};

/**
* Converts any string to kebab case.
* Backwards compatible with Lodash's `_.kebabCase()`.
* Backwards compatible with `_wp_to_kebab_case()`.
*
* @see https://lodash.com/docs/4.17.15#kebabCase
* @see https://developer.wordpress.org/reference/functions/_wp_to_kebab_case/
*
* @param str String to convert.
* @return Kebab-cased string
*/
export function kebabCase( str: unknown ) {
let input = str?.toString?.() ?? '';

// See https://github.com/lodash/lodash/blob/b185fcee26b2133bd071f4aaca14b455c2ed1008/lodash.js#L4970
input = input.replace( /['\u2019]/, '' );

return paramCase( input, {
splitRegexp: [
/(?!(?:1ST|2ND|3RD|[4-9]TH)(?![a-z]))([a-z0-9])([A-Z])/g, // fooBar => foo-bar, 3Bar => 3-bar
/(?!(?:1st|2nd|3rd|[4-9]th)(?![a-z]))([0-9])([a-z])/g, // 3bar => 3-bar
/([A-Za-z])([0-9])/g, // Foo3 => foo-3, foo3 => foo-3
/([A-Z])([A-Z][a-z])/g, // FOOBar => foo-bar
],
} );
}
Comment on lines -36 to -50

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This has been migrated verbatim to packages/string/src/index.js.


/**
* Escapes the RegExp special characters.
*
Expand Down
Loading
Loading