@elementor/editor-controls 0.16.0 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +33 -0
- package/dist/index.d.mts +19 -6
- package/dist/index.d.ts +19 -6
- package/dist/index.js +340 -167
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +344 -160
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -5
- package/src/components/control-toggle-button-group.tsx +5 -0
- package/src/components/enable-unfiltered-modal.tsx +130 -0
- package/src/components/repeater.tsx +39 -10
- package/src/components/sortable.tsx +2 -7
- package/src/controls/background-control/background-gradient-color-control.tsx +1 -1
- package/src/controls/background-control/background-overlay/background-overlay-repeater-control.tsx +38 -10
- package/src/controls/box-shadow-repeater-control.tsx +15 -4
- package/src/controls/equal-unequal-sizes-control.tsx +1 -1
- package/src/controls/font-family-control/font-family-control.tsx +7 -2
- package/src/controls/link-control.tsx +11 -2
- package/src/controls/svg-media-control.tsx +20 -5
- package/src/controls/toggle-control.tsx +36 -10
- package/src/hooks/use-filtered-font-families.ts +15 -16
- package/src/index.ts +2 -0
- package/src/utils/link-restriction.ts +47 -0
- package/src/utils/types.ts +5 -0
|
@@ -6,28 +6,54 @@ import { useBoundProp } from '../bound-prop-context';
|
|
|
6
6
|
import { ControlToggleButtonGroup, type ToggleButtonGroupItem } from '../components/control-toggle-button-group';
|
|
7
7
|
import { createControl } from '../create-control';
|
|
8
8
|
|
|
9
|
-
type ToggleControlProps< T extends PropValue > = {
|
|
10
|
-
options: ToggleButtonGroupItem< T >
|
|
9
|
+
export type ToggleControlProps< T extends PropValue > = {
|
|
10
|
+
options: Array< ToggleButtonGroupItem< T > & { exclusive?: boolean } >;
|
|
11
11
|
fullWidth?: boolean;
|
|
12
12
|
size?: ToggleButtonProps[ 'size' ];
|
|
13
|
+
exclusive?: boolean;
|
|
13
14
|
};
|
|
14
15
|
|
|
15
16
|
export const ToggleControl = createControl(
|
|
16
|
-
( {
|
|
17
|
+
( {
|
|
18
|
+
options,
|
|
19
|
+
fullWidth = false,
|
|
20
|
+
size = 'tiny',
|
|
21
|
+
exclusive = true,
|
|
22
|
+
}: ToggleControlProps< StringPropValue[ 'value' ] > ) => {
|
|
17
23
|
const { value, setValue } = useBoundProp( stringPropTypeUtil );
|
|
18
24
|
|
|
19
|
-
const
|
|
20
|
-
|
|
25
|
+
const exclusiveValues = options.filter( ( option ) => option.exclusive ).map( ( option ) => option.value );
|
|
26
|
+
|
|
27
|
+
const handleNonExclusiveToggle = ( selectedValues: StringPropValue[ 'value' ][] ) => {
|
|
28
|
+
const newSelectedValue = selectedValues[ selectedValues.length - 1 ];
|
|
29
|
+
const isNewSelectedValueExclusive = exclusiveValues.includes( newSelectedValue );
|
|
30
|
+
|
|
31
|
+
const updatedValues = isNewSelectedValueExclusive
|
|
32
|
+
? [ newSelectedValue ]
|
|
33
|
+
: selectedValues?.filter( ( val ) => ! exclusiveValues.includes( val ) );
|
|
34
|
+
|
|
35
|
+
setValue( updatedValues?.join( ' ' ) || null );
|
|
21
36
|
};
|
|
22
37
|
|
|
23
|
-
|
|
38
|
+
const toggleButtonGroupProps = {
|
|
39
|
+
items: options,
|
|
40
|
+
fullWidth,
|
|
41
|
+
size,
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
return exclusive ? (
|
|
24
45
|
<ControlToggleButtonGroup
|
|
25
|
-
|
|
46
|
+
{ ...toggleButtonGroupProps }
|
|
26
47
|
value={ value ?? null }
|
|
27
|
-
onChange={
|
|
48
|
+
onChange={ setValue }
|
|
28
49
|
exclusive={ true }
|
|
29
|
-
|
|
30
|
-
|
|
50
|
+
/>
|
|
51
|
+
) : (
|
|
52
|
+
<ControlToggleButtonGroup
|
|
53
|
+
{ ...toggleButtonGroupProps }
|
|
54
|
+
value={ value?.split( ' ' ) ?? [] }
|
|
55
|
+
onChange={ handleNonExclusiveToggle }
|
|
56
|
+
exclusive={ false }
|
|
31
57
|
/>
|
|
32
58
|
);
|
|
33
59
|
}
|
|
@@ -1,25 +1,24 @@
|
|
|
1
|
+
import { type FontCategory } from '@elementor/editor-controls';
|
|
2
|
+
|
|
1
3
|
export type FontListItem = {
|
|
2
4
|
type: 'font' | 'category';
|
|
3
5
|
value: string;
|
|
4
6
|
};
|
|
5
7
|
|
|
6
|
-
export const useFilteredFontFamilies = ( fontFamilies:
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
if ( filteredFonts.length ) {
|
|
12
|
-
acc.push( { type: 'category', value: category } );
|
|
8
|
+
export const useFilteredFontFamilies = ( fontFamilies: FontCategory[], searchValue: string ) => {
|
|
9
|
+
return fontFamilies.reduce< FontListItem[] >( ( acc, category ) => {
|
|
10
|
+
const filteredFonts = category.fonts.filter( ( font ) =>
|
|
11
|
+
font.toLowerCase().includes( searchValue.toLowerCase() )
|
|
12
|
+
);
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
} );
|
|
17
|
-
}
|
|
14
|
+
if ( filteredFonts.length ) {
|
|
15
|
+
acc.push( { type: 'category', value: category.label } );
|
|
18
16
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
17
|
+
filteredFonts.forEach( ( font ) => {
|
|
18
|
+
acc.push( { type: 'font', value: font } );
|
|
19
|
+
} );
|
|
20
|
+
}
|
|
23
21
|
|
|
24
|
-
|
|
22
|
+
return acc;
|
|
23
|
+
}, [] );
|
|
25
24
|
};
|
package/src/index.ts
CHANGED
|
@@ -30,6 +30,8 @@ export type { ControlActionsItems } from './control-actions/control-actions-cont
|
|
|
30
30
|
export type { PropProviderProps } from './bound-prop-context';
|
|
31
31
|
export type { SetValue } from './bound-prop-context/prop-context';
|
|
32
32
|
export type { ExtendedValue } from './controls/size-control';
|
|
33
|
+
export type { ToggleControlProps } from './controls/toggle-control';
|
|
34
|
+
export type { FontCategory } from './controls/font-family-control/font-family-control';
|
|
33
35
|
|
|
34
36
|
// providers
|
|
35
37
|
export { createControlReplacement, ControlReplacementProvider } from './create-control-replacement';
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { getContainer } from '@elementor/editor-elements';
|
|
2
|
+
|
|
3
|
+
type LinkRestriction =
|
|
4
|
+
| {
|
|
5
|
+
shouldRestrict: true;
|
|
6
|
+
restrictReason: 'ancestor' | 'descendant';
|
|
7
|
+
}
|
|
8
|
+
| {
|
|
9
|
+
shouldRestrict: false;
|
|
10
|
+
restrictReason?: never;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export function getLinkRestriction( elementId: string ): LinkRestriction {
|
|
14
|
+
if ( getAncestorAnchor( elementId ) ) {
|
|
15
|
+
return {
|
|
16
|
+
shouldRestrict: true,
|
|
17
|
+
restrictReason: 'ancestor',
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if ( getDescendantAnchor( elementId ) ) {
|
|
22
|
+
return {
|
|
23
|
+
shouldRestrict: true,
|
|
24
|
+
restrictReason: 'descendant',
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return { shouldRestrict: false };
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function getAncestorAnchor( elementId: string ) {
|
|
32
|
+
const element = getElementView( elementId );
|
|
33
|
+
|
|
34
|
+
return element?.closest( 'a' ) || null;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function getDescendantAnchor( elementId: string ) {
|
|
38
|
+
const element = getElementView( elementId );
|
|
39
|
+
|
|
40
|
+
return element?.querySelector( 'a' ) || null;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function getElementView( id: string ) {
|
|
44
|
+
const elementContainer = getContainer( id );
|
|
45
|
+
|
|
46
|
+
return elementContainer?.view?.el || null;
|
|
47
|
+
}
|