@wordpress/customize-widgets 5.57.0 → 6.1.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.
Files changed (157) hide show
  1. package/build/components/block-appender/index.cjs +24 -41
  2. package/build/components/block-appender/index.cjs.map +1 -7
  3. package/build/components/block-inspector-button/index.cjs +24 -52
  4. package/build/components/block-inspector-button/index.cjs.map +1 -7
  5. package/build/components/customize-widgets/index.cjs +76 -95
  6. package/build/components/customize-widgets/index.cjs.map +1 -7
  7. package/build/components/customize-widgets/use-clear-selected-block.cjs +58 -67
  8. package/build/components/customize-widgets/use-clear-selected-block.cjs.map +1 -7
  9. package/build/components/error-boundary/index.cjs +115 -155
  10. package/build/components/error-boundary/index.cjs.map +1 -7
  11. package/build/components/focus-control/index.cjs +44 -84
  12. package/build/components/focus-control/index.cjs.map +1 -7
  13. package/build/components/focus-control/use-blocks-focus-control.cjs +28 -49
  14. package/build/components/focus-control/use-blocks-focus-control.cjs.map +1 -7
  15. package/build/components/header/index.cjs +84 -122
  16. package/build/components/header/index.cjs.map +1 -7
  17. package/build/components/inserter/index.cjs +43 -78
  18. package/build/components/inserter/index.cjs.map +1 -7
  19. package/build/components/inserter/use-inserter.cjs +22 -54
  20. package/build/components/inserter/use-inserter.cjs.map +1 -7
  21. package/build/components/keyboard-shortcut-help-modal/config.cjs +88 -85
  22. package/build/components/keyboard-shortcut-help-modal/config.cjs.map +1 -7
  23. package/build/components/keyboard-shortcut-help-modal/dynamic-shortcut.cjs +40 -57
  24. package/build/components/keyboard-shortcut-help-modal/dynamic-shortcut.cjs.map +1 -7
  25. package/build/components/keyboard-shortcut-help-modal/index.cjs +103 -165
  26. package/build/components/keyboard-shortcut-help-modal/index.cjs.map +1 -7
  27. package/build/components/keyboard-shortcut-help-modal/shortcut.cjs +37 -76
  28. package/build/components/keyboard-shortcut-help-modal/shortcut.cjs.map +1 -7
  29. package/build/components/keyboard-shortcuts/index.cjs +70 -100
  30. package/build/components/keyboard-shortcuts/index.cjs.map +1 -7
  31. package/build/components/more-menu/index.cjs +103 -151
  32. package/build/components/more-menu/index.cjs.map +1 -7
  33. package/build/components/sidebar-block-editor/index.cjs +122 -155
  34. package/build/components/sidebar-block-editor/index.cjs.map +1 -7
  35. package/build/components/sidebar-block-editor/sidebar-adapter.cjs +207 -270
  36. package/build/components/sidebar-block-editor/sidebar-adapter.cjs.map +1 -7
  37. package/build/components/sidebar-block-editor/sidebar-editor-provider.cjs +40 -50
  38. package/build/components/sidebar-block-editor/sidebar-editor-provider.cjs.map +1 -7
  39. package/build/components/sidebar-block-editor/use-sidebar-block-editor.cjs +75 -110
  40. package/build/components/sidebar-block-editor/use-sidebar-block-editor.cjs.map +1 -7
  41. package/build/components/sidebar-controls/index.cjs +27 -53
  42. package/build/components/sidebar-controls/index.cjs.map +1 -7
  43. package/build/components/welcome-guide/index.cjs +70 -94
  44. package/build/components/welcome-guide/index.cjs.map +1 -7
  45. package/build/controls/inserter-outer-section.cjs +68 -110
  46. package/build/controls/inserter-outer-section.cjs.map +1 -7
  47. package/build/controls/inspector-section.cjs +57 -90
  48. package/build/controls/inspector-section.cjs.map +1 -7
  49. package/build/controls/sidebar-control.cjs +55 -69
  50. package/build/controls/sidebar-control.cjs.map +1 -7
  51. package/build/controls/sidebar-section.cjs +79 -103
  52. package/build/controls/sidebar-section.cjs.map +1 -7
  53. package/build/filters/index.cjs +8 -5
  54. package/build/filters/move-to-sidebar.cjs +62 -78
  55. package/build/filters/move-to-sidebar.cjs.map +1 -7
  56. package/build/filters/replace-media-upload.cjs +11 -9
  57. package/build/filters/replace-media-upload.cjs.map +1 -7
  58. package/build/filters/wide-widget-display.cjs +20 -20
  59. package/build/filters/wide-widget-display.cjs.map +1 -7
  60. package/build/index.cjs +84 -91
  61. package/build/index.cjs.map +1 -7
  62. package/build/lock-unlock.cjs +10 -35
  63. package/build/lock-unlock.cjs.map +1 -7
  64. package/build/store/actions.cjs +49 -32
  65. package/build/store/actions.cjs.map +1 -7
  66. package/build/store/constants.cjs +12 -29
  67. package/build/store/constants.cjs.map +1 -7
  68. package/build/store/index.cjs +49 -41
  69. package/build/store/index.cjs.map +1 -7
  70. package/build/store/reducer.cjs +20 -33
  71. package/build/store/reducer.cjs.map +1 -7
  72. package/build/store/selectors.cjs +47 -38
  73. package/build/store/selectors.cjs.map +1 -7
  74. package/build/utils.cjs +81 -108
  75. package/build/utils.cjs.map +1 -7
  76. package/build-module/components/block-appender/index.mjs +18 -23
  77. package/build-module/components/block-appender/index.mjs.map +1 -7
  78. package/build-module/components/block-inspector-button/index.mjs +15 -28
  79. package/build-module/components/block-inspector-button/index.mjs.map +1 -7
  80. package/build-module/components/customize-widgets/index.mjs +46 -72
  81. package/build-module/components/customize-widgets/index.mjs.map +1 -7
  82. package/build-module/components/customize-widgets/use-clear-selected-block.mjs +52 -46
  83. package/build-module/components/customize-widgets/use-clear-selected-block.mjs.map +1 -7
  84. package/build-module/components/error-boundary/index.mjs +103 -128
  85. package/build-module/components/error-boundary/index.mjs.map +1 -7
  86. package/build-module/components/focus-control/index.mjs +37 -66
  87. package/build-module/components/focus-control/index.mjs.map +1 -7
  88. package/build-module/components/focus-control/use-blocks-focus-control.mjs +21 -27
  89. package/build-module/components/focus-control/use-blocks-focus-control.mjs.map +1 -7
  90. package/build-module/components/header/index.mjs +55 -92
  91. package/build-module/components/header/index.mjs.map +1 -7
  92. package/build-module/components/inserter/index.mjs +33 -53
  93. package/build-module/components/inserter/index.mjs.map +1 -7
  94. package/build-module/components/inserter/use-inserter.mjs +17 -34
  95. package/build-module/components/inserter/use-inserter.mjs.map +1 -7
  96. package/build-module/components/keyboard-shortcut-help-modal/config.mjs +83 -61
  97. package/build-module/components/keyboard-shortcut-help-modal/config.mjs.map +1 -7
  98. package/build-module/components/keyboard-shortcut-help-modal/dynamic-shortcut.mjs +19 -33
  99. package/build-module/components/keyboard-shortcut-help-modal/dynamic-shortcut.mjs.map +1 -7
  100. package/build-module/components/keyboard-shortcut-help-modal/index.mjs +75 -139
  101. package/build-module/components/keyboard-shortcut-help-modal/index.mjs.map +1 -7
  102. package/build-module/components/keyboard-shortcut-help-modal/shortcut.mjs +31 -55
  103. package/build-module/components/keyboard-shortcut-help-modal/shortcut.mjs.map +1 -7
  104. package/build-module/components/keyboard-shortcuts/index.mjs +62 -79
  105. package/build-module/components/keyboard-shortcuts/index.mjs.map +1 -7
  106. package/build-module/components/more-menu/index.mjs +76 -128
  107. package/build-module/components/more-menu/index.mjs.map +1 -7
  108. package/build-module/components/sidebar-block-editor/index.mjs +86 -128
  109. package/build-module/components/sidebar-block-editor/index.mjs.map +1 -7
  110. package/build-module/components/sidebar-block-editor/sidebar-adapter.mjs +202 -250
  111. package/build-module/components/sidebar-block-editor/sidebar-adapter.mjs.map +1 -7
  112. package/build-module/components/sidebar-block-editor/sidebar-editor-provider.mjs +17 -25
  113. package/build-module/components/sidebar-block-editor/sidebar-editor-provider.mjs.map +1 -7
  114. package/build-module/components/sidebar-block-editor/use-sidebar-block-editor.mjs +54 -86
  115. package/build-module/components/sidebar-block-editor/use-sidebar-block-editor.mjs.map +1 -7
  116. package/build-module/components/sidebar-controls/index.mjs +19 -27
  117. package/build-module/components/sidebar-controls/index.mjs.map +1 -7
  118. package/build-module/components/welcome-guide/index.mjs +62 -71
  119. package/build-module/components/welcome-guide/index.mjs.map +1 -7
  120. package/build-module/controls/inserter-outer-section.mjs +61 -88
  121. package/build-module/controls/inserter-outer-section.mjs.map +1 -7
  122. package/build-module/controls/inspector-section.mjs +52 -70
  123. package/build-module/controls/inspector-section.mjs.map +1 -7
  124. package/build-module/controls/sidebar-control.mjs +33 -45
  125. package/build-module/controls/sidebar-control.mjs.map +1 -7
  126. package/build-module/controls/sidebar-section.mjs +59 -80
  127. package/build-module/controls/sidebar-section.mjs.map +1 -7
  128. package/build-module/filters/index.mjs +0 -2
  129. package/build-module/filters/move-to-sidebar.mjs +52 -79
  130. package/build-module/filters/move-to-sidebar.mjs.map +1 -7
  131. package/build-module/filters/replace-media-upload.mjs +5 -8
  132. package/build-module/filters/replace-media-upload.mjs.map +1 -7
  133. package/build-module/filters/wide-widget-display.mjs +13 -18
  134. package/build-module/filters/wide-widget-display.mjs.map +1 -7
  135. package/build-module/index.mjs +53 -71
  136. package/build-module/index.mjs.map +1 -7
  137. package/build-module/lock-unlock.mjs +5 -10
  138. package/build-module/lock-unlock.mjs.map +1 -7
  139. package/build-module/store/actions.mjs +44 -8
  140. package/build-module/store/actions.mjs.map +1 -7
  141. package/build-module/store/constants.mjs +7 -5
  142. package/build-module/store/constants.mjs.map +1 -7
  143. package/build-module/store/index.mjs +15 -11
  144. package/build-module/store/index.mjs.map +1 -7
  145. package/build-module/store/reducer.mjs +15 -13
  146. package/build-module/store/reducer.mjs.map +1 -7
  147. package/build-module/store/selectors.mjs +41 -13
  148. package/build-module/store/selectors.mjs.map +1 -7
  149. package/build-module/utils.mjs +74 -82
  150. package/build-module/utils.mjs.map +1 -7
  151. package/package.json +30 -31
  152. package/src/components/customize-widgets/index.jsx +5 -2
  153. package/src/components/customize-widgets/use-clear-selected-block.js +2 -1
  154. package/src/components/welcome-guide/index.jsx +6 -2
  155. package/CHANGELOG.md +0 -289
  156. package/build/filters/index.cjs.map +0 -7
  157. package/build-module/filters/index.mjs.map +0 -7
@@ -1,259 +1,211 @@
1
- // packages/customize-widgets/src/components/sidebar-block-editor/sidebar-adapter.js
2
1
  import { settingIdToWidgetId } from "../../utils.mjs";
3
- var { wp } = window;
2
+ // packages/customize-widgets/src/components/sidebar-block-editor/sidebar-adapter.js
3
+ const { wp } = window;
4
4
  function parseWidgetId(widgetId) {
5
- const matches = widgetId.match(/^(.+)-(\d+)$/);
6
- if (matches) {
7
- return {
8
- idBase: matches[1],
9
- number: parseInt(matches[2], 10)
10
- };
11
- }
12
- return { idBase: widgetId };
5
+ const matches = widgetId.match(/^(.+)-(\d+)$/);
6
+ if (matches) return {
7
+ idBase: matches[1],
8
+ number: parseInt(matches[2], 10)
9
+ };
10
+ return { idBase: widgetId };
13
11
  }
14
12
  function widgetIdToSettingId(widgetId) {
15
- const { idBase, number } = parseWidgetId(widgetId);
16
- if (number) {
17
- return `widget_${idBase}[${number}]`;
18
- }
19
- return `widget_${idBase}`;
13
+ const { idBase, number } = parseWidgetId(widgetId);
14
+ if (number) return `widget_${idBase}[${number}]`;
15
+ return `widget_${idBase}`;
20
16
  }
17
+ /**
18
+ * This is a custom debounce function to call different callbacks depending on
19
+ * whether it's the _leading_ call or not.
20
+ *
21
+ * @param {Function} leading The callback that gets called first.
22
+ * @param {Function} callback The callback that gets called after the first time.
23
+ * @param {number} timeout The debounced time in milliseconds.
24
+ * @return {Function} The debounced function.
25
+ */
21
26
  function debounce(leading, callback, timeout) {
22
- let isLeading = false;
23
- let timerID;
24
- function debounced(...args) {
25
- const result = (isLeading ? callback : leading).apply(this, args);
26
- isLeading = true;
27
- clearTimeout(timerID);
28
- timerID = setTimeout(() => {
29
- isLeading = false;
30
- }, timeout);
31
- return result;
32
- }
33
- debounced.cancel = () => {
34
- isLeading = false;
35
- clearTimeout(timerID);
36
- };
37
- return debounced;
27
+ let isLeading = false;
28
+ let timerID;
29
+ function debounced(...args) {
30
+ const result = (isLeading ? callback : leading).apply(this, args);
31
+ isLeading = true;
32
+ clearTimeout(timerID);
33
+ timerID = setTimeout(() => {
34
+ isLeading = false;
35
+ }, timeout);
36
+ return result;
37
+ }
38
+ debounced.cancel = () => {
39
+ isLeading = false;
40
+ clearTimeout(timerID);
41
+ };
42
+ return debounced;
38
43
  }
39
44
  var SidebarAdapter = class {
40
- constructor(setting, api) {
41
- this.setting = setting;
42
- this.api = api;
43
- this.locked = false;
44
- this.widgetsCache = /* @__PURE__ */ new WeakMap();
45
- this.subscribers = /* @__PURE__ */ new Set();
46
- this.history = [
47
- this._getWidgetIds().map(
48
- (widgetId) => this.getWidget(widgetId)
49
- )
50
- ];
51
- this.historyIndex = 0;
52
- this.historySubscribers = /* @__PURE__ */ new Set();
53
- this._debounceSetHistory = debounce(
54
- this._pushHistory,
55
- this._replaceHistory,
56
- 1e3
57
- );
58
- this.setting.bind(this._handleSettingChange.bind(this));
59
- this.api.bind("change", this._handleAllSettingsChange.bind(this));
60
- this.undo = this.undo.bind(this);
61
- this.redo = this.redo.bind(this);
62
- this.save = this.save.bind(this);
63
- }
64
- subscribe(callback) {
65
- this.subscribers.add(callback);
66
- return () => {
67
- this.subscribers.delete(callback);
68
- };
69
- }
70
- getWidgets() {
71
- return this.history[this.historyIndex];
72
- }
73
- _emit(...args) {
74
- for (const callback of this.subscribers) {
75
- callback(...args);
76
- }
77
- }
78
- _getWidgetIds() {
79
- return this.setting.get();
80
- }
81
- _pushHistory() {
82
- this.history = [
83
- ...this.history.slice(0, this.historyIndex + 1),
84
- this._getWidgetIds().map(
85
- (widgetId) => this.getWidget(widgetId)
86
- )
87
- ];
88
- this.historyIndex += 1;
89
- this.historySubscribers.forEach((listener) => listener());
90
- }
91
- _replaceHistory() {
92
- this.history[this.historyIndex] = this._getWidgetIds().map(
93
- (widgetId) => this.getWidget(widgetId)
94
- );
95
- }
96
- _handleSettingChange() {
97
- if (this.locked) {
98
- return;
99
- }
100
- const prevWidgets = this.getWidgets();
101
- this._pushHistory();
102
- this._emit(prevWidgets, this.getWidgets());
103
- }
104
- _handleAllSettingsChange(setting) {
105
- if (this.locked) {
106
- return;
107
- }
108
- if (!setting.id.startsWith("widget_")) {
109
- return;
110
- }
111
- const widgetId = settingIdToWidgetId(setting.id);
112
- if (!this.setting.get().includes(widgetId)) {
113
- return;
114
- }
115
- const prevWidgets = this.getWidgets();
116
- this._pushHistory();
117
- this._emit(prevWidgets, this.getWidgets());
118
- }
119
- _createWidget(widget) {
120
- const widgetModel = wp.customize.Widgets.availableWidgets.findWhere({
121
- id_base: widget.idBase
122
- });
123
- let number = widget.number;
124
- if (widgetModel.get("is_multi") && !number) {
125
- widgetModel.set(
126
- "multi_number",
127
- widgetModel.get("multi_number") + 1
128
- );
129
- number = widgetModel.get("multi_number");
130
- }
131
- const settingId = number ? `widget_${widget.idBase}[${number}]` : `widget_${widget.idBase}`;
132
- const settingArgs = {
133
- transport: wp.customize.Widgets.data.selectiveRefreshableWidgets[widgetModel.get("id_base")] ? "postMessage" : "refresh",
134
- previewer: this.setting.previewer
135
- };
136
- const setting = this.api.create(
137
- settingId,
138
- settingId,
139
- "",
140
- settingArgs
141
- );
142
- setting.set(widget.instance);
143
- const widgetId = settingIdToWidgetId(settingId);
144
- return widgetId;
145
- }
146
- _removeWidget(widget) {
147
- const settingId = widgetIdToSettingId(widget.id);
148
- const setting = this.api(settingId);
149
- if (setting) {
150
- const instance = setting.get();
151
- this.widgetsCache.delete(instance);
152
- }
153
- this.api.remove(settingId);
154
- }
155
- _updateWidget(widget) {
156
- const prevWidget = this.getWidget(widget.id);
157
- if (prevWidget === widget) {
158
- return widget.id;
159
- }
160
- if (prevWidget.idBase && widget.idBase && prevWidget.idBase === widget.idBase) {
161
- const settingId = widgetIdToSettingId(widget.id);
162
- this.api(settingId).set(widget.instance);
163
- return widget.id;
164
- }
165
- this._removeWidget(widget);
166
- return this._createWidget(widget);
167
- }
168
- getWidget(widgetId) {
169
- if (!widgetId) {
170
- return null;
171
- }
172
- const { idBase, number } = parseWidgetId(widgetId);
173
- const settingId = widgetIdToSettingId(widgetId);
174
- const setting = this.api(settingId);
175
- if (!setting) {
176
- return null;
177
- }
178
- const instance = setting.get();
179
- if (this.widgetsCache.has(instance)) {
180
- return this.widgetsCache.get(instance);
181
- }
182
- const widget = {
183
- id: widgetId,
184
- idBase,
185
- number,
186
- instance
187
- };
188
- this.widgetsCache.set(instance, widget);
189
- return widget;
190
- }
191
- _updateWidgets(nextWidgets) {
192
- this.locked = true;
193
- const addedWidgetIds = [];
194
- const nextWidgetIds = nextWidgets.map((nextWidget) => {
195
- if (nextWidget.id && this.getWidget(nextWidget.id)) {
196
- addedWidgetIds.push(null);
197
- return this._updateWidget(nextWidget);
198
- }
199
- const widgetId = this._createWidget(nextWidget);
200
- addedWidgetIds.push(widgetId);
201
- return widgetId;
202
- });
203
- const deletedWidgets = this.getWidgets().filter(
204
- (widget) => !nextWidgetIds.includes(widget.id)
205
- );
206
- deletedWidgets.forEach((widget) => this._removeWidget(widget));
207
- this.setting.set(nextWidgetIds);
208
- this.locked = false;
209
- return addedWidgetIds;
210
- }
211
- setWidgets(nextWidgets) {
212
- const addedWidgetIds = this._updateWidgets(nextWidgets);
213
- this._debounceSetHistory();
214
- return addedWidgetIds;
215
- }
216
- /**
217
- * Undo/Redo related features
218
- */
219
- hasUndo() {
220
- return this.historyIndex > 0;
221
- }
222
- hasRedo() {
223
- return this.historyIndex < this.history.length - 1;
224
- }
225
- _seek(historyIndex) {
226
- const currentWidgets = this.getWidgets();
227
- this.historyIndex = historyIndex;
228
- const widgets = this.history[this.historyIndex];
229
- this._updateWidgets(widgets);
230
- this._emit(currentWidgets, this.getWidgets());
231
- this.historySubscribers.forEach((listener) => listener());
232
- this._debounceSetHistory.cancel();
233
- }
234
- undo() {
235
- if (!this.hasUndo()) {
236
- return;
237
- }
238
- this._seek(this.historyIndex - 1);
239
- }
240
- redo() {
241
- if (!this.hasRedo()) {
242
- return;
243
- }
244
- this._seek(this.historyIndex + 1);
245
- }
246
- subscribeHistory(listener) {
247
- this.historySubscribers.add(listener);
248
- return () => {
249
- this.historySubscribers.delete(listener);
250
- };
251
- }
252
- save() {
253
- this.api.previewer.save();
254
- }
255
- };
256
- export {
257
- SidebarAdapter as default
45
+ constructor(setting, api) {
46
+ this.setting = setting;
47
+ this.api = api;
48
+ this.locked = false;
49
+ this.widgetsCache = /* @__PURE__ */ new WeakMap();
50
+ this.subscribers = /* @__PURE__ */ new Set();
51
+ this.history = [this._getWidgetIds().map((widgetId) => this.getWidget(widgetId))];
52
+ this.historyIndex = 0;
53
+ this.historySubscribers = /* @__PURE__ */ new Set();
54
+ this._debounceSetHistory = debounce(this._pushHistory, this._replaceHistory, 1e3);
55
+ this.setting.bind(this._handleSettingChange.bind(this));
56
+ this.api.bind("change", this._handleAllSettingsChange.bind(this));
57
+ this.undo = this.undo.bind(this);
58
+ this.redo = this.redo.bind(this);
59
+ this.save = this.save.bind(this);
60
+ }
61
+ subscribe(callback) {
62
+ this.subscribers.add(callback);
63
+ return () => {
64
+ this.subscribers.delete(callback);
65
+ };
66
+ }
67
+ getWidgets() {
68
+ return this.history[this.historyIndex];
69
+ }
70
+ _emit(...args) {
71
+ for (const callback of this.subscribers) callback(...args);
72
+ }
73
+ _getWidgetIds() {
74
+ return this.setting.get();
75
+ }
76
+ _pushHistory() {
77
+ this.history = [...this.history.slice(0, this.historyIndex + 1), this._getWidgetIds().map((widgetId) => this.getWidget(widgetId))];
78
+ this.historyIndex += 1;
79
+ this.historySubscribers.forEach((listener) => listener());
80
+ }
81
+ _replaceHistory() {
82
+ this.history[this.historyIndex] = this._getWidgetIds().map((widgetId) => this.getWidget(widgetId));
83
+ }
84
+ _handleSettingChange() {
85
+ if (this.locked) return;
86
+ const prevWidgets = this.getWidgets();
87
+ this._pushHistory();
88
+ this._emit(prevWidgets, this.getWidgets());
89
+ }
90
+ _handleAllSettingsChange(setting) {
91
+ if (this.locked) return;
92
+ if (!setting.id.startsWith("widget_")) return;
93
+ const widgetId = settingIdToWidgetId(setting.id);
94
+ if (!this.setting.get().includes(widgetId)) return;
95
+ const prevWidgets = this.getWidgets();
96
+ this._pushHistory();
97
+ this._emit(prevWidgets, this.getWidgets());
98
+ }
99
+ _createWidget(widget) {
100
+ const widgetModel = wp.customize.Widgets.availableWidgets.findWhere({ id_base: widget.idBase });
101
+ let number = widget.number;
102
+ if (widgetModel.get("is_multi") && !number) {
103
+ widgetModel.set("multi_number", widgetModel.get("multi_number") + 1);
104
+ number = widgetModel.get("multi_number");
105
+ }
106
+ const settingId = number ? `widget_${widget.idBase}[${number}]` : `widget_${widget.idBase}`;
107
+ const settingArgs = {
108
+ transport: wp.customize.Widgets.data.selectiveRefreshableWidgets[widgetModel.get("id_base")] ? "postMessage" : "refresh",
109
+ previewer: this.setting.previewer
110
+ };
111
+ this.api.create(settingId, settingId, "", settingArgs).set(widget.instance);
112
+ return settingIdToWidgetId(settingId);
113
+ }
114
+ _removeWidget(widget) {
115
+ const settingId = widgetIdToSettingId(widget.id);
116
+ const setting = this.api(settingId);
117
+ if (setting) {
118
+ const instance = setting.get();
119
+ this.widgetsCache.delete(instance);
120
+ }
121
+ this.api.remove(settingId);
122
+ }
123
+ _updateWidget(widget) {
124
+ const prevWidget = this.getWidget(widget.id);
125
+ if (prevWidget === widget) return widget.id;
126
+ if (prevWidget.idBase && widget.idBase && prevWidget.idBase === widget.idBase) {
127
+ const settingId = widgetIdToSettingId(widget.id);
128
+ this.api(settingId).set(widget.instance);
129
+ return widget.id;
130
+ }
131
+ this._removeWidget(widget);
132
+ return this._createWidget(widget);
133
+ }
134
+ getWidget(widgetId) {
135
+ if (!widgetId) return null;
136
+ const { idBase, number } = parseWidgetId(widgetId);
137
+ const settingId = widgetIdToSettingId(widgetId);
138
+ const setting = this.api(settingId);
139
+ if (!setting) return null;
140
+ const instance = setting.get();
141
+ if (this.widgetsCache.has(instance)) return this.widgetsCache.get(instance);
142
+ const widget = {
143
+ id: widgetId,
144
+ idBase,
145
+ number,
146
+ instance
147
+ };
148
+ this.widgetsCache.set(instance, widget);
149
+ return widget;
150
+ }
151
+ _updateWidgets(nextWidgets) {
152
+ this.locked = true;
153
+ const addedWidgetIds = [];
154
+ const nextWidgetIds = nextWidgets.map((nextWidget) => {
155
+ if (nextWidget.id && this.getWidget(nextWidget.id)) {
156
+ addedWidgetIds.push(null);
157
+ return this._updateWidget(nextWidget);
158
+ }
159
+ const widgetId = this._createWidget(nextWidget);
160
+ addedWidgetIds.push(widgetId);
161
+ return widgetId;
162
+ });
163
+ this.getWidgets().filter((widget) => !nextWidgetIds.includes(widget.id)).forEach((widget) => this._removeWidget(widget));
164
+ this.setting.set(nextWidgetIds);
165
+ this.locked = false;
166
+ return addedWidgetIds;
167
+ }
168
+ setWidgets(nextWidgets) {
169
+ const addedWidgetIds = this._updateWidgets(nextWidgets);
170
+ this._debounceSetHistory();
171
+ return addedWidgetIds;
172
+ }
173
+ /**
174
+ * Undo/Redo related features
175
+ */
176
+ hasUndo() {
177
+ return this.historyIndex > 0;
178
+ }
179
+ hasRedo() {
180
+ return this.historyIndex < this.history.length - 1;
181
+ }
182
+ _seek(historyIndex) {
183
+ const currentWidgets = this.getWidgets();
184
+ this.historyIndex = historyIndex;
185
+ const widgets = this.history[this.historyIndex];
186
+ this._updateWidgets(widgets);
187
+ this._emit(currentWidgets, this.getWidgets());
188
+ this.historySubscribers.forEach((listener) => listener());
189
+ this._debounceSetHistory.cancel();
190
+ }
191
+ undo() {
192
+ if (!this.hasUndo()) return;
193
+ this._seek(this.historyIndex - 1);
194
+ }
195
+ redo() {
196
+ if (!this.hasRedo()) return;
197
+ this._seek(this.historyIndex + 1);
198
+ }
199
+ subscribeHistory(listener) {
200
+ this.historySubscribers.add(listener);
201
+ return () => {
202
+ this.historySubscribers.delete(listener);
203
+ };
204
+ }
205
+ save() {
206
+ this.api.previewer.save();
207
+ }
258
208
  };
259
- //# sourceMappingURL=sidebar-adapter.mjs.map
209
+ export { SidebarAdapter as default };
210
+
211
+ //# sourceMappingURL=sidebar-adapter.mjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/components/sidebar-block-editor/sidebar-adapter.js"],
4
- "sourcesContent": ["import { 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"],
5
- "mappings": ";AAAA,SAAS,2BAA2B;AAEpC,IAAM,EAAE,GAAG,IAAI;AAEf,SAAS,cAAe,UAAW;AAClC,QAAM,UAAU,SAAS,MAAO,cAAe;AAC/C,MAAK,SAAU;AACd,WAAO;AAAA,MACN,QAAQ,QAAS,CAAE;AAAA,MACnB,QAAQ,SAAU,QAAS,CAAE,GAAG,EAAG;AAAA,IACpC;AAAA,EACD;AAGA,SAAO,EAAE,QAAQ,SAAS;AAC3B;AAEA,SAAS,oBAAqB,UAAW;AACxC,QAAM,EAAE,QAAQ,OAAO,IAAI,cAAe,QAAS;AACnD,MAAK,QAAS;AACb,WAAO,UAAW,MAAO,IAAK,MAAO;AAAA,EACtC;AAEA,SAAO,UAAW,MAAO;AAC1B;AAWA,SAAS,SAAU,SAAS,UAAU,SAAU;AAC/C,MAAI,YAAY;AAChB,MAAI;AAEJ,WAAS,aAAc,MAAO;AAC7B,UAAM,UAAW,YAAY,WAAW,SAAU,MAAO,MAAM,IAAK;AAEpE,gBAAY;AAEZ,iBAAc,OAAQ;AAEtB,cAAU,WAAY,MAAM;AAC3B,kBAAY;AAAA,IACb,GAAG,OAAQ;AAEX,WAAO;AAAA,EACR;AAEA,YAAU,SAAS,MAAM;AACxB,gBAAY;AACZ,iBAAc,OAAQ;AAAA,EACvB;AAEA,SAAO;AACR;AAEA,IAAqB,iBAArB,MAAoC;AAAA,EACnC,YAAa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eAAe,CAAE;AAAA,EACnC;AAAA,EAEA,OAAO;AACN,QAAK,CAAE,KAAK,QAAQ,GAAI;AACvB;AAAA,IACD;AAEA,SAAK,MAAO,KAAK,eAAe,CAAE;AAAA,EACnC;AAAA,EAEA,iBAAkB,UAAW;AAC5B,SAAK,mBAAmB,IAAK,QAAS;AAEtC,WAAO,MAAM;AACZ,WAAK,mBAAmB,OAAQ,QAAS;AAAA,IAC1C;AAAA,EACD;AAAA,EAEA,OAAO;AACN,SAAK,IAAI,UAAU,KAAK;AAAA,EACzB;AACD;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"sidebar-adapter.mjs","names":[],"sources":["../../../src/components/sidebar-block-editor/sidebar-adapter.js"],"sourcesContent":["import { 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":";;AAEA,MAAM,EAAE,OAAO;AAEf,SAAS,cAA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EACN,IAAK,CAAE,KAAK,QAAQ,GACnB;EAGD,KAAK,MAAO,KAAK,eAAe,CAAE;CACnC;CAEA,iBAAkB,UAAW;EAC5B,KAAK,mBAAmB,IAAK,QAAS;EAEtC,aAAa;GACZ,KAAK,mBAAmB,OAAQ,QAAS;EAC1C;CACD;CAEA,OAAO;EACN,KAAK,IAAI,UAAU,KAAK;CACzB;AACD"}
@@ -1,30 +1,22 @@
1
- // packages/customize-widgets/src/components/sidebar-block-editor/sidebar-editor-provider.jsx
2
- import { privateApis as blockEditorPrivateApis } from "@wordpress/block-editor";
1
+ import { privateApis } from "@wordpress/block-editor";
3
2
  import useSidebarBlockEditor from "./use-sidebar-block-editor.mjs";
4
3
  import useBlocksFocusControl from "../focus-control/use-blocks-focus-control.mjs";
5
4
  import { unlock } from "../../lock-unlock.mjs";
6
5
  import { jsx } from "react/jsx-runtime";
7
- var { ExperimentalBlockEditorProvider } = unlock(blockEditorPrivateApis);
8
- function SidebarEditorProvider({
9
- sidebar,
10
- settings,
11
- children
12
- }) {
13
- const [blocks, onInput, onChange] = useSidebarBlockEditor(sidebar);
14
- useBlocksFocusControl(blocks);
15
- return /* @__PURE__ */ jsx(
16
- ExperimentalBlockEditorProvider,
17
- {
18
- value: blocks,
19
- onInput,
20
- onChange,
21
- settings,
22
- useSubRegistry: false,
23
- children
24
- }
25
- );
6
+ // packages/customize-widgets/src/components/sidebar-block-editor/sidebar-editor-provider.jsx
7
+ const { ExperimentalBlockEditorProvider } = unlock(privateApis);
8
+ function SidebarEditorProvider({ sidebar, settings, children }) {
9
+ const [blocks, onInput, onChange] = useSidebarBlockEditor(sidebar);
10
+ useBlocksFocusControl(blocks);
11
+ return /* @__PURE__ */ jsx(ExperimentalBlockEditorProvider, {
12
+ value: blocks,
13
+ onInput,
14
+ onChange,
15
+ settings,
16
+ useSubRegistry: false,
17
+ children
18
+ });
26
19
  }
27
- export {
28
- SidebarEditorProvider as default
29
- };
30
- //# sourceMappingURL=sidebar-editor-provider.mjs.map
20
+ export { SidebarEditorProvider as default };
21
+
22
+ //# sourceMappingURL=sidebar-editor-provider.mjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/components/sidebar-block-editor/sidebar-editor-provider.jsx"],
4
- "sourcesContent": ["import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';\nimport useSidebarBlockEditor from './use-sidebar-block-editor';\nimport useBlocksFocusControl from '../focus-control/use-blocks-focus-control';\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"],
5
- "mappings": ";AAAA,SAAS,eAAe,8BAA8B;AACtD,OAAO,2BAA2B;AAClC,OAAO,2BAA2B;AAClC,SAAS,cAAc;AAcrB;AAZF,IAAM,EAAE,gCAAgC,IAAI,OAAQ,sBAAuB;AAE5D,SAAR,sBAAwC;AAAA,EAC9C;AAAA,EACA;AAAA,EACA;AACD,GAAI;AACH,QAAM,CAAE,QAAQ,SAAS,QAAS,IAAI,sBAAuB,OAAQ;AAErE,wBAAuB,MAAO;AAE9B,SACC;AAAA,IAAC;AAAA;AAAA,MACA,OAAQ;AAAA,MACR;AAAA,MACA;AAAA,MACA;AAAA,MACA,gBAAiB;AAAA,MAEf;AAAA;AAAA,EACH;AAEF;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"sidebar-editor-provider.mjs","names":["blockEditorPrivateApis"],"sources":["../../../src/components/sidebar-block-editor/sidebar-editor-provider.jsx"],"sourcesContent":["import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';\nimport useSidebarBlockEditor from './use-sidebar-block-editor';\nimport useBlocksFocusControl from '../focus-control/use-blocks-focus-control';\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":";;;;;;AAKA,MAAM,EAAE,oCAAoC,OAAQA,WAAuB;AAE3E,SAAwB,sBAAuB,EAC9C,SACA,UACA,YACG;CACH,MAAM,CAAE,QAAQ,SAAS,YAAa,sBAAuB,OAAQ;CAErE,sBAAuB,MAAO;CAE9B,OACC,oBAAC,iCAAD;EACC,OAAQ;EACE;EACC;EACA;EACX,gBAAiB;EAEf;CAC8B,CAAA;AAEnC"}