@elementor/editor-controls 4.4.0-1085 → 4.4.0-1087

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@elementor/editor-controls",
3
3
  "description": "This package contains the controls model and utils for the Elementor editor",
4
- "version": "4.4.0-1085",
4
+ "version": "4.4.0-1087",
5
5
  "private": false,
6
6
  "author": "Elementor Team",
7
7
  "homepage": "https://elementor.com/",
@@ -40,23 +40,23 @@
40
40
  "dev": "tsup --config=../../tsup.dev.ts"
41
41
  },
42
42
  "dependencies": {
43
- "@elementor/editor-current-user": "4.4.0-1085",
44
- "@elementor/editor-elements": "4.4.0-1085",
45
- "@elementor/editor-props": "4.4.0-1085",
46
- "@elementor/editor-responsive": "4.4.0-1085",
47
- "@elementor/editor-ui": "4.4.0-1085",
48
- "@elementor/editor-v1-adapters": "4.4.0-1085",
49
- "@elementor/env": "4.4.0-1085",
50
- "@elementor/events": "4.4.0-1085",
51
- "@elementor/http-client": "4.4.0-1085",
43
+ "@elementor/editor-current-user": "4.4.0-1087",
44
+ "@elementor/editor-elements": "4.4.0-1087",
45
+ "@elementor/editor-props": "4.4.0-1087",
46
+ "@elementor/editor-responsive": "4.4.0-1087",
47
+ "@elementor/editor-ui": "4.4.0-1087",
48
+ "@elementor/editor-v1-adapters": "4.4.0-1087",
49
+ "@elementor/env": "4.4.0-1087",
50
+ "@elementor/events": "4.4.0-1087",
51
+ "@elementor/http-client": "4.4.0-1087",
52
52
  "@elementor/icons": "~1.75.1",
53
- "@elementor/locations": "4.4.0-1085",
54
- "@elementor/query": "4.4.0-1085",
55
- "@elementor/schema": "4.4.0-1085",
56
- "@elementor/session": "4.4.0-1085",
53
+ "@elementor/locations": "4.4.0-1087",
54
+ "@elementor/query": "4.4.0-1087",
55
+ "@elementor/schema": "4.4.0-1087",
56
+ "@elementor/session": "4.4.0-1087",
57
57
  "@elementor/ui": "1.37.5",
58
- "@elementor/utils": "4.4.0-1085",
59
- "@elementor/wp-media": "4.4.0-1085",
58
+ "@elementor/utils": "4.4.0-1087",
59
+ "@elementor/wp-media": "4.4.0-1087",
60
60
  "@monaco-editor/react": "^4.7.0",
61
61
  "@tiptap/extension-bold": "^3.11.1",
62
62
  "@tiptap/extension-document": "^3.11.1",
@@ -0,0 +1,105 @@
1
+ import * as React from 'react';
2
+ import { useState } from 'react';
3
+ import { ajax } from '@elementor/editor-v1-adapters';
4
+ import { BulbIcon } from '@elementor/icons';
5
+ import { Alert, AlertAction, type AlertProps, AlertTitle, styled, Typography } from '@elementor/ui';
6
+
7
+ import { createControl } from '../create-control';
8
+
9
+ type NoticeType = 'info' | 'success' | 'warning' | 'danger';
10
+
11
+ // Elementor's `Alert` forces `.MuiAlertTitle-root { marginBottom: 0 }` via a selector scoped to the
12
+ // Alert's own class. Repeating the `.MuiAlertTitle-root` class here matches that selector's specificity
13
+ // so this override applies reliably regardless of stylesheet insertion order.
14
+ const NoticeTitle = styled( AlertTitle )( {
15
+ '&.MuiAlertTitle-root.MuiAlertTitle-root': {
16
+ marginBottom: 4,
17
+ fontStyle: 'italic',
18
+ },
19
+ } );
20
+
21
+ type NoticeControlProps = {
22
+ noticeType?: NoticeType;
23
+ heading?: string;
24
+ content?: string;
25
+ dismissible?: string;
26
+ buttonText?: string;
27
+ buttonUrl?: string;
28
+ };
29
+
30
+ type ExtendedWindow = Window & {
31
+ elementor?: {
32
+ config?: {
33
+ user?: {
34
+ dismissed_editor_notices?: string[];
35
+ };
36
+ };
37
+ };
38
+ };
39
+
40
+ const markNoticeAsDismissedInSession = ( dismissId: string ) => {
41
+ const dismissedNotices = ( window as ExtendedWindow ).elementor?.config?.user?.dismissed_editor_notices;
42
+
43
+ if ( dismissedNotices && ! dismissedNotices.includes( dismissId ) ) {
44
+ dismissedNotices.push( dismissId );
45
+ }
46
+ };
47
+
48
+ export const NoticeControl = createControl(
49
+ ( { noticeType = 'info', heading, content, dismissible, buttonText, buttonUrl }: NoticeControlProps ) => {
50
+ const [ isDismissed, setIsDismissed ] = useState( false );
51
+
52
+ if ( isDismissed || ! content ) {
53
+ return null;
54
+ }
55
+
56
+ const severity: AlertProps[ 'severity' ] = noticeType === 'danger' ? 'error' : noticeType;
57
+ const icon = noticeType === 'info' ? <BulbIcon fontSize="inherit" /> : undefined;
58
+
59
+ const handleDismiss = () => {
60
+ setIsDismissed( true );
61
+
62
+ if ( ! dismissible ) {
63
+ return;
64
+ }
65
+
66
+ markNoticeAsDismissedInSession( dismissible );
67
+
68
+ ajax.load( {
69
+ action: 'dismissed_editor_notices',
70
+ unique_id: `dismiss-editor-notice-${ dismissible }`,
71
+ data: { dismissId: dismissible },
72
+ } ).catch( () => {} );
73
+ };
74
+
75
+ const handleActionClick = () => {
76
+ setIsDismissed( true );
77
+
78
+ if ( dismissible ) {
79
+ markNoticeAsDismissedInSession( dismissible );
80
+ }
81
+ };
82
+
83
+ return (
84
+ <Alert variant="outlined" severity={ severity } icon={ icon } size="small" onClose={ handleDismiss }>
85
+ { heading && <NoticeTitle>{ heading }</NoticeTitle> }
86
+ <Typography variant="caption" color="textSecondary" sx={ { fontStyle: 'italic' } }>
87
+ { content }
88
+ </Typography>
89
+ { buttonText && buttonUrl && (
90
+ <AlertAction
91
+ variant="contained"
92
+ color={ severity }
93
+ target="_blank"
94
+ rel="noopener noreferrer"
95
+ href={ buttonUrl }
96
+ onClick={ handleActionClick }
97
+ sx={ { mt: 2 } }
98
+ >
99
+ { buttonText }
100
+ </AlertAction>
101
+ ) }
102
+ </Alert>
103
+ );
104
+ }
105
+ );
package/src/index.ts CHANGED
@@ -51,6 +51,7 @@ export { TimeRangeControl } from './controls/time-range-control';
51
51
  export { InlineEditingControl } from './controls/inline-editing-control';
52
52
  export { EmailFormActionControl } from './controls/email-form-action-control';
53
53
  export { AttachmentTypeControl } from './controls/attachment-type-control';
54
+ export { NoticeControl } from './controls/notice-control';
54
55
  export { UnstableSizeControl } from './controls/size-control/unstable-size-control';
55
56
  export { GridSpanControl } from './controls/grid-span-control';
56
57