@elementor/editor-controls 4.0.0-manual → 4.0.1

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.
Files changed (39) hide show
  1. package/dist/index.d.mts +138 -64
  2. package/dist/index.d.ts +138 -64
  3. package/dist/index.js +905 -233
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.mjs +890 -225
  6. package/dist/index.mjs.map +1 -1
  7. package/package.json +15 -15
  8. package/src/components/inline-editor.tsx +16 -57
  9. package/src/components/promotions/attributes-control.tsx +2 -1
  10. package/src/components/promotions/display-conditions-control.tsx +2 -1
  11. package/src/components/promotions/promotion-trigger.tsx +14 -4
  12. package/src/controls/chips-control.tsx +1 -1
  13. package/src/controls/email-form-action-control.tsx +5 -5
  14. package/src/controls/number-control.tsx +8 -2
  15. package/src/controls/size-control/hooks/use-size-unit-keyboard.tsx +66 -0
  16. package/src/controls/size-control/hooks/use-size-value.ts +71 -0
  17. package/src/controls/size-control/size-component.tsx +94 -0
  18. package/src/controls/size-control/size-field.tsx +113 -0
  19. package/src/controls/size-control/sync/get-units.ts +17 -0
  20. package/src/controls/size-control/types.ts +17 -0
  21. package/src/controls/size-control/ui/size-input.tsx +68 -0
  22. package/src/controls/size-control/ui/text-field-popover.tsx +78 -0
  23. package/src/controls/size-control/ui/unit-selector.tsx +80 -0
  24. package/src/controls/size-control/unstable-size-control.tsx +86 -0
  25. package/src/controls/size-control/utils/has-size-value.ts +5 -0
  26. package/src/controls/size-control/utils/is-extended-unit.ts +8 -0
  27. package/src/controls/size-control/utils/resolve-bound-prop-value.ts +72 -0
  28. package/src/controls/size-control/utils/resolve-size-value.ts +85 -0
  29. package/src/controls/size-control/utils/settings/get-default-unit.ts +7 -0
  30. package/src/controls/size-control/utils/settings/get-prop-type-settings.ts +12 -0
  31. package/src/controls/size-control/utils/settings/get-size-units.ts +23 -0
  32. package/src/controls/size-control/utils/should-nullify-value.ts +15 -0
  33. package/src/controls/svg-media-control.tsx +5 -4
  34. package/src/controls/transition-control/data.ts +3 -3
  35. package/src/controls/transition-control/transition-repeater-control.tsx +8 -2
  36. package/src/controls/transition-control/transition-selector.tsx +7 -0
  37. package/src/hooks/use-font-families.ts +22 -25
  38. package/src/index.ts +4 -0
  39. package/src/utils/tracking.ts +61 -0
@@ -9,6 +9,7 @@ import { __ } from '@wordpress/i18n';
9
9
  import { useBoundProp } from '../../bound-prop-context';
10
10
  import { ItemSelector } from '../../components/item-selector';
11
11
  import ControlActions from '../../control-actions/control-actions';
12
+ import { trackUpgradePromotionClick } from '../../utils/tracking';
12
13
  import { transitionProperties, transitionsItemsList } from './data';
13
14
 
14
15
  const toTransitionSelectorValue = ( label: string ) => {
@@ -170,6 +171,12 @@ export const TransitionSelector = ( {
170
171
  'elementor'
171
172
  ) }
172
173
  upgradeUrl={ PRO_UPGRADE_URL }
174
+ onCtaClick={ () =>
175
+ trackUpgradePromotionClick( {
176
+ target_name: 'transition_property',
177
+ location_l2: 'style',
178
+ } )
179
+ }
173
180
  />
174
181
  ) : null
175
182
  }
@@ -1,52 +1,49 @@
1
1
  import { useMemo } from 'react';
2
- import { getElementorConfig, type SupportedFonts } from '@elementor/editor-v1-adapters';
3
- import { __ } from '@wordpress/i18n';
2
+ import { getElementorConfig } from '@elementor/editor-v1-adapters';
4
3
 
5
4
  import { type FontCategory } from '../controls/font-family-control/font-family-control';
6
5
 
7
- const supportedCategories: Record< SupportedFonts, string > = {
8
- system: __( 'System', 'elementor' ),
9
- custom: __( 'Custom Fonts', 'elementor' ),
10
- googlefonts: __( 'Google Fonts', 'elementor' ),
6
+ type FontControlConfig = {
7
+ groups?: Record< string, string >;
8
+ options?: Record< string, string >;
11
9
  };
12
10
 
13
- const getFontFamilies = () => {
11
+ const getFontControlConfig = (): FontControlConfig => {
14
12
  const { controls } = getElementorConfig();
15
13
 
16
- const options = controls?.font?.options;
17
-
18
- if ( ! options ) {
19
- return null;
20
- }
21
-
22
- return options;
14
+ return controls?.font ?? {};
23
15
  };
24
16
 
25
17
  export const useFontFamilies = () => {
26
- const fontFamilies = getFontFamilies();
18
+ const { groups, options } = getFontControlConfig();
27
19
 
28
20
  return useMemo( () => {
29
- const categoriesOrder: SupportedFonts[] = [ 'system', 'custom', 'googlefonts' ];
21
+ if ( ! groups || ! options ) {
22
+ return [];
23
+ }
24
+
25
+ const groupKeys = Object.keys( groups );
26
+ const groupIndexMap = new Map( groupKeys.map( ( key, index ) => [ key, index ] ) );
30
27
 
31
- return Object.entries( fontFamilies || {} )
28
+ return Object.entries( options )
32
29
  .reduce< FontCategory[] >( ( acc, [ font, category ] ) => {
33
- if ( ! supportedCategories[ category as SupportedFonts ] ) {
30
+ const groupIndex = groupIndexMap.get( category );
31
+
32
+ if ( groupIndex === undefined ) {
34
33
  return acc;
35
34
  }
36
35
 
37
- const categoryIndex = categoriesOrder.indexOf( category );
38
-
39
- if ( ! acc[ categoryIndex ] ) {
40
- acc[ categoryIndex ] = {
41
- label: supportedCategories[ category as SupportedFonts ],
36
+ if ( ! acc[ groupIndex ] ) {
37
+ acc[ groupIndex ] = {
38
+ label: groups[ category ],
42
39
  fonts: [],
43
40
  };
44
41
  }
45
42
 
46
- acc[ categoryIndex ].fonts.push( font );
43
+ acc[ groupIndex ].fonts.push( font );
47
44
 
48
45
  return acc;
49
46
  }, [] )
50
47
  .filter( Boolean );
51
- }, [ fontFamilies ] );
48
+ }, [ groups, options ] );
52
49
  };
package/src/index.ts CHANGED
@@ -38,6 +38,7 @@ export { transitionProperties, transitionsItemsList } from './controls/transitio
38
38
  export { DateTimeControl } from './controls/date-time-control';
39
39
  export { InlineEditingControl } from './controls/inline-editing-control';
40
40
  export { EmailFormActionControl } from './controls/email-form-action-control';
41
+ export { UnstableSizeControl } from './controls/size-control/unstable-size-control';
41
42
 
42
43
  // components
43
44
  export { ControlFormLabel } from './components/control-form-label';
@@ -58,6 +59,7 @@ export { InlineEditor } from './components/inline-editor';
58
59
  export { InlineEditorToolbar } from './components/inline-editor-toolbar';
59
60
  export { UnstableSizeField } from './components/size/unstable-size-field';
60
61
  export { NumberInput } from './components/number-input';
62
+ export { SizeComponent } from './controls/size-control/size-component';
61
63
 
62
64
  // types
63
65
  export type { ControlComponent } from './create-control';
@@ -80,6 +82,8 @@ export type { FontCategory } from './controls/font-family-control/font-family-co
80
82
  export type { InlineEditorToolbarProps } from './components/inline-editor-toolbar';
81
83
  export type { V4PromotionData, V4PromotionKey } from './components/promotions/types';
82
84
  export type { PromotionTriggerRef } from './components/promotions/promotion-trigger';
85
+ export { trackViewPromotion, trackUpgradePromotionClick } from './utils/tracking';
86
+ export type { PromotionTrackingData } from './utils/tracking';
83
87
 
84
88
  // providers
85
89
  export {
@@ -0,0 +1,61 @@
1
+ import { getSelectedElements } from '@elementor/editor-elements';
2
+ import { getMixpanel } from '@elementor/events';
3
+
4
+ export type PromotionTrackingData = {
5
+ target_name: string;
6
+ target_location?: 'widget_panel' | 'variables_manager';
7
+ location_l1?: string;
8
+ location_l2?: 'style' | 'general' | 'interactions';
9
+ };
10
+
11
+ type PromotionEventOptions = {
12
+ eventName: string | undefined;
13
+ interactionResult: string;
14
+ interactionDescription: string;
15
+ };
16
+
17
+ type MixpanelConfig = ReturnType< typeof getMixpanel >[ 'config' ];
18
+
19
+ const getBaseEventProperties = ( data: PromotionTrackingData, config: MixpanelConfig ) => ( {
20
+ app_type: config?.appTypes?.editor ?? 'editor',
21
+ window_name: config?.appTypes?.editor ?? 'editor',
22
+ interaction_type: config?.triggers?.click ?? 'Click',
23
+ target_name: data.target_name,
24
+ target_location: data.target_location ?? 'widget_panel',
25
+ location_l1: data.location_l1 ?? getSelectedElements()[ 0 ]?.type ?? '',
26
+ ...( data.location_l2 && { location_l2: data.location_l2 } ),
27
+ } );
28
+
29
+ const dispatchPromotionEvent = (
30
+ data: PromotionTrackingData,
31
+ resolveOptions: ( config: MixpanelConfig ) => PromotionEventOptions
32
+ ) => {
33
+ const { dispatchEvent, config } = getMixpanel();
34
+ const { eventName, interactionResult, interactionDescription } = resolveOptions( config );
35
+
36
+ if ( ! eventName ) {
37
+ return;
38
+ }
39
+
40
+ dispatchEvent?.( eventName, {
41
+ ...getBaseEventProperties( data, config ),
42
+ interaction_result: interactionResult,
43
+ interaction_description: interactionDescription,
44
+ } );
45
+ };
46
+
47
+ export const trackViewPromotion = ( data: PromotionTrackingData ) => {
48
+ dispatchPromotionEvent( data, ( config ) => ( {
49
+ eventName: config?.names?.promotions?.viewPromotion,
50
+ interactionResult: config?.interactionResults?.promotionViewed ?? 'promotion_viewed',
51
+ interactionDescription: 'user_viewed_promotion',
52
+ } ) );
53
+ };
54
+
55
+ export const trackUpgradePromotionClick = ( data: PromotionTrackingData ) => {
56
+ dispatchPromotionEvent( data, ( config ) => ( {
57
+ eventName: config?.names?.promotions?.upgradePromotionClick,
58
+ interactionResult: config?.interactionResults?.upgradeNow ?? 'upgrade_now',
59
+ interactionDescription: 'user_clicked_upgrade_now',
60
+ } ) );
61
+ };