@wordpress/customize-widgets 4.15.0 → 4.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 +4 -0
- package/build/components/block-appender/index.js +6 -8
- package/build/components/block-appender/index.js.map +1 -1
- package/build/components/block-inspector-button/index.js +3 -9
- package/build/components/block-inspector-button/index.js.map +1 -1
- package/build/components/customize-widgets/index.js +4 -12
- package/build/components/customize-widgets/index.js.map +1 -1
- package/build/components/customize-widgets/use-clear-selected-block.js +12 -15
- package/build/components/customize-widgets/use-clear-selected-block.js.map +1 -1
- package/build/components/error-boundary/index.js +1 -14
- package/build/components/error-boundary/index.js.map +1 -1
- package/build/components/focus-control/index.js +1 -12
- package/build/components/focus-control/index.js.map +1 -1
- package/build/components/focus-control/use-blocks-focus-control.js +3 -9
- package/build/components/focus-control/use-blocks-focus-control.js.map +1 -1
- package/build/components/header/index.js +7 -18
- package/build/components/header/index.js.map +1 -1
- package/build/components/inserter/index.js +1 -10
- package/build/components/inserter/index.js.map +1 -1
- package/build/components/inserter/use-inserter.js +1 -6
- package/build/components/inserter/use-inserter.js.map +1 -1
- package/build/components/keyboard-shortcut-help-modal/config.js +1 -2
- package/build/components/keyboard-shortcut-help-modal/config.js.map +1 -1
- package/build/components/keyboard-shortcut-help-modal/dynamic-shortcut.js +1 -9
- package/build/components/keyboard-shortcut-help-modal/dynamic-shortcut.js.map +1 -1
- package/build/components/keyboard-shortcut-help-modal/index.js +4 -20
- package/build/components/keyboard-shortcut-help-modal/index.js.map +1 -1
- package/build/components/keyboard-shortcut-help-modal/shortcut.js +1 -6
- package/build/components/keyboard-shortcut-help-modal/shortcut.js.map +1 -1
- package/build/components/keyboard-shortcuts/index.js +1 -16
- package/build/components/keyboard-shortcuts/index.js.map +1 -1
- package/build/components/more-menu/index.js +2 -15
- package/build/components/more-menu/index.js.map +1 -1
- package/build/components/sidebar-block-editor/index.js +5 -22
- package/build/components/sidebar-block-editor/index.js.map +1 -1
- package/build/components/sidebar-block-editor/sidebar-adapter.js +13 -75
- package/build/components/sidebar-block-editor/sidebar-adapter.js.map +1 -1
- package/build/components/sidebar-block-editor/sidebar-editor-provider.js +1 -8
- package/build/components/sidebar-block-editor/sidebar-editor-provider.js.map +1 -1
- package/build/components/sidebar-block-editor/use-sidebar-block-editor.js +14 -24
- package/build/components/sidebar-block-editor/use-sidebar-block-editor.js.map +1 -1
- package/build/components/sidebar-controls/index.js +1 -5
- package/build/components/sidebar-controls/index.js.map +1 -1
- package/build/components/welcome-guide/index.js +1 -6
- package/build/components/welcome-guide/index.js.map +1 -1
- package/build/controls/inserter-outer-section.js +15 -24
- package/build/controls/inserter-outer-section.js.map +1 -1
- package/build/controls/inspector-section.js +0 -12
- package/build/controls/inspector-section.js.map +1 -1
- package/build/controls/sidebar-control.js +1 -12
- package/build/controls/sidebar-control.js.map +1 -1
- package/build/controls/sidebar-section.js +3 -14
- package/build/controls/sidebar-section.js.map +1 -1
- package/build/filters/index.js +0 -2
- package/build/filters/index.js.map +1 -1
- package/build/filters/move-to-sidebar.js +7 -17
- package/build/filters/move-to-sidebar.js.map +1 -1
- package/build/filters/replace-media-upload.js +1 -3
- package/build/filters/replace-media-upload.js.map +1 -1
- package/build/filters/wide-widget-display.js +3 -5
- package/build/filters/wide-widget-display.js.map +1 -1
- package/build/index.js +5 -20
- package/build/index.js.map +1 -1
- package/build/lock-unlock.js +1 -2
- package/build/lock-unlock.js.map +1 -1
- package/build/store/actions.js +0 -1
- package/build/store/actions.js.map +1 -1
- package/build/store/constants.js +0 -1
- package/build/store/constants.js.map +1 -1
- package/build/store/index.js +1 -10
- package/build/store/index.js.map +1 -1
- package/build/store/reducer.js +0 -5
- package/build/store/reducer.js.map +1 -1
- package/build/store/selectors.js +9 -10
- package/build/store/selectors.js.map +1 -1
- package/build/utils.js +8 -18
- package/build/utils.js.map +1 -1
- package/build-module/components/block-appender/index.js +5 -5
- package/build-module/components/block-appender/index.js.map +1 -1
- package/build-module/components/block-inspector-button/index.js +2 -5
- package/build-module/components/block-inspector-button/index.js.map +1 -1
- package/build-module/components/customize-widgets/index.js +4 -4
- package/build-module/components/customize-widgets/index.js.map +1 -1
- package/build-module/components/customize-widgets/use-clear-selected-block.js +13 -12
- package/build-module/components/customize-widgets/use-clear-selected-block.js.map +1 -1
- package/build-module/components/error-boundary/index.js +0 -8
- package/build-module/components/error-boundary/index.js.map +1 -1
- package/build-module/components/focus-control/index.js +1 -8
- package/build-module/components/focus-control/index.js.map +1 -1
- package/build-module/components/focus-control/use-blocks-focus-control.js +3 -4
- package/build-module/components/focus-control/use-blocks-focus-control.js.map +1 -1
- package/build-module/components/header/index.js +8 -11
- package/build-module/components/header/index.js.map +1 -1
- package/build-module/components/inserter/index.js +1 -4
- package/build-module/components/inserter/index.js.map +1 -1
- package/build-module/components/inserter/use-inserter.js +1 -3
- package/build-module/components/inserter/use-inserter.js.map +1 -1
- package/build-module/components/keyboard-shortcut-help-modal/config.js.map +1 -1
- package/build-module/components/keyboard-shortcut-help-modal/dynamic-shortcut.js +1 -6
- package/build-module/components/keyboard-shortcut-help-modal/dynamic-shortcut.js.map +1 -1
- package/build-module/components/keyboard-shortcut-help-modal/index.js +5 -13
- package/build-module/components/keyboard-shortcut-help-modal/index.js.map +1 -1
- package/build-module/components/keyboard-shortcut-help-modal/shortcut.js +0 -5
- package/build-module/components/keyboard-shortcut-help-modal/shortcut.js.map +1 -1
- package/build-module/components/keyboard-shortcuts/index.js +0 -9
- package/build-module/components/keyboard-shortcuts/index.js.map +1 -1
- package/build-module/components/more-menu/index.js +2 -6
- package/build-module/components/more-menu/index.js.map +1 -1
- package/build-module/components/sidebar-block-editor/index.js +5 -9
- package/build-module/components/sidebar-block-editor/index.js.map +1 -1
- package/build-module/components/sidebar-block-editor/sidebar-adapter.js +12 -72
- package/build-module/components/sidebar-block-editor/sidebar-adapter.js.map +1 -1
- package/build-module/components/sidebar-block-editor/sidebar-editor-provider.js +1 -2
- package/build-module/components/sidebar-block-editor/sidebar-editor-provider.js.map +1 -1
- package/build-module/components/sidebar-block-editor/use-sidebar-block-editor.js +15 -20
- package/build-module/components/sidebar-block-editor/use-sidebar-block-editor.js.map +1 -1
- package/build-module/components/sidebar-controls/index.js +0 -1
- package/build-module/components/sidebar-controls/index.js.map +1 -1
- package/build-module/components/welcome-guide/index.js +0 -1
- package/build-module/components/welcome-guide/index.js.map +1 -1
- package/build-module/controls/inserter-outer-section.js +15 -20
- package/build-module/controls/inserter-outer-section.js.map +1 -1
- package/build-module/controls/inspector-section.js +0 -11
- package/build-module/controls/inspector-section.js.map +1 -1
- package/build-module/controls/sidebar-control.js +1 -8
- package/build-module/controls/sidebar-control.js.map +1 -1
- package/build-module/controls/sidebar-section.js +3 -12
- package/build-module/controls/sidebar-section.js.map +1 -1
- package/build-module/filters/index.js.map +1 -1
- package/build-module/filters/move-to-sidebar.js +7 -10
- package/build-module/filters/move-to-sidebar.js.map +1 -1
- package/build-module/filters/replace-media-upload.js +0 -2
- package/build-module/filters/replace-media-upload.js.map +1 -1
- package/build-module/filters/wide-widget-display.js +2 -3
- package/build-module/filters/wide-widget-display.js.map +1 -1
- package/build-module/index.js +5 -10
- package/build-module/index.js.map +1 -1
- package/build-module/lock-unlock.js.map +1 -1
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/constants.js.map +1 -1
- package/build-module/store/index.js +3 -3
- package/build-module/store/index.js.map +1 -1
- package/build-module/store/reducer.js +1 -3
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/selectors.js +10 -9
- package/build-module/store/selectors.js.map +1 -1
- package/build-module/utils.js +9 -14
- package/build-module/utils.js.map +1 -1
- package/package.json +22 -22
- package/src/store/selectors.js +10 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["store","coreStore","useSelect","useMemo","createPortal","BlockList","BlockTools","BlockSelectionClearer","BlockInspector","CopyHandler","ObserveTyping","WritingFlow","BlockEditorKeyboardShortcuts","__unstableBlockSettingsMenuFirstItem","__unstableEditorStyles","EditorStyles","uploadMedia","preferencesStore","BlockInspectorButton","Header","useInserter","SidebarEditorProvider","WelcomeGuide","KeyboardShortcuts","BlockAppender","SidebarBlockEditor","blockEditorSettings","sidebar","inserter","inspector","isInserterOpened","setIsInserterOpened","hasUploadPermissions","isFixedToolbarActive","keepCaretInsideBlock","isWelcomeGuideActive","select","_select$canUser","get","canUser","settings","mediaUploadBlockEditor","onError","argumentsObject","wpAllowedMimeTypes","allowedMimeTypes","message","__experimentalSetIsInserterOpened","mediaUpload","hasFixedToolbar","__unstableHasCustomAppender","createElement","Fragment","Register","undo","redo","save","styles","defaultEditorStyles","className","renderAppender","onSubmit","event","preventDefault","contentContainer","onClose","closeMenu"],"sources":["@wordpress/customize-widgets/src/components/sidebar-block-editor/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { store as coreStore } from '@wordpress/core-data';\nimport { useSelect } from '@wordpress/data';\nimport { useMemo, createPortal } from '@wordpress/element';\nimport {\n\tBlockList,\n\tBlockTools,\n\tBlockSelectionClearer,\n\tBlockInspector,\n\tCopyHandler,\n\tObserveTyping,\n\tWritingFlow,\n\tBlockEditorKeyboardShortcuts,\n\t__unstableBlockSettingsMenuFirstItem,\n\t__unstableEditorStyles as EditorStyles,\n} from '@wordpress/block-editor';\nimport { uploadMedia } from '@wordpress/media-utils';\nimport { store as preferencesStore } from '@wordpress/preferences';\n\n/**\n * Internal dependencies\n */\nimport BlockInspectorButton from '../block-inspector-button';\nimport Header from '../header';\nimport useInserter from '../inserter/use-inserter';\nimport SidebarEditorProvider from './sidebar-editor-provider';\nimport WelcomeGuide from '../welcome-guide';\nimport KeyboardShortcuts from '../keyboard-shortcuts';\nimport BlockAppender from '../block-appender';\n\nexport default function SidebarBlockEditor( {\n\tblockEditorSettings,\n\tsidebar,\n\tinserter,\n\tinspector,\n} ) {\n\tconst [ isInserterOpened, setIsInserterOpened ] = useInserter( inserter );\n\tconst {\n\t\thasUploadPermissions,\n\t\tisFixedToolbarActive,\n\t\tkeepCaretInsideBlock,\n\t\tisWelcomeGuideActive,\n\t} = useSelect( ( select ) => {\n\t\tconst { get } = select( preferencesStore );\n\t\treturn {\n\t\t\thasUploadPermissions:\n\t\t\t\tselect( coreStore ).canUser( 'create', 'media' ) ?? true,\n\t\t\tisFixedToolbarActive: !! get(\n\t\t\t\t'core/customize-widgets',\n\t\t\t\t'fixedToolbar'\n\t\t\t),\n\t\t\tkeepCaretInsideBlock: !! get(\n\t\t\t\t'core/customize-widgets',\n\t\t\t\t'keepCaretInsideBlock'\n\t\t\t),\n\t\t\tisWelcomeGuideActive: !! get(\n\t\t\t\t'core/customize-widgets',\n\t\t\t\t'welcomeGuide'\n\t\t\t),\n\t\t};\n\t}, [] );\n\tconst settings = useMemo( () => {\n\t\tlet mediaUploadBlockEditor;\n\t\tif ( hasUploadPermissions ) {\n\t\t\tmediaUploadBlockEditor = ( { onError, ...argumentsObject } ) => {\n\t\t\t\tuploadMedia( {\n\t\t\t\t\twpAllowedMimeTypes: blockEditorSettings.allowedMimeTypes,\n\t\t\t\t\tonError: ( { message } ) => onError( message ),\n\t\t\t\t\t...argumentsObject,\n\t\t\t\t} );\n\t\t\t};\n\t\t}\n\n\t\treturn {\n\t\t\t...blockEditorSettings,\n\t\t\t__experimentalSetIsInserterOpened: setIsInserterOpened,\n\t\t\tmediaUpload: mediaUploadBlockEditor,\n\t\t\thasFixedToolbar: isFixedToolbarActive,\n\t\t\tkeepCaretInsideBlock,\n\t\t\t__unstableHasCustomAppender: true,\n\t\t};\n\t}, [\n\t\thasUploadPermissions,\n\t\tblockEditorSettings,\n\t\tisFixedToolbarActive,\n\t\tkeepCaretInsideBlock,\n\t\tsetIsInserterOpened,\n\t] );\n\n\tif ( isWelcomeGuideActive ) {\n\t\treturn <WelcomeGuide sidebar={ sidebar } />;\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t<BlockEditorKeyboardShortcuts.Register />\n\t\t\t<KeyboardShortcuts.Register />\n\n\t\t\t<SidebarEditorProvider sidebar={ sidebar } settings={ settings }>\n\t\t\t\t<KeyboardShortcuts\n\t\t\t\t\tundo={ sidebar.undo }\n\t\t\t\t\tredo={ sidebar.redo }\n\t\t\t\t\tsave={ sidebar.save }\n\t\t\t\t/>\n\n\t\t\t\t<Header\n\t\t\t\t\tsidebar={ sidebar }\n\t\t\t\t\tinserter={ inserter }\n\t\t\t\t\tisInserterOpened={ isInserterOpened }\n\t\t\t\t\tsetIsInserterOpened={ setIsInserterOpened }\n\t\t\t\t\tisFixedToolbarActive={ isFixedToolbarActive }\n\t\t\t\t/>\n\n\t\t\t\t<CopyHandler>\n\t\t\t\t\t<BlockTools>\n\t\t\t\t\t\t<EditorStyles styles={ settings.defaultEditorStyles } />\n\t\t\t\t\t\t<BlockSelectionClearer>\n\t\t\t\t\t\t\t<WritingFlow className=\"editor-styles-wrapper\">\n\t\t\t\t\t\t\t\t<ObserveTyping>\n\t\t\t\t\t\t\t\t\t<BlockList\n\t\t\t\t\t\t\t\t\t\trenderAppender={ BlockAppender }\n\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t</ObserveTyping>\n\t\t\t\t\t\t\t</WritingFlow>\n\t\t\t\t\t\t</BlockSelectionClearer>\n\t\t\t\t\t</BlockTools>\n\t\t\t\t</CopyHandler>\n\n\t\t\t\t{ createPortal(\n\t\t\t\t\t// This is a temporary hack to prevent button component inside <BlockInspector>\n\t\t\t\t\t// from submitting form when type=\"button\" is not specified.\n\t\t\t\t\t<form onSubmit={ ( event ) => event.preventDefault() }>\n\t\t\t\t\t\t<BlockInspector />\n\t\t\t\t\t</form>,\n\t\t\t\t\tinspector.contentContainer[ 0 ]\n\t\t\t\t) }\n\t\t\t</SidebarEditorProvider>\n\n\t\t\t<__unstableBlockSettingsMenuFirstItem>\n\t\t\t\t{ ( { onClose } ) => (\n\t\t\t\t\t<BlockInspectorButton\n\t\t\t\t\t\tinspector={ inspector }\n\t\t\t\t\t\tcloseM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';
|
|
|
5
5
|
const {
|
|
6
6
|
wp
|
|
7
7
|
} = window;
|
|
8
|
-
|
|
9
8
|
function parseWidgetId(widgetId) {
|
|
10
9
|
const matches = widgetId.match(/^(.+)-(\d+)$/);
|
|
11
|
-
|
|
12
10
|
if (matches) {
|
|
13
11
|
return {
|
|
14
12
|
idBase: matches[1],
|
|
15
13
|
number: parseInt(matches[2], 10)
|
|
16
14
|
};
|
|
17
|
-
}
|
|
18
|
-
|
|
15
|
+
}
|
|
19
16
|
|
|
17
|
+
// Likely an old single widget.
|
|
20
18
|
return {
|
|
21
19
|
idBase: widgetId
|
|
22
20
|
};
|
|
23
21
|
}
|
|
24
|
-
|
|
25
22
|
function widgetIdToSettingId(widgetId) {
|
|
26
23
|
const {
|
|
27
24
|
idBase,
|
|
28
25
|
number
|
|
29
26
|
} = parseWidgetId(widgetId);
|
|
30
|
-
|
|
31
27
|
if (number) {
|
|
32
28
|
return `widget_${idBase}[${number}]`;
|
|
33
29
|
}
|
|
34
|
-
|
|
35
30
|
return `widget_${idBase}`;
|
|
36
31
|
}
|
|
32
|
+
|
|
37
33
|
/**
|
|
38
34
|
* This is a custom debounce function to call different callbacks depending on
|
|
39
35
|
* whether it's the _leading_ call or not.
|
|
@@ -43,12 +39,9 @@ function widgetIdToSettingId(widgetId) {
|
|
|
43
39
|
* @param {number} timeout The debounced time in milliseconds.
|
|
44
40
|
* @return {Function} The debounced function.
|
|
45
41
|
*/
|
|
46
|
-
|
|
47
|
-
|
|
48
42
|
function debounce(leading, callback, timeout) {
|
|
49
43
|
let isLeading = false;
|
|
50
44
|
let timerID;
|
|
51
|
-
|
|
52
45
|
function debounced(...args) {
|
|
53
46
|
const result = (isLeading ? callback : leading).apply(this, args);
|
|
54
47
|
isLeading = true;
|
|
@@ -58,15 +51,12 @@ function debounce(leading, callback, timeout) {
|
|
|
58
51
|
}, timeout);
|
|
59
52
|
return result;
|
|
60
53
|
}
|
|
61
|
-
|
|
62
54
|
debounced.cancel = () => {
|
|
63
55
|
isLeading = false;
|
|
64
56
|
clearTimeout(timerID);
|
|
65
57
|
};
|
|
66
|
-
|
|
67
58
|
return debounced;
|
|
68
59
|
}
|
|
69
|
-
|
|
70
60
|
export default class SidebarAdapter {
|
|
71
61
|
constructor(setting, api) {
|
|
72
62
|
this.setting = setting;
|
|
@@ -76,8 +66,8 @@ export default class SidebarAdapter {
|
|
|
76
66
|
this.subscribers = new Set();
|
|
77
67
|
this.history = [this._getWidgetIds().map(widgetId => this.getWidget(widgetId))];
|
|
78
68
|
this.historyIndex = 0;
|
|
79
|
-
this.historySubscribers = new Set();
|
|
80
|
-
|
|
69
|
+
this.historySubscribers = new Set();
|
|
70
|
+
// Debounce the input for 1 second.
|
|
81
71
|
this._debounceSetHistory = debounce(this._pushHistory, this._replaceHistory, 1000);
|
|
82
72
|
this.setting.bind(this._handleSettingChange.bind(this));
|
|
83
73
|
this.api.bind('change', this._handleAllSettingsChange.bind(this));
|
|
@@ -85,83 +75,63 @@ export default class SidebarAdapter {
|
|
|
85
75
|
this.redo = this.redo.bind(this);
|
|
86
76
|
this.save = this.save.bind(this);
|
|
87
77
|
}
|
|
88
|
-
|
|
89
78
|
subscribe(callback) {
|
|
90
79
|
this.subscribers.add(callback);
|
|
91
80
|
return () => {
|
|
92
81
|
this.subscribers.delete(callback);
|
|
93
82
|
};
|
|
94
83
|
}
|
|
95
|
-
|
|
96
84
|
getWidgets() {
|
|
97
85
|
return this.history[this.historyIndex];
|
|
98
86
|
}
|
|
99
|
-
|
|
100
87
|
_emit(...args) {
|
|
101
88
|
for (const callback of this.subscribers) {
|
|
102
89
|
callback(...args);
|
|
103
90
|
}
|
|
104
91
|
}
|
|
105
|
-
|
|
106
92
|
_getWidgetIds() {
|
|
107
93
|
return this.setting.get();
|
|
108
94
|
}
|
|
109
|
-
|
|
110
95
|
_pushHistory() {
|
|
111
96
|
this.history = [...this.history.slice(0, this.historyIndex + 1), this._getWidgetIds().map(widgetId => this.getWidget(widgetId))];
|
|
112
97
|
this.historyIndex += 1;
|
|
113
98
|
this.historySubscribers.forEach(listener => listener());
|
|
114
99
|
}
|
|
115
|
-
|
|
116
100
|
_replaceHistory() {
|
|
117
101
|
this.history[this.historyIndex] = this._getWidgetIds().map(widgetId => this.getWidget(widgetId));
|
|
118
102
|
}
|
|
119
|
-
|
|
120
103
|
_handleSettingChange() {
|
|
121
104
|
if (this.locked) {
|
|
122
105
|
return;
|
|
123
106
|
}
|
|
124
|
-
|
|
125
107
|
const prevWidgets = this.getWidgets();
|
|
126
|
-
|
|
127
108
|
this._pushHistory();
|
|
128
|
-
|
|
129
109
|
this._emit(prevWidgets, this.getWidgets());
|
|
130
110
|
}
|
|
131
|
-
|
|
132
111
|
_handleAllSettingsChange(setting) {
|
|
133
112
|
if (this.locked) {
|
|
134
113
|
return;
|
|
135
114
|
}
|
|
136
|
-
|
|
137
115
|
if (!setting.id.startsWith('widget_')) {
|
|
138
116
|
return;
|
|
139
117
|
}
|
|
140
|
-
|
|
141
118
|
const widgetId = settingIdToWidgetId(setting.id);
|
|
142
|
-
|
|
143
119
|
if (!this.setting.get().includes(widgetId)) {
|
|
144
120
|
return;
|
|
145
121
|
}
|
|
146
|
-
|
|
147
122
|
const prevWidgets = this.getWidgets();
|
|
148
|
-
|
|
149
123
|
this._pushHistory();
|
|
150
|
-
|
|
151
124
|
this._emit(prevWidgets, this.getWidgets());
|
|
152
125
|
}
|
|
153
|
-
|
|
154
126
|
_createWidget(widget) {
|
|
155
127
|
const widgetModel = wp.customize.Widgets.availableWidgets.findWhere({
|
|
156
128
|
id_base: widget.idBase
|
|
157
129
|
});
|
|
158
130
|
let number = widget.number;
|
|
159
|
-
|
|
160
131
|
if (widgetModel.get('is_multi') && !number) {
|
|
161
132
|
widgetModel.set('multi_number', widgetModel.get('multi_number') + 1);
|
|
162
133
|
number = widgetModel.get('multi_number');
|
|
163
134
|
}
|
|
164
|
-
|
|
165
135
|
const settingId = number ? `widget_${widget.idBase}[${number}]` : `widget_${widget.idBase}`;
|
|
166
136
|
const settingArgs = {
|
|
167
137
|
transport: wp.customize.Widgets.data.selectiveRefreshableWidgets[widgetModel.get('id_base')] ? 'postMessage' : 'refresh',
|
|
@@ -172,61 +142,51 @@ export default class SidebarAdapter {
|
|
|
172
142
|
const widgetId = settingIdToWidgetId(settingId);
|
|
173
143
|
return widgetId;
|
|
174
144
|
}
|
|
175
|
-
|
|
176
145
|
_removeWidget(widget) {
|
|
177
146
|
const settingId = widgetIdToSettingId(widget.id);
|
|
178
147
|
const setting = this.api(settingId);
|
|
179
|
-
|
|
180
148
|
if (setting) {
|
|
181
149
|
const instance = setting.get();
|
|
182
150
|
this.widgetsCache.delete(instance);
|
|
183
151
|
}
|
|
184
|
-
|
|
185
152
|
this.api.remove(settingId);
|
|
186
153
|
}
|
|
187
|
-
|
|
188
154
|
_updateWidget(widget) {
|
|
189
|
-
const prevWidget = this.getWidget(widget.id);
|
|
155
|
+
const prevWidget = this.getWidget(widget.id);
|
|
190
156
|
|
|
157
|
+
// Bail out update if nothing changed.
|
|
191
158
|
if (prevWidget === widget) {
|
|
192
159
|
return widget.id;
|
|
193
|
-
}
|
|
194
|
-
|
|
160
|
+
}
|
|
195
161
|
|
|
162
|
+
// Update existing setting if only the widget's instance changed.
|
|
196
163
|
if (prevWidget.idBase && widget.idBase && prevWidget.idBase === widget.idBase) {
|
|
197
164
|
const settingId = widgetIdToSettingId(widget.id);
|
|
198
165
|
this.api(settingId).set(widget.instance);
|
|
199
166
|
return widget.id;
|
|
200
|
-
}
|
|
201
|
-
|
|
167
|
+
}
|
|
202
168
|
|
|
169
|
+
// Otherwise delete and re-create.
|
|
203
170
|
this._removeWidget(widget);
|
|
204
|
-
|
|
205
171
|
return this._createWidget(widget);
|
|
206
172
|
}
|
|
207
|
-
|
|
208
173
|
getWidget(widgetId) {
|
|
209
174
|
if (!widgetId) {
|
|
210
175
|
return null;
|
|
211
176
|
}
|
|
212
|
-
|
|
213
177
|
const {
|
|
214
178
|
idBase,
|
|
215
179
|
number
|
|
216
180
|
} = parseWidgetId(widgetId);
|
|
217
181
|
const settingId = widgetIdToSettingId(widgetId);
|
|
218
182
|
const setting = this.api(settingId);
|
|
219
|
-
|
|
220
183
|
if (!setting) {
|
|
221
184
|
return null;
|
|
222
185
|
}
|
|
223
|
-
|
|
224
186
|
const instance = setting.get();
|
|
225
|
-
|
|
226
187
|
if (this.widgetsCache.has(instance)) {
|
|
227
188
|
return this.widgetsCache.get(instance);
|
|
228
189
|
}
|
|
229
|
-
|
|
230
190
|
const widget = {
|
|
231
191
|
id: widgetId,
|
|
232
192
|
idBase,
|
|
@@ -236,7 +196,6 @@ export default class SidebarAdapter {
|
|
|
236
196
|
this.widgetsCache.set(instance, widget);
|
|
237
197
|
return widget;
|
|
238
198
|
}
|
|
239
|
-
|
|
240
199
|
_updateWidgets(nextWidgets) {
|
|
241
200
|
this.locked = true;
|
|
242
201
|
const addedWidgetIds = [];
|
|
@@ -245,9 +204,7 @@ export default class SidebarAdapter {
|
|
|
245
204
|
addedWidgetIds.push(null);
|
|
246
205
|
return this._updateWidget(nextWidget);
|
|
247
206
|
}
|
|
248
|
-
|
|
249
207
|
const widgetId = this._createWidget(nextWidget);
|
|
250
|
-
|
|
251
208
|
addedWidgetIds.push(widgetId);
|
|
252
209
|
return widgetId;
|
|
253
210
|
});
|
|
@@ -257,67 +214,50 @@ export default class SidebarAdapter {
|
|
|
257
214
|
this.locked = false;
|
|
258
215
|
return addedWidgetIds;
|
|
259
216
|
}
|
|
260
|
-
|
|
261
217
|
setWidgets(nextWidgets) {
|
|
262
218
|
const addedWidgetIds = this._updateWidgets(nextWidgets);
|
|
263
|
-
|
|
264
219
|
this._debounceSetHistory();
|
|
265
|
-
|
|
266
220
|
return addedWidgetIds;
|
|
267
221
|
}
|
|
222
|
+
|
|
268
223
|
/**
|
|
269
224
|
* Undo/Redo related features
|
|
270
225
|
*/
|
|
271
|
-
|
|
272
|
-
|
|
273
226
|
hasUndo() {
|
|
274
227
|
return this.historyIndex > 0;
|
|
275
228
|
}
|
|
276
|
-
|
|
277
229
|
hasRedo() {
|
|
278
230
|
return this.historyIndex < this.history.length - 1;
|
|
279
231
|
}
|
|
280
|
-
|
|
281
232
|
_seek(historyIndex) {
|
|
282
233
|
const currentWidgets = this.getWidgets();
|
|
283
234
|
this.historyIndex = historyIndex;
|
|
284
235
|
const widgets = this.history[this.historyIndex];
|
|
285
|
-
|
|
286
236
|
this._updateWidgets(widgets);
|
|
287
|
-
|
|
288
237
|
this._emit(currentWidgets, this.getWidgets());
|
|
289
|
-
|
|
290
238
|
this.historySubscribers.forEach(listener => listener());
|
|
291
|
-
|
|
292
239
|
this._debounceSetHistory.cancel();
|
|
293
240
|
}
|
|
294
|
-
|
|
295
241
|
undo() {
|
|
296
242
|
if (!this.hasUndo()) {
|
|
297
243
|
return;
|
|
298
244
|
}
|
|
299
|
-
|
|
300
245
|
this._seek(this.historyIndex - 1);
|
|
301
246
|
}
|
|
302
|
-
|
|
303
247
|
redo() {
|
|
304
248
|
if (!this.hasRedo()) {
|
|
305
249
|
return;
|
|
306
250
|
}
|
|
307
|
-
|
|
308
251
|
this._seek(this.historyIndex + 1);
|
|
309
252
|
}
|
|
310
|
-
|
|
311
253
|
subscribeHistory(listener) {
|
|
312
254
|
this.historySubscribers.add(listener);
|
|
313
255
|
return () => {
|
|
314
256
|
this.historySubscribers.delete(listener);
|
|
315
257
|
};
|
|
316
258
|
}
|
|
317
|
-
|
|
318
259
|
save() {
|
|
319
260
|
this.api.previewer.save();
|
|
320
261
|
}
|
|
321
|
-
|
|
322
262
|
}
|
|
323
263
|
//# sourceMappingURL=sidebar-adapter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/customize-widgets/src/components/sidebar-block-editor/sidebar-adapter.js"],"names":["settingIdToWidgetId","wp","window","parseWidgetId","widgetId","matches","match","idBase","number","parseInt","widgetIdToSettingId","debounce","leading","callback","timeout","isLeading","timerID","debounced","args","result","apply","clearTimeout","setTimeout","cancel","SidebarAdapter","constructor","setting","api","locked","widgetsCache","WeakMap","subscribers","Set","history","_getWidgetIds","map","getWidget","historyIndex","historySubscribers","_debounceSetHistory","_pushHistory","_replaceHistory","bind","_handleSettingChange","_handleAllSettingsChange","undo","redo","save","subscribe","add","delete","getWidgets","_emit","get","slice","forEach","listener","prevWidgets","id","startsWith","includes","_createWidget","widget","widgetModel","customize","Widgets","availableWidgets","findWhere","id_base","set","settingId","settingArgs","transport","data","selectiveRefreshableWidgets","previewer","create","instance","_removeWidget","remove","_updateWidget","prevWidget","has","_updateWidgets","nextWidgets","addedWidgetIds","nextWidgetIds","nextWidget","push","deletedWidgets","filter","setWidgets","hasUndo","hasRedo","length","_seek","currentWidgets","widgets","subscribeHistory"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,mBAAT,QAAoC,aAApC;AAEA,MAAM;AAAEC,EAAAA;AAAF,IAASC,MAAf;;AAEA,SAASC,aAAT,CAAwBC,QAAxB,EAAmC;AAClC,QAAMC,OAAO,GAAGD,QAAQ,CAACE,KAAT,CAAgB,cAAhB,CAAhB;;AACA,MAAKD,OAAL,EAAe;AACd,WAAO;AACNE,MAAAA,MAAM,EAAEF,OAAO,CAAE,CAAF,CADT;AAENG,MAAAA,MAAM,EAAEC,QAAQ,CAAEJ,OAAO,CAAE,CAAF,CAAT,EAAgB,EAAhB;AAFV,KAAP;AAIA,GAPiC,CASlC;;;AACA,SAAO;AAAEE,IAAAA,MAAM,EAAEH;AAAV,GAAP;AACA;;AAED,SAASM,mBAAT,CAA8BN,QAA9B,EAAyC;AACxC,QAAM;AAAEG,IAAAA,MAAF;AAAUC,IAAAA;AAAV,MAAqBL,aAAa,CAAEC,QAAF,CAAxC;;AACA,MAAKI,MAAL,EAAc;AACb,WAAQ,UAAUD,MAAQ,IAAIC,MAAQ,GAAtC;AACA;;AAED,SAAQ,UAAUD,MAAQ,EAA1B;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,SAASI,QA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ction parseWidgetId( widgetId ) {\n\tconst matches = widgetId.match( /^(.+)-(\\d+)$/ );\n\tif ( matches ) {\n\t\treturn {\n\t\t\tidBase: matches[ 1 ],\n\t\t\tnumber: parseInt( matches[ 2 ], 10 ),\n\t\t};\n\t}\n\n\t// Likely an old single widget.\n\treturn { idBase: widgetId };\n}\n\nfunction widgetIdToSettingId( widgetId ) {\n\tconst { idBase, number } = parseWidgetId( widgetId );\n\tif ( number ) {\n\t\treturn `widget_${ idBase }[${ number }]`;\n\t}\n\n\treturn `widget_${ idBase }`;\n}\n\n/**\n * This is a custom debounce function to call different callbacks depending on\n * whether it's the _leading_ call or not.\n *\n * @param {Function} leading The callback that gets called first.\n * @param {Function} callback The callback that gets called after the first time.\n * @param {number} timeout The debounced time in milliseconds.\n * @return {Function} The debounced function.\n */\nfunction debounce( leading, callback, timeout ) {\n\tlet isLeading = false;\n\tlet timerID;\n\n\tfunction debounced( ...args ) {\n\t\tconst result = ( isLeading ? callback : leading ).apply( this, args );\n\n\t\tisLeading = true;\n\n\t\tclearTimeout( timerID );\n\n\t\ttimerID = setTimeout( () => {\n\t\t\tisLeading = false;\n\t\t}, timeout );\n\n\t\treturn result;\n\t}\n\n\tdebounced.cancel = () => {\n\t\tisLeading = false;\n\t\tclearTimeout( timerID );\n\t};\n\n\treturn debounced;\n}\n\nexport default class SidebarAdapter {\n\tconstructor( setting, api ) {\n\t\tthis.setting = setting;\n\t\tthis.api = api;\n\n\t\tthis.locked = false;\n\t\tthis.widgetsCache = new WeakMap();\n\t\tthis.subscribers = new Set();\n\n\t\tthis.history = [\n\t\t\tthis._getWidgetIds().map( ( widgetId ) =>\n\t\t\t\tthis.getWidget( widgetId )\n\t\t\t),\n\t\t];\n\t\tthis.historyIndex = 0;\n\t\tthis.historySubscribers = new Set();\n\t\t// Debounce the input for 1 second.\n\t\tthis._debounceSetHistory = debounce(\n\t\t\tthis._pushHistory,\n\t\t\tthis._replaceHistory,\n\t\t\t1000\n\t\t);\n\n\t\tthis.setting.bind( this._handleSettingChange.bind( this ) );\n\t\tthis.api.bind( 'change', this._handleAllSettingsChange.bind( this ) );\n\n\t\tthis.undo = this.undo.bind( this );\n\t\tthis.redo = this.redo.bind( this );\n\t\tthis.save = this.save.bind( this );\n\t}\n\n\tsubscribe( callback ) {\n\t\tthis.subscribers.add( callback );\n\n\t\treturn () => {\n\t\t\tthis.subscribers.delete( callback );\n\t\t};\n\t}\n\n\tgetWidgets() {\n\t\treturn this.history[ this.historyIndex ];\n\t}\n\n\t_emit( ...args ) {\n\t\tfor ( const callback of this.subscribers ) {\n\t\t\tcallback( ...args );\n\t\t}\n\t}\n\n\t_getWidgetIds() {\n\t\treturn this.setting.get();\n\t}\n\n\t_pushHistory() {\n\t\tthis.history = [\n\t\t\t...this.history.slice( 0, this.historyIndex + 1 ),\n\t\t\tthis._getWidgetIds().map( ( widgetId ) =>\n\t\t\t\tthis.getWidget( widgetId )\n\t\t\t),\n\t\t];\n\t\tthis.historyIndex += 1;\n\n\t\tthis.historySubscribers.forEach( ( listener ) => listener() );\n\t}\n\n\t_replaceHistory() {\n\t\tthis.history[ this.historyIndex ] = this._getWidgetIds().map(\n\t\t\t( widgetId ) => this.getWidget( widgetId )\n\t\t);\n\t}\n\n\t_handleSettingChange() {\n\t\tif ( this.locked ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst prevWidgets = this.getWidgets();\n\n\t\tthis._pushHistory();\n\n\t\tthis._emit( prevWidgets, this.getWidgets() );\n\t}\n\n\t_handleAllSettingsChange( setting ) {\n\t\tif ( this.locked ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( ! setting.id.startsWith( 'widget_' ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst widgetId = settingIdToWidgetId( setting.id );\n\t\tif ( ! this.setting.get().includes( widgetId ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst prevWidgets = this.getWidgets();\n\n\t\tthis._pushHistory();\n\n\t\tthis._emit( prevWidgets, this.getWidgets() );\n\t}\n\n\t_createWidget( widget ) {\n\t\tconst widgetModel = wp.customize.Widgets.availableWidgets.findWhere( {\n\t\t\tid_base: widget.idBase,\n\t\t} );\n\n\t\tlet number = widget.number;\n\t\tif ( widgetModel.get( 'is_multi' ) && ! number ) {\n\t\t\twidgetModel.set(\n\t\t\t\t'multi_number',\n\t\t\t\twidgetModel.get( 'multi_number' ) + 1\n\t\t\t);\n\t\t\tnumber = widgetModel.get( 'multi_number' );\n\t\t}\n\n\t\tconst settingId = number\n\t\t\t? `widget_${ widget.idBase }[${ number }]`\n\t\t\t: `widget_${ widget.idBase }`;\n\n\t\tconst settingArgs = {\n\t\t\ttransport: wp.customize.Widgets.data.selectiveRefreshableWidgets[\n\t\t\t\twidgetModel.get( 'id_base' )\n\t\t\t]\n\t\t\t\t? 'postMessage'\n\t\t\t\t: 'refresh',\n\t\t\tpreviewer: this.setting.previewer,\n\t\t};\n\t\tconst setting = this.api.create(\n\t\t\tsettingId,\n\t\t\tsettingId,\n\t\t\t'',\n\t\t\tsettingArgs\n\t\t);\n\t\tsetting.set( widget.instance );\n\n\t\tconst widgetId = settingIdToWidgetId( settingId );\n\n\t\treturn widgetId;\n\t}\n\n\t_removeWidget( widget ) {\n\t\tconst settingId = widgetIdToSettingId( widget.id );\n\t\tconst setting = this.api( settingId );\n\n\t\tif ( setting ) {\n\t\t\tconst instance = setting.get();\n\t\t\tthis.widgetsCache.delete( instance );\n\t\t}\n\n\t\tthis.api.remove( settingId );\n\t}\n\n\t_updateWidget( widget ) {\n\t\tconst prevWidget = this.getWidget( widget.id );\n\n\t\t// Bail out update if nothing changed.\n\t\tif ( prevWidget === widget ) {\n\t\t\treturn widget.id;\n\t\t}\n\n\t\t// Update existing setting if only the widget's instance changed.\n\t\tif (\n\t\t\tprevWidget.idBase &&\n\t\t\twidget.idBase &&\n\t\t\tprevWidget.idBase === widget.idBase\n\t\t) {\n\t\t\tconst settingId = widgetIdToSettingId( widget.id );\n\t\t\tthis.api( settingId ).set( widget.instance );\n\t\t\treturn widget.id;\n\t\t}\n\n\t\t// Otherwise delete and re-create.\n\t\tthis._removeWidget( widget );\n\t\treturn this._createWidget( widget );\n\t}\n\n\tgetWidget( widgetId ) {\n\t\tif ( ! widgetId ) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst { idBase, number } = parseWidgetId( widgetId );\n\t\tconst settingId = widgetIdToSettingId( widgetId );\n\t\tconst setting = this.api( settingId );\n\n\t\tif ( ! setting ) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst instance = setting.get();\n\n\t\tif ( this.widgetsCache.has( instance ) ) {\n\t\t\treturn this.widgetsCache.get( instance );\n\t\t}\n\n\t\tconst widget = {\n\t\t\tid: widgetId,\n\t\t\tidBase,\n\t\t\tnumber,\n\t\t\tinstance,\n\t\t};\n\n\t\tthis.widgetsCache.set( instance, widget );\n\n\t\treturn widget;\n\t}\n\n\t_updateWidgets( nextWidgets ) {\n\t\tthis.locked = true;\n\n\t\tconst addedWidgetIds = [];\n\n\t\tconst nextWidgetIds = nextWidgets.map( ( nextWidget ) => {\n\t\t\tif ( nextWidget.id && this.getWidget( nextWidget.id ) ) {\n\t\t\t\taddedWidgetIds.push( null );\n\n\t\t\t\treturn this._updateWidget( nextWidget );\n\t\t\t}\n\n\t\t\tconst widgetId = this._createWidget( nextWidget );\n\n\t\t\taddedWidgetIds.push( widgetId );\n\n\t\t\treturn widgetId;\n\t\t} );\n\n\t\tconst deletedWidgets = this.getWidgets().filter(\n\t\t\t( widget ) => ! nextWidgetIds.includes( widget.id )\n\t\t);\n\t\tdeletedWidgets.forEach( ( widget ) => this._removeWidget( widget ) );\n\n\t\tthis.setting.set( nextWidgetIds );\n\n\t\tthis.locked = false;\n\n\t\treturn addedWidgetIds;\n\t}\n\n\tsetWidgets( nextWidgets ) {\n\t\tconst addedWidgetIds = this._updateWidgets( nextWidgets );\n\n\t\tthis._debounceSetHistory();\n\n\t\treturn addedWidgetIds;\n\t}\n\n\t/**\n\t * Undo/Redo related features\n\t */\n\thasUndo() {\n\t\treturn this.historyIndex > 0;\n\t}\n\n\thasRedo() {\n\t\treturn this.historyIndex < this.history.length - 1;\n\t}\n\n\t_seek( historyIndex ) {\n\t\tconst currentWidgets = this.getWidgets();\n\n\t\tthis.historyIndex = historyIndex;\n\n\t\tconst widgets = this.history[ this.historyIndex ];\n\n\t\tthis._updateWidgets( widgets );\n\n\t\tthis._emit( currentWidgets, this.getWidgets() );\n\n\t\tthis.historySubscribers.forEach( ( listener ) => listener() );\n\t\tthis._debounceSetHistory.cancel();\n\t}\n\n\tundo() {\n\t\tif ( ! this.hasUndo() ) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis._seek( this.historyIndex - 1 );\n\t}\n\n\tredo() {\n\t\tif ( ! this.hasRedo() ) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis._seek( this.historyIndex + 1 );\n\t}\n\n\tsubscribeHistory( listener ) {\n\t\tthis.historySubscribers.add( listener );\n\n\t\treturn () => {\n\t\t\tthis.historySubscribers.delete( listener );\n\t\t};\n\t}\n\n\tsave() {\n\t\tthis.api.previewer.save();\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"names":["settingIdToWidgetId","wp","window","parseWidgetId","widgetId","matches","match","idBase","number","parseInt","widgetIdToSettingId","debounce","leading","callback","timeout","isLeading","timerID","debounced","args","result","apply","clearTimeout","setTimeout","cancel","SidebarAdapter","constructor","setting","api","locked","widgetsCache","WeakMap","subscribers","Set","history","_getWidgetIds","map","getWidget","historyIndex","historySubscribers","_debounceSetHistory","_pushHistory","_replaceHistory","bind","_handleSettingChange","_handleAllSettingsChange","undo","redo","save","subscribe","add","delete","getWidgets","_emit","get","slice","forEach","listener","prevWidgets","id","startsWith","includes","_createWidget","widget","widgetModel","customize","Widgets","availableWidgets","findWhere","id_base","set","settingId","settingArgs","transport","data","selectiveRefreshableWidgets","previewer","create","instance","_removeWidget","remove","_updateWidget","prevWidget","has","_updateWidgets","nextWidgets","addedWidgetIds","nextWidgetIds","nextWidget","push","deletedWidgets","filter","setWidgets","hasUndo","hasRedo","length","_seek","currentWidgets","widgets","subscribeHistory"],"sources":["@wordpress/customize-widgets/src/components/sidebar-block-editor/sidebar-adapter.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport { settingIdToWidgetId } from '../../utils';\n\nconst { wp } = window;\n\nfunction parseWidgetId( widgetId ) {\n\tconst matches = widgetId.match( /^(.+)-(\\d+)$/ );\n\tif ( matches ) {\n\t\treturn {\n\t\t\tidBase: matches[ 1 ],\n\t\t\tnumber: parseInt( matches[ 2 ], 10 ),\n\t\t};\n\t}\n\n\t// Likely an old single widget.\n\treturn { idBase: widgetId };\n}\n\nfunction widgetIdToSettingId( widgetId ) {\n\tconst { idBase, number } = parseWidgetId( widgetId );\n\tif ( number ) {\n\t\treturn `widget_${ idBase }[${ number }]`;\n\t}\n\n\treturn `widget_${ idBase }`;\n}\n\n/**\n * This is a custom debounce function to call different callbacks depending on\n * whether it's the _leading_ call or not.\n *\n * @param {Function} leading The callback that gets called first.\n * @param {Function} callback The callback that gets called after the first time.\n * @param {number} timeout The debounced time in milliseconds.\n * @return {Function} The debounced function.\n */\nfunction debounce( leading, callback, timeout ) {\n\tlet isLeading = false;\n\tlet timerID;\n\n\tfunction debounced( ...args ) {\n\t\tconst result = ( isLeading ? callback : leading ).apply( this, args );\n\n\t\tisLeading = true;\n\n\t\tclearTimeout( timerID );\n\n\t\ttimerID = setTimeout( () => {\n\t\t\tisLeading = false;\n\t\t}, timeout );\n\n\t\treturn result;\n\t}\n\n\tdebounced.cancel = () => {\n\t\tisLeading = false;\n\t\tclearTimeout( timerID );\n\t};\n\n\treturn debounced;\n}\n\nexport default class SidebarAdapter {\n\tconstructor( setting, api ) {\n\t\tthis.setting = setting;\n\t\tthis.api = api;\n\n\t\tthis.locked = false;\n\t\tthis.widgetsCache = new WeakMap();\n\t\tthis.subscribers = new Set();\n\n\t\tthis.history = [\n\t\t\tthis._getWidgetIds().map( ( widgetId ) =>\n\t\t\t\tthis.getWidget( widgetId )\n\t\t\t),\n\t\t];\n\t\tthis.historyIndex = 0;\n\t\tthis.historySubscribers = new Set();\n\t\t// Debounce the input for 1 second.\n\t\tthis._debounceSetHistory = debounce(\n\t\t\tthis._pushHistory,\n\t\t\tthis._replaceHistory,\n\t\t\t1000\n\t\t);\n\n\t\tthis.setting.bind( this._handleSettingChange.bind( this ) );\n\t\tthis.api.bind( 'change', this._handleAllSettingsChange.bind( this ) );\n\n\t\tthis.undo = this.undo.bind( this );\n\t\tthis.redo = this.redo.bind( this );\n\t\tthis.save = this.save.bind( this );\n\t}\n\n\tsubscribe( callback ) {\n\t\tthis.subscribers.add( callback );\n\n\t\treturn () => {\n\t\t\tthis.subscribers.delete( callback );\n\t\t};\n\t}\n\n\tgetWidgets() {\n\t\treturn this.history[ this.historyIndex ];\n\t}\n\n\t_emit( ...args ) {\n\t\tfor ( const callback of this.subscribers ) {\n\t\t\tcallback( ...args );\n\t\t}\n\t}\n\n\t_getWidgetIds() {\n\t\treturn this.setting.get();\n\t}\n\n\t_pushHistory() {\n\t\tthis.history = [\n\t\t\t...this.history.slice( 0, this.historyIndex + 1 ),\n\t\t\tthis._getWidgetIds().map( ( widgetId ) =>\n\t\t\t\tthis.getWidget( widgetId )\n\t\t\t),\n\t\t];\n\t\tthis.historyIndex += 1;\n\n\t\tthis.historySubscribers.forEach( ( listener ) => listener() );\n\t}\n\n\t_replaceHistory() {\n\t\tthis.history[ this.historyIndex ] = this._getWidgetIds().map(\n\t\t\t( widgetId ) => this.getWidget( widgetId )\n\t\t);\n\t}\n\n\t_handleSettingChange() {\n\t\tif ( this.locked ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst prevWidgets = this.getWidgets();\n\n\t\tthis._pushHistory();\n\n\t\tthis._emit( prevWidgets, this.getWidgets() );\n\t}\n\n\t_handleAllSettingsChange( setting ) {\n\t\tif ( this.locked ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( ! setting.id.startsWith( 'widget_' ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst widgetId = settingIdToWidgetId( setting.id );\n\t\tif ( ! this.setting.get().includes( widgetId ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst prevWidgets = this.getWidgets();\n\n\t\tthis._pushHistory();\n\n\t\tthis._emit( prevWidgets, this.getWidgets() );\n\t}\n\n\t_createWidget( widget ) {\n\t\tconst widgetModel = wp.customize.Widgets.availableWidgets.findWhere( {\n\t\t\tid_base: widget.idBase,\n\t\t} );\n\n\t\tlet number = widget.number;\n\t\tif ( widgetModel.get( 'is_multi' ) && ! number ) {\n\t\t\twidgetModel.set(\n\t\t\t\t'multi_number',\n\t\t\t\twidgetModel.get( 'multi_number' ) + 1\n\t\t\t);\n\t\t\tnumber = widgetModel.get( 'multi_number' );\n\t\t}\n\n\t\tconst settingId = number\n\t\t\t? `widget_${ widget.idBase }[${ number }]`\n\t\t\t: `widget_${ widget.idBase }`;\n\n\t\tconst settingArgs = {\n\t\t\ttransport: wp.customize.Widgets.data.selectiveRefreshableWidgets[\n\t\t\t\twidgetModel.get( 'id_base' )\n\t\t\t]\n\t\t\t\t? 'postMessage'\n\t\t\t\t: 'refresh',\n\t\t\tpreviewer: this.setting.previewer,\n\t\t};\n\t\tconst setting = this.api.create(\n\t\t\tsettingId,\n\t\t\tsettingId,\n\t\t\t'',\n\t\t\tsettingArgs\n\t\t);\n\t\tsetting.set( widget.instance );\n\n\t\tconst widgetId = settingIdToWidgetId( settingId );\n\n\t\treturn widgetId;\n\t}\n\n\t_removeWidget( widget ) {\n\t\tconst settingId = widgetIdToSettingId( widget.id );\n\t\tconst setting = this.api( settingId );\n\n\t\tif ( setting ) {\n\t\t\tconst instance = setting.get();\n\t\t\tthis.widgetsCache.delete( instance );\n\t\t}\n\n\t\tthis.api.remove( settingId );\n\t}\n\n\t_updateWidget( widget ) {\n\t\tconst prevWidget = this.getWidget( widget.id );\n\n\t\t// Bail out update if nothing changed.\n\t\tif ( prevWidget === widget ) {\n\t\t\treturn widget.id;\n\t\t}\n\n\t\t// Update existing setting if only the widget's instance changed.\n\t\tif (\n\t\t\tprevWidget.idBase &&\n\t\t\twidget.idBase &&\n\t\t\tprevWidget.idBase === widget.idBase\n\t\t) {\n\t\t\tconst settingId = widgetIdToSettingId( widget.id );\n\t\t\tthis.api( settingId ).set( widget.instance );\n\t\t\treturn widget.id;\n\t\t}\n\n\t\t// Otherwise delete and re-create.\n\t\tthis._removeWidget( widget );\n\t\treturn this._createWidget( widget );\n\t}\n\n\tgetWidget( widgetId ) {\n\t\tif ( ! widgetId ) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst { idBase, number } = parseWidgetId( widgetId );\n\t\tconst settingId = widgetIdToSettingId( widgetId );\n\t\tconst setting = this.api( settingId );\n\n\t\tif ( ! setting ) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst instance = setting.get();\n\n\t\tif ( this.widgetsCache.has( instance ) ) {\n\t\t\treturn this.widgetsCache.get( instance );\n\t\t}\n\n\t\tconst widget = {\n\t\t\tid: widgetId,\n\t\t\tidBase,\n\t\t\tnumber,\n\t\t\tinstance,\n\t\t};\n\n\t\tthis.widgetsCache.set( instance, widget );\n\n\t\treturn widget;\n\t}\n\n\t_updateWidgets( nextWidgets ) {\n\t\tthis.locked = true;\n\n\t\tconst addedWidgetIds = [];\n\n\t\tconst nextWidgetIds = nextWidgets.map( ( nextWidget ) => {\n\t\t\tif ( nextWidget.id && this.getWidget( nextWidget.id ) ) {\n\t\t\t\taddedWidgetIds.push( null );\n\n\t\t\t\treturn this._updateWidget( nextWidget );\n\t\t\t}\n\n\t\t\tconst widgetId = this._createWidget( nextWidget );\n\n\t\t\taddedWidgetIds.push( widgetId );\n\n\t\t\treturn widgetId;\n\t\t} );\n\n\t\tconst deletedWidgets = this.getWidgets().filter(\n\t\t\t( widget ) => ! nextWidgetIds.includes( widget.id )\n\t\t);\n\t\tdeletedWidgets.forEach( ( widget ) => this._removeWidget( widget ) );\n\n\t\tthis.setting.set( nextWidgetIds );\n\n\t\tthis.locked = false;\n\n\t\treturn addedWidgetIds;\n\t}\n\n\tsetWidgets( nextWidgets ) {\n\t\tconst addedWidgetIds = this._updateWidgets( nextWidgets );\n\n\t\tthis._debounceSetHistory();\n\n\t\treturn addedWidgetIds;\n\t}\n\n\t/**\n\t * Undo/Redo related features\n\t */\n\thasUndo() {\n\t\treturn this.historyIndex > 0;\n\t}\n\n\thasRedo() {\n\t\treturn this.historyIndex < this.history.length - 1;\n\t}\n\n\t_seek( historyIndex ) {\n\t\tconst currentWidgets = this.getWidgets();\n\n\t\tthis.historyIndex = historyIndex;\n\n\t\tconst widgets = this.history[ this.historyIndex ];\n\n\t\tthis._updateWidgets( widgets );\n\n\t\tthis._emit( currentWidgets, this.getWidgets() );\n\n\t\tthis.historySubscribers.forEach( ( listener ) => listener() );\n\t\tthis._debounceSetHistory.cancel();\n\t}\n\n\tundo() {\n\t\tif ( ! this.hasUndo() ) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis._seek( this.historyIndex - 1 );\n\t}\n\n\tredo() {\n\t\tif ( ! this.hasRedo() ) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis._seek( this.historyIndex + 1 );\n\t}\n\n\tsubscribeHistory( listener ) {\n\t\tthis.historySubscribers.add( listener );\n\n\t\treturn () => {\n\t\t\tthis.historySubscribers.delete( listener );\n\t\t};\n\t}\n\n\tsave() {\n\t\tthis.api.previewer.save();\n\t}\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,mBAAmB,QAAQ,aAAa;AAEjD,MAAM;EAAEC;AAAG,CAAC,GAAGC,MAAM;AAErB,SAASC,aAAaA,CAAEC,QAAQ,EAAG;EAClC,MAAMC,OAAO,GAAGD,QAAQ,CAACE,KAAK,CAAE,cAAe,CAAC;EAChD,IAAKD,OAAO,EAAG;IACd,OAAO;MACNE,MAAM,EAAEF,OAAO,CAAE,CAAC,CAAE;MACpBG,MAAM,EAAEC,QAAQ,CAAEJ,OAAO,CAAE,CAAC,CAAE,EAAE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,CAAC;EAClC;EAEAsB,IAAIA,CAAA,EAAG;IACN,IAAK,CAAE,IAAI,CAAC+C,OAAO,CAAC,CAAC,EAAG;MACvB;IACD;IAEA,IAAI,CAACG,KAAK,CAAE,IAAI,CAAC1D,YAAY,GAAG,CAAE,CAAC;EACpC;EAEAS,IAAIA,CAAA,EAAG;IACN,IAAK,CAAE,IAAI,CAAC+C,OAAO,CAAC,CAAC,EAAG;MACvB;IACD;IAEA,IAAI,CAACE,KAAK,CAAE,IAAI,CAAC1D,YAAY,GAAG,CAAE,CAAC;EACpC;EAEA6D,gBAAgBA,CAAE1C,QAAQ,EAAG;IAC5B,IAAI,CAAClB,kBAAkB,CAACW,GAAG,CAAEO,QAAS,CAAC;IAEvC,OAAO,MAAM;MACZ,IAAI,CAAClB,kBAAkB,CAACY,MAAM,CAAEM,QAAS,CAAC;IAC3C,CAAC;EACF;EAEAT,IAAIA,CAAA,EAAG;IACN,IAAI,CAACpB,GAAG,CAACgD,SAAS,CAAC5B,IAAI,CAAC,CAAC;EAC1B;AACD"}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { createElement } from "@wordpress/element";
|
|
2
|
-
|
|
3
2
|
/**
|
|
4
3
|
* WordPress dependencies
|
|
5
4
|
*/
|
|
6
5
|
import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';
|
|
6
|
+
|
|
7
7
|
/**
|
|
8
8
|
* Internal dependencies
|
|
9
9
|
*/
|
|
10
|
-
|
|
11
10
|
import useSidebarBlockEditor from './use-sidebar-block-editor';
|
|
12
11
|
import useBlocksFocusControl from '../focus-control/use-blocks-focus-control';
|
|
13
12
|
import { unlock } from '../../lock-unlock';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["privateApis","blockEditorPrivateApis","useSidebarBlockEditor","useBlocksFocusControl","unlock","ExperimentalBlockEditorProvider","SidebarEditorProvider","sidebar","settings","children","blocks","onInput","onChange","createElement","value","useSubRegistry"],"sources":["@wordpress/customize-widgets/src/components/sidebar-block-editor/sidebar-editor-provider.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport useSidebarBlockEditor from './use-sidebar-block-editor';\nimport useBlocksFocusControl from '../focus-control/use-blocks-focus-control';\n\nimport { unlock } from '../../lock-unlock';\n\nconst { ExperimentalBlockEditorProvider } = unlock( blockEditorPrivateApis );\n\nexport default function SidebarEditorProvider( {\n\tsidebar,\n\tsettings,\n\tchildren,\n} ) {\n\tconst [ blocks, onInput, onChange ] = useSidebarBlockEditor( sidebar );\n\n\tuseBlocksFocusControl( blocks );\n\n\treturn (\n\t\t<ExperimentalBlockEditorProvider\n\t\t\tvalue={ blocks }\n\t\t\tonInput={ onInput }\n\t\t\tonChange={ onChange }\n\t\t\tsettings={ settings }\n\t\t\tuseSubRegistry={ false }\n\t\t>\n\t\t\t{ children }\n\t\t</ExperimentalBlockEditorProvider>\n\t);\n}\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,WAAW,IAAIC,sBAAsB,QAAQ,yBAAyB;;AAE/E;AACA;AACA;AACA,OAAOC,qBAAqB,MAAM,4BAA4B;AAC9D,OAAOC,qBAAqB,MAAM,2CAA2C;AAE7E,SAASC,MAAM,QAAQ,mBAAmB;AAE1C,MAAM;EAAEC;AAAgC,CAAC,GAAGD,MAAM,CAAEH,sBAAuB,CAAC;AAE5E,eAAe,SAASK,qBAAqBA,CAAE;EAC9CC,OAAO;EACPC,QAAQ;EACRC;AACD,CAAC,EAAG;EACH,MAAM,CAAEC,MAAM,EAAEC,OAAO,EAAEC,QAAQ,CAAE,GAAGV,qBAAqB,CAAEK,OAAQ,CAAC;EAEtEJ,qBAAqB,CAAEO,MAAO,CAAC;EAE/B,OACCG,aAAA,CAACR,+BAA+B;IAC/BS,KAAK,EAAGJ,MAAQ;IAChBC,OAAO,EAAGA,OAAS;IACnBC,QAAQ,EAAGA,QAAU;IACrBJ,QAAQ,EAAGA,QAAU;IACrBO,cAAc,EAAG;EAAO,GAEtBN,QAC8B,CAAC;AAEpC"}
|
|
@@ -2,23 +2,21 @@
|
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
4
|
import fastDeepEqual from 'fast-deep-equal/es6';
|
|
5
|
+
|
|
5
6
|
/**
|
|
6
7
|
* WordPress dependencies
|
|
7
8
|
*/
|
|
8
|
-
|
|
9
9
|
import { useState, useEffect, useCallback } from '@wordpress/element';
|
|
10
10
|
import isShallowEqual from '@wordpress/is-shallow-equal';
|
|
11
11
|
import { getWidgetIdFromBlock, addWidgetIdToBlock } from '@wordpress/widgets';
|
|
12
|
+
|
|
12
13
|
/**
|
|
13
14
|
* Internal dependencies
|
|
14
15
|
*/
|
|
15
|
-
|
|
16
16
|
import { blockToWidget, widgetToBlock } from '../../utils';
|
|
17
|
-
|
|
18
17
|
function widgetsToBlocks(widgets) {
|
|
19
18
|
return widgets.map(widget => widgetToBlock(widget));
|
|
20
19
|
}
|
|
21
|
-
|
|
22
20
|
export default function useSidebarBlockEditor(sidebar) {
|
|
23
21
|
const [blocks, setBlocks] = useState(() => widgetsToBlocks(sidebar.getWidgets()));
|
|
24
22
|
useEffect(() => {
|
|
@@ -27,19 +25,19 @@ export default function useSidebarBlockEditor(sidebar) {
|
|
|
27
25
|
const prevWidgetsMap = new Map(prevWidgets.map(widget => [widget.id, widget]));
|
|
28
26
|
const prevBlocksMap = new Map(prevBlocks.map(block => [getWidgetIdFromBlock(block), block]));
|
|
29
27
|
const nextBlocks = nextWidgets.map(nextWidget => {
|
|
30
|
-
const prevWidget = prevWidgetsMap.get(nextWidget.id);
|
|
28
|
+
const prevWidget = prevWidgetsMap.get(nextWidget.id);
|
|
31
29
|
|
|
30
|
+
// Bail out updates.
|
|
32
31
|
if (prevWidget && prevWidget === nextWidget) {
|
|
33
32
|
return prevBlocksMap.get(nextWidget.id);
|
|
34
33
|
}
|
|
35
|
-
|
|
36
34
|
return widgetToBlock(nextWidget);
|
|
37
|
-
});
|
|
35
|
+
});
|
|
38
36
|
|
|
37
|
+
// Bail out updates.
|
|
39
38
|
if (isShallowEqual(prevBlocks, nextBlocks)) {
|
|
40
39
|
return prevBlocks;
|
|
41
40
|
}
|
|
42
|
-
|
|
43
41
|
return nextBlocks;
|
|
44
42
|
});
|
|
45
43
|
});
|
|
@@ -49,45 +47,42 @@ export default function useSidebarBlockEditor(sidebar) {
|
|
|
49
47
|
if (isShallowEqual(prevBlocks, nextBlocks)) {
|
|
50
48
|
return prevBlocks;
|
|
51
49
|
}
|
|
52
|
-
|
|
53
50
|
const prevBlocksMap = new Map(prevBlocks.map(block => [getWidgetIdFromBlock(block), block]));
|
|
54
51
|
const nextWidgets = nextBlocks.map(nextBlock => {
|
|
55
|
-
const widgetId = getWidgetIdFromBlock(nextBlock);
|
|
52
|
+
const widgetId = getWidgetIdFromBlock(nextBlock);
|
|
56
53
|
|
|
54
|
+
// Update existing widgets.
|
|
57
55
|
if (widgetId && prevBlocksMap.has(widgetId)) {
|
|
58
56
|
const prevBlock = prevBlocksMap.get(widgetId);
|
|
59
|
-
const prevWidget = sidebar.getWidget(widgetId);
|
|
60
|
-
// Deep equality is necessary until the block editor's internals changes.
|
|
57
|
+
const prevWidget = sidebar.getWidget(widgetId);
|
|
61
58
|
|
|
59
|
+
// Bail out updates by returning the previous widgets.
|
|
60
|
+
// Deep equality is necessary until the block editor's internals changes.
|
|
62
61
|
if (fastDeepEqual(nextBlock, prevBlock) && prevWidget) {
|
|
63
62
|
return prevWidget;
|
|
64
63
|
}
|
|
65
|
-
|
|
66
64
|
return blockToWidget(nextBlock, prevWidget);
|
|
67
|
-
}
|
|
68
|
-
|
|
65
|
+
}
|
|
69
66
|
|
|
67
|
+
// Add a new widget.
|
|
70
68
|
return blockToWidget(nextBlock);
|
|
71
|
-
});
|
|
69
|
+
});
|
|
72
70
|
|
|
71
|
+
// Bail out updates if the updated widgets are the same.
|
|
73
72
|
if (isShallowEqual(sidebar.getWidgets(), nextWidgets)) {
|
|
74
73
|
return prevBlocks;
|
|
75
74
|
}
|
|
76
|
-
|
|
77
75
|
const addedWidgetIds = sidebar.setWidgets(nextWidgets);
|
|
78
76
|
return nextBlocks.reduce((updatedNextBlocks, nextBlock, index) => {
|
|
79
77
|
const addedWidgetId = addedWidgetIds[index];
|
|
80
|
-
|
|
81
78
|
if (addedWidgetId !== null) {
|
|
82
79
|
// Only create a new instance if necessary to prevent
|
|
83
80
|
// the whole editor from re-rendering on every edit.
|
|
84
81
|
if (updatedNextBlocks === nextBlocks) {
|
|
85
82
|
updatedNextBlocks = nextBlocks.slice();
|
|
86
83
|
}
|
|
87
|
-
|
|
88
84
|
updatedNextBlocks[index] = addWidgetIdToBlock(nextBlock, addedWidgetId);
|
|
89
85
|
}
|
|
90
|
-
|
|
91
86
|
return updatedNextBlocks;
|
|
92
87
|
}, nextBlocks);
|
|
93
88
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["fastDeepEqual","useState","useEffect","useCallback","isShallowEqual","getWidgetIdFromBlock","addWidgetIdToBlock","blockToWidget","widgetToBlock","widgetsToBlocks","widgets","map","widget","useSidebarBlockEditor","sidebar","blocks","setBlocks","getWidgets","subscribe","prevWidgets","nextWidgets","prevBlocks","prevWidgetsMap","Map","id","prevBlocksMap","block","nextBlocks","nextWidget","prevWidget","get","onChangeBlocks","nextBlock","widgetId","has","prevBlock","getWidget","addedWidgetIds","setWidgets","reduce","updatedNextBlocks","index","addedWidgetId","slice"],"sources":["@wordpress/customize-widgets/src/components/sidebar-block-editor/use-sidebar-block-editor.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport fastDeepEqual from 'fast-deep-equal/es6';\n\n/**\n * WordPress dependencies\n */\nimport { useState, useEffect, useCallback } from '@wordpress/element';\nimport isShallowEqual from '@wordpress/is-shallow-equal';\nimport { getWidgetIdFromBlock, addWidgetIdToBlock } from '@wordpress/widgets';\n\n/**\n * Internal dependencies\n */\nimport { blockToWidget, widgetToBlock } from '../../utils';\n\nfunction widgetsToBlocks( widgets ) {\n\treturn widgets.map( ( widget ) => widgetToBlock( widget ) );\n}\n\nexport default function useSidebarBlockEditor( sidebar ) {\n\tconst [ blocks, setBlocks ] = useState( () =>\n\t\twidgetsToBlocks( sidebar.getWidgets() )\n\t);\n\n\tuseEffect( () => {\n\t\treturn sidebar.subscribe( ( prevWidgets, nextWidgets ) => {\n\t\t\tsetBlocks( ( prevBlocks ) => {\n\t\t\t\tconst prevWidgetsMap = new Map(\n\t\t\t\t\tprevWidgets.map( ( widget ) => [ widget.id, widget ] )\n\t\t\t\t);\n\t\t\t\tconst prevBlocksMap = new Map(\n\t\t\t\t\tprevBlocks.map( ( block ) => [\n\t\t\t\t\t\tgetWidgetIdFromBlock( block ),\n\t\t\t\t\t\tblock,\n\t\t\t\t\t] )\n\t\t\t\t);\n\n\t\t\t\tconst nextBlocks = nextWidgets.map( ( nextWidget ) => {\n\t\t\t\t\tconst prevWidget = prevWidgetsMap.get( nextWidget.id );\n\n\t\t\t\t\t// Bail out updates.\n\t\t\t\t\tif ( prevWidget && prevWidget === nextWidget ) {\n\t\t\t\t\t\treturn prevBlocksMap.get( nextWidget.id );\n\t\t\t\t\t}\n\n\t\t\t\t\treturn widgetToBlock( nextWidget );\n\t\t\t\t} );\n\n\t\t\t\t// Bail out updates.\n\t\t\t\tif ( isShallowEqual( prevBlocks, nextBlocks ) ) {\n\t\t\t\t\treturn prevBlocks;\n\t\t\t\t}\n\n\t\t\t\treturn nextBlocks;\n\t\t\t} );\n\t\t} );\n\t}, [ sidebar ] );\n\n\tconst onChangeBlocks = useCallback(\n\t\t( nextBlocks ) => {\n\t\t\tsetBlocks( ( prevBlocks ) => {\n\t\t\t\tif ( isShallowEqual( prevBlocks, nextBlocks ) ) {\n\t\t\t\t\treturn prevBlocks;\n\t\t\t\t}\n\n\t\t\t\tconst prevBlocksMap = new Map(\n\t\t\t\t\tprevBlocks.map( ( block ) => [\n\t\t\t\t\t\tgetWidgetIdFromBlock( block ),\n\t\t\t\t\t\tblock,\n\t\t\t\t\t] )\n\t\t\t\t);\n\n\t\t\t\tconst nextWidgets = nextBlocks.map( ( nextBlock ) => {\n\t\t\t\t\tconst widgetId = getWidgetIdFromBlock( nextBlock );\n\n\t\t\t\t\t// Update existing widgets.\n\t\t\t\t\tif ( widgetId && prevBlocksMap.has( widgetId ) ) {\n\t\t\t\t\t\tconst prevBlock = prevBlocksMap.get( widgetId );\n\t\t\t\t\t\tconst prevWidget = sidebar.getWidget( widgetId );\n\n\t\t\t\t\t\t// Bail out updates by returning the previous widgets.\n\t\t\t\t\t\t// Deep equality is necessary until the block editor's internals changes.\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tfastDeepEqual( nextBlock, prevBlock ) &&\n\t\t\t\t\t\t\tprevWidget\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\treturn prevWidget;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn blockToWidget( nextBlock, prevWidget );\n\t\t\t\t\t}\n\n\t\t\t\t\t// Add a new widget.\n\t\t\t\t\treturn blockToWidget( nextBlock );\n\t\t\t\t} );\n\n\t\t\t\t// Bail out updates if the updated widgets are the same.\n\t\t\t\tif ( isShallowEqual( sidebar.getWidgets(), nextWidgets ) ) {\n\t\t\t\t\treturn prevBlocks;\n\t\t\t\t}\n\n\t\t\t\tconst addedWidgetIds = sidebar.setWidgets( nextWidgets );\n\n\t\t\t\treturn nextBlocks.reduce(\n\t\t\t\t\t( updatedNextBlocks, nextBlock, index ) => {\n\t\t\t\t\t\tconst addedWidgetId = addedWidgetIds[ index ];\n\n\t\t\t\t\t\tif ( addedWidgetId !== null ) {\n\t\t\t\t\t\t\t// Only create a new instance if necessary to prevent\n\t\t\t\t\t\t\t// the whole editor from re-rendering on every edit.\n\t\t\t\t\t\t\tif ( updatedNextBlocks === nextBlocks ) {\n\t\t\t\t\t\t\t\tupdatedNextBlocks = nextBlocks.slice();\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tupdatedNextBlocks[ index ] = addWidgetIdToBlock(\n\t\t\t\t\t\t\t\tnextBlock,\n\t\t\t\t\t\t\t\taddedWidgetId\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn updatedNextBlocks;\n\t\t\t\t\t},\n\t\t\t\t\tnextBlocks\n\t\t\t\t);\n\t\t\t} );\n\t\t},\n\t\t[ sidebar ]\n\t);\n\n\treturn [ blocks, onChangeBlocks, onChangeBlocks ];\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,aAAa,MAAM,qBAAqB;;AAE/C;AACA;AACA;AACA,SAASC,QAAQ,EAAEC,SAAS,EAAEC,WAAW,QAAQ,oBAAoB;AACrE,OAAOC,cAAc,MAAM,6BAA6B;AACxD,SAASC,oBAAoB,EAAEC,kBAAkB,QAAQ,oBAAoB;;AAE7E;AACA;AACA;AACA,SAASC,aAAa,EAAEC,aAAa,QAAQ,aAAa;AAE1D,SAASC,eAAeA,CAAEC,OAAO,EAAG;EACnC,OAAOA,OAAO,CAACC,GAAG,CAAIC,MAAM,IAAMJ,aAAa,CAAEI,MAAO,CAAE,CAAC;AAC5D;AAEA,eAAe,SAASC,qBAAqBA,CAAEC,OAAO,EAAG;EACxD,MAAM,CAAEC,MAAM,EAAEC,SAAS,CAAE,GAAGf,QAAQ,CAAE,MACvCQ,eAAe,CAAEK,OAAO,CAACG,UAAU,CAAC,CAAE,CACvC,CAAC;EAEDf,SAAS,CAAE,MAAM;IAChB,OAAOY,OAAO,CAACI,SAAS,CAAE,CAAEC,WAAW,EAAEC,WAAW,KAAM;MACzDJ,SAAS,CAAIK,UAAU,IAAM;QAC5B,MAAMC,cAAc,GAAG,IAAIC,GAAG,CAC7BJ,WAAW,CAACR,GAAG,CAAIC,MAAM,IAAM,CAAEA,MAAM,CAACY,EAAE,EAAEZ,MAAM,CAAG,CACtD,CAAC;QACD,MAAMa,aAAa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AAEG,QAAS,CAAC;UAC/C,MAAMJ,UAAU,GAAGf,OAAO,CAACsB,SAAS,CAAEH,QAAS,CAAC;;UAEhD;UACA;UACA,IACCjC,aAAa,CAAEgC,SAAS,EAAEG,SAAU,CAAC,IACrCN,UAAU,EACT;YACD,OAAOA,UAAU;UAClB;UAEA,OAAOtB,aAAa,CAAEyB,SAAS,EAAEH,UAAW,CAAC;QAC9C;;QAEA;QACA,OAAOtB,aAAa,CAAEyB,SAAU,CAAC;MAClC,CAAE,CAAC;;MAEH;MACA,IAAK5B,cAAc,CAAEU,OAAO,CAACG,UAAU,CAAC,CAAC,EAAEG,WAAY,CAAC,EAAG;QAC1D,OAAOC,UAAU;MAClB;MAEA,MAAMgB,cAAc,GAAGvB,OAAO,CAACwB,UAAU,CAAElB,WAAY,CAAC;MAExD,OAAOO,UAAU,CAACY,MAAM,CACvB,CAAEC,iBAAiB,EAAER,SAAS,EAAES,KAAK,KAAM;QAC1C,MAAMC,aAAa,GAAGL,cAAc,CAAEI,KAAK,CAAE;QAE7C,IAAKC,aAAa,KAAK,IAAI,EAAG;UAC7B;UACA;UACA,IAAKF,iBAAiB,KAAKb,UAAU,EAAG;YACvCa,iBAAiB,GAAGb,UAAU,CAACgB,KAAK,CAAC,CAAC;UACvC;UAEAH,iBAAiB,CAAEC,KAAK,CAAE,GAAGnC,kBAAkB,CAC9C0B,SAAS,EACTU,aACD,CAAC;QACF;QAEA,OAAOF,iBAAiB;MACzB,CAAC,EACDb,UACD,CAAC;IACF,CAAE,CAAC;EACJ,CAAC,EACD,CAAEb,OAAO,CACV,CAAC;EAED,OAAO,CAAEC,MAAM,EAAEgB,cAAc,EAAEA,cAAc,CAAE;AAClD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["createContext","useMemo","useContext","SidebarControlsContext","SidebarControls","sidebarControls","activeSidebarControl","children","context","createElement","Provider","value","useSidebarControls","useActiveSidebarControl"],"sources":["@wordpress/customize-widgets/src/components/sidebar-controls/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createContext, useMemo, useContext } from '@wordpress/element';\n\nexport const SidebarControlsContext = createContext();\n\nexport default function SidebarControls( {\n\tsidebarControls,\n\tactiveSidebarControl,\n\tchildren,\n} ) {\n\tconst context = useMemo(\n\t\t() => ( {\n\t\t\tsidebarControls,\n\t\t\tactiveSidebarControl,\n\t\t} ),\n\t\t[ sidebarControls, activeSidebarControl ]\n\t);\n\n\treturn (\n\t\t<SidebarControlsContext.Provider value={ context }>\n\t\t\t{ children }\n\t\t</SidebarControlsContext.Provider>\n\t);\n}\n\nexport function useSidebarControls() {\n\tconst { sidebarControls } = useContext( SidebarControlsContext );\n\n\treturn sidebarControls;\n}\n\nexport function useActiveSidebarControl() {\n\tconst { activeSidebarControl } = useContext( SidebarControlsContext );\n\n\treturn activeSidebarControl;\n}\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,aAAa,EAAEC,OAAO,EAAEC,UAAU,QAAQ,oBAAoB;AAEvE,OAAO,MAAMC,sBAAsB,GAAGH,aAAa,CAAC,CAAC;AAErD,eAAe,SAASI,eAAeA,CAAE;EACxCC,eAAe;EACfC,oBAAoB;EACpBC;AACD,CAAC,EAAG;EACH,MAAMC,OAAO,GAAGP,OAAO,CACtB,OAAQ;IACPI,eAAe;IACfC;EACD,CAAC,CAAE,EACH,CAAED,eAAe,EAAEC,oBAAoB,CACxC,CAAC;EAED,OACCG,aAAA,CAACN,sBAAsB,CAACO,QAAQ;IAACC,KAAK,EAAGH;EAAS,GAC/CD,QAC8B,CAAC;AAEpC;AAEA,OAAO,SAASK,kBAAkBA,CAAA,EAAG;EACpC,MAAM;IAAEP;EAAgB,CAAC,GAAGH,UAAU,CAAEC,sBAAuB,CAAC;EAEhE,OAAOE,eAAe;AACvB;AAEA,OAAO,SAASQ,uBAAuBA,CAAA,EAAG;EACzC,MAAM;IAAEP;EAAqB,CAAC,GAAGJ,UAAU,CAAEC,sBAAuB,CAAC;EAErE,OAAOG,oBAAoB;AAC5B"}
|