@elementor/editor-app-bar 0.3.0 → 0.4.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 (31) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/index.d.ts +27 -42
  3. package/dist/index.js +73 -88
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.mjs +75 -90
  6. package/dist/index.mjs.map +1 -1
  7. package/package.json +5 -5
  8. package/src/components/locations/__tests__/locations-components.test.tsx +1 -1
  9. package/src/components/locations/__tests__/menus.test.tsx +4 -4
  10. package/src/components/locations/page-indication-location.tsx +2 -3
  11. package/src/components/locations/primary-action-location.tsx +2 -3
  12. package/src/components/locations/responsive-location.tsx +2 -3
  13. package/src/extensions/documents-indicator/index.ts +1 -1
  14. package/src/extensions/documents-preview/index.ts +1 -1
  15. package/src/extensions/documents-save/components/__tests__/primary-action-menu.test.tsx +2 -2
  16. package/src/extensions/documents-save/index.ts +3 -3
  17. package/src/extensions/elements/index.ts +1 -1
  18. package/src/extensions/finder/index.ts +1 -1
  19. package/src/extensions/help/index.ts +1 -1
  20. package/src/extensions/history/index.ts +1 -1
  21. package/src/extensions/keyboard-shortcuts/index.ts +1 -1
  22. package/src/extensions/site-settings/index.ts +2 -2
  23. package/src/extensions/structure/index.ts +1 -1
  24. package/src/extensions/theme-builder/index.ts +1 -1
  25. package/src/extensions/user-preferences/index.ts +1 -1
  26. package/src/extensions/wordpress/index.ts +1 -1
  27. package/src/init.ts +1 -1
  28. package/src/locations/__tests__/menus.test.tsx +15 -30
  29. package/src/locations/index.ts +19 -21
  30. package/src/locations/menus.tsx +57 -69
  31. package/src/locations/consts.ts +0 -4
package/CHANGELOG.md CHANGED
@@ -3,6 +3,17 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [0.4.0](https://github.com/elementor/elementor-packages/compare/@elementor/editor-app-bar@0.3.0...@elementor/editor-app-bar@0.4.0) (2023-05-21)
7
+
8
+
9
+ ### Features
10
+
11
+ * **locations:** change api to support props for slots [ED-10730] ([#38](https://github.com/elementor/elementor-packages/issues/38)) ([44bec3c](https://github.com/elementor/elementor-packages/commit/44bec3cda1020037ba7105c6f05ce4baa8e3b376))
12
+
13
+
14
+
15
+
16
+
6
17
  # 0.3.0 (2023-05-16)
7
18
 
8
19
 
package/dist/index.d.ts CHANGED
@@ -28,27 +28,12 @@ type Props = {
28
28
  target?: string;
29
29
  };
30
30
 
31
- declare const injectIntoPageIndication: ({ filler, name, options }: Omit<{
32
- location: string;
33
- filler: _elementor_locations.Filler;
34
- name: string;
35
- options?: _elementor_locations.InjectionOptions | undefined;
36
- }, "location">) => void;
37
- declare const injectIntoResponsive: ({ filler, name, options }: Omit<{
38
- location: string;
39
- filler: _elementor_locations.Filler;
40
- name: string;
41
- options?: _elementor_locations.InjectionOptions | undefined;
42
- }, "location">) => void;
43
- declare const injectIntoPrimaryAction: ({ filler, name, options }: Omit<{
44
- location: string;
45
- filler: _elementor_locations.Filler;
46
- name: string;
47
- options?: _elementor_locations.InjectionOptions | undefined;
48
- }, "location">) => void;
31
+ declare const injectIntoPageIndication: (args: _elementor_locations.InjectArgs<_elementor_locations.EmptyObject>) => void;
32
+ declare const injectIntoResponsive: (args: _elementor_locations.InjectArgs<_elementor_locations.EmptyObject>) => void;
33
+ declare const injectIntoPrimaryAction: (args: _elementor_locations.InjectArgs<_elementor_locations.EmptyObject>) => void;
49
34
  declare const mainMenu: {
50
- registerAction: ({ group, name, overwrite, priority, ...args }: {
51
- name: string;
35
+ registerAction: (args: {
36
+ id: string;
52
37
  group?: ("default" | "exits") | undefined;
53
38
  priority?: number | undefined;
54
39
  overwrite?: boolean | undefined;
@@ -59,8 +44,8 @@ declare const mainMenu: {
59
44
  useProps: () => Props$2;
60
45
  props?: undefined;
61
46
  })) => void;
62
- registerToggleAction: ({ group, name, overwrite, priority, ...args }: {
63
- name: string;
47
+ registerToggleAction: (args: {
48
+ id: string;
64
49
  group?: ("default" | "exits") | undefined;
65
50
  priority?: number | undefined;
66
51
  overwrite?: boolean | undefined;
@@ -71,8 +56,8 @@ declare const mainMenu: {
71
56
  useProps: () => Props$1;
72
57
  props?: undefined;
73
58
  })) => void;
74
- registerLink: ({ group, name, overwrite, priority, ...args }: {
75
- name: string;
59
+ registerLink: (args: {
60
+ id: string;
76
61
  group?: ("default" | "exits") | undefined;
77
62
  priority?: number | undefined;
78
63
  overwrite?: boolean | undefined;
@@ -95,8 +80,8 @@ declare const mainMenu: {
95
80
  };
96
81
  };
97
82
  declare const toolsMenu: {
98
- registerAction: ({ group, name, overwrite, priority, ...args }: {
99
- name: string;
83
+ registerAction: (args: {
84
+ id: string;
100
85
  group?: "default" | undefined;
101
86
  priority?: number | undefined;
102
87
  overwrite?: boolean | undefined;
@@ -107,8 +92,8 @@ declare const toolsMenu: {
107
92
  useProps: () => Props$2;
108
93
  props?: undefined;
109
94
  })) => void;
110
- registerToggleAction: ({ group, name, overwrite, priority, ...args }: {
111
- name: string;
95
+ registerToggleAction: (args: {
96
+ id: string;
112
97
  group?: "default" | undefined;
113
98
  priority?: number | undefined;
114
99
  overwrite?: boolean | undefined;
@@ -119,8 +104,8 @@ declare const toolsMenu: {
119
104
  useProps: () => Props$1;
120
105
  props?: undefined;
121
106
  })) => void;
122
- registerLink: ({ group, name, overwrite, priority, ...args }: {
123
- name: string;
107
+ registerLink: (args: {
108
+ id: string;
124
109
  group?: "default" | undefined;
125
110
  priority?: number | undefined;
126
111
  overwrite?: boolean | undefined;
@@ -139,8 +124,8 @@ declare const toolsMenu: {
139
124
  };
140
125
  };
141
126
  declare const utilitiesMenu: {
142
- registerAction: ({ group, name, overwrite, priority, ...args }: {
143
- name: string;
127
+ registerAction: (args: {
128
+ id: string;
144
129
  group?: "default" | undefined;
145
130
  priority?: number | undefined;
146
131
  overwrite?: boolean | undefined;
@@ -151,8 +136,8 @@ declare const utilitiesMenu: {
151
136
  useProps: () => Props$2;
152
137
  props?: undefined;
153
138
  })) => void;
154
- registerToggleAction: ({ group, name, overwrite, priority, ...args }: {
155
- name: string;
139
+ registerToggleAction: (args: {
140
+ id: string;
156
141
  group?: "default" | undefined;
157
142
  priority?: number | undefined;
158
143
  overwrite?: boolean | undefined;
@@ -163,8 +148,8 @@ declare const utilitiesMenu: {
163
148
  useProps: () => Props$1;
164
149
  props?: undefined;
165
150
  })) => void;
166
- registerLink: ({ group, name, overwrite, priority, ...args }: {
167
- name: string;
151
+ registerLink: (args: {
152
+ id: string;
168
153
  group?: "default" | undefined;
169
154
  priority?: number | undefined;
170
155
  overwrite?: boolean | undefined;
@@ -183,8 +168,8 @@ declare const utilitiesMenu: {
183
168
  };
184
169
  };
185
170
  declare const documentOptionsMenu: {
186
- registerAction: ({ group, name, overwrite, priority, ...args }: {
187
- name: string;
171
+ registerAction: (args: {
172
+ id: string;
188
173
  group?: ("default" | "save") | undefined;
189
174
  priority?: number | undefined;
190
175
  overwrite?: boolean | undefined;
@@ -195,8 +180,8 @@ declare const documentOptionsMenu: {
195
180
  useProps: () => Props$2;
196
181
  props?: undefined;
197
182
  })) => void;
198
- registerToggleAction: ({ group, name, overwrite, priority, ...args }: {
199
- name: string;
183
+ registerToggleAction: (args: {
184
+ id: string;
200
185
  group?: ("default" | "save") | undefined;
201
186
  priority?: number | undefined;
202
187
  overwrite?: boolean | undefined;
@@ -207,8 +192,8 @@ declare const documentOptionsMenu: {
207
192
  useProps: () => Props$1;
208
193
  props?: undefined;
209
194
  })) => void;
210
- registerLink: ({ group, name, overwrite, priority, ...args }: {
211
- name: string;
195
+ registerLink: (args: {
196
+ id: string;
212
197
  group?: ("default" | "save") | undefined;
213
198
  priority?: number | undefined;
214
199
  overwrite?: boolean | undefined;
package/dist/index.js CHANGED
@@ -149,30 +149,30 @@ function Link({ icon: Icon, title, visible = true, ...props }) {
149
149
  }
150
150
 
151
151
  // src/locations/menus.tsx
152
- function createMenu({ name: menuName, groups = [] }) {
152
+ function createMenu(groups = []) {
153
153
  const menuGroups = [
154
154
  ...groups,
155
155
  "default"
156
156
  ];
157
- const registerAction = createRegisterMenuItem({
158
- menuName,
159
- menuGroups,
160
- component: Action
161
- });
162
- const registerToggleAction = createRegisterMenuItem({
163
- menuName,
164
- menuGroups,
165
- component: ToggleAction
166
- });
167
- const registerLink = createRegisterMenuItem({
168
- menuName,
169
- menuGroups,
170
- component: Link
171
- });
172
- const useMenuItems5 = createUseMenuItems({
173
- menuName,
174
- menuGroups
175
- });
157
+ const locations = menuGroups.reduce(
158
+ (carry, group) => ({
159
+ ...carry,
160
+ [group]: (0, import_locations.createLocation)()
161
+ }),
162
+ {}
163
+ );
164
+ const [
165
+ registerAction,
166
+ registerToggleAction,
167
+ registerLink
168
+ ] = [Action, ToggleAction, Link].map(
169
+ (Component) => createRegisterMenuItem({
170
+ locations,
171
+ menuGroups,
172
+ component: Component
173
+ })
174
+ );
175
+ const useMenuItems5 = createUseMenuItems(locations);
176
176
  return {
177
177
  registerAction,
178
178
  registerToggleAction,
@@ -180,8 +180,8 @@ function createMenu({ name: menuName, groups = [] }) {
180
180
  useMenuItems: useMenuItems5
181
181
  };
182
182
  }
183
- function createRegisterMenuItem({ menuName, menuGroups, component }) {
184
- return ({ group = "default", name, overwrite, priority, ...args }) => {
183
+ function createRegisterMenuItem({ locations, menuGroups, component }) {
184
+ return ({ group = "default", id, overwrite, priority, ...args }) => {
185
185
  if (!menuGroups.includes(group)) {
186
186
  return;
187
187
  }
@@ -191,10 +191,8 @@ function createRegisterMenuItem({ menuName, menuGroups, component }) {
191
191
  const componentProps = useProps();
192
192
  return /* @__PURE__ */ React8.createElement(Component, { ...props, ...componentProps });
193
193
  };
194
- const location = getMenuLocationId(menuName, group);
195
- (0, import_locations.inject)({
196
- location,
197
- name,
194
+ locations[group].inject({
195
+ id,
198
196
  filler: Filler,
199
197
  options: {
200
198
  priority,
@@ -203,54 +201,44 @@ function createRegisterMenuItem({ menuName, menuGroups, component }) {
203
201
  });
204
202
  };
205
203
  }
206
- function createUseMenuItems({ menuName, menuGroups }) {
207
- const locations = menuGroups.map((group) => getMenuLocationId(menuName, group));
204
+ function createUseMenuItems(locations) {
208
205
  return () => {
209
- const injectionsGroups = (0, import_locations.useInjectionsOf)(locations);
210
206
  return (0, import_react2.useMemo)(() => {
211
- return injectionsGroups.reduce((acc, injections, index) => {
212
- const groupName = menuGroups[index];
213
- return {
214
- ...acc,
215
- [groupName]: injections.map((injection) => ({
207
+ return Object.entries(locations).reduce(
208
+ (carry, [groupName, location]) => {
209
+ const items = location.getInjections().map((injection) => ({
216
210
  id: injection.id,
217
211
  MenuItem: injection.filler
218
- }))
219
- };
220
- }, {});
221
- }, [injectionsGroups]);
212
+ }));
213
+ return {
214
+ ...carry,
215
+ [groupName]: items
216
+ };
217
+ },
218
+ {}
219
+ );
220
+ }, []);
222
221
  };
223
222
  }
224
- function getMenuLocationId(menu, group) {
225
- return `editor/app-bar/${menu}/${group}`;
226
- }
227
223
 
228
224
  // src/locations/index.ts
229
225
  var import_locations2 = require("@elementor/locations");
230
-
231
- // src/locations/consts.ts
232
- var LOCATION_PAGE_INDICATION = "editor/app-bar/page-indication";
233
- var LOCATION_RESPONSIVE = "editor/app-bar/responsive";
234
- var LOCATION_PRIMARY_ACTION = "editor/app-bar/primary-action";
235
-
236
- // src/locations/index.ts
237
- var injectIntoPageIndication = (0, import_locations2.createInjectorFor)(LOCATION_PAGE_INDICATION);
238
- var injectIntoResponsive = (0, import_locations2.createInjectorFor)(LOCATION_RESPONSIVE);
239
- var injectIntoPrimaryAction = (0, import_locations2.createInjectorFor)(LOCATION_PRIMARY_ACTION);
240
- var mainMenu = createMenu({
241
- name: "main",
242
- groups: ["exits"]
243
- });
244
- var toolsMenu = createMenu({
245
- name: "tools"
246
- });
247
- var utilitiesMenu = createMenu({
248
- name: "utilities"
249
- });
250
- var documentOptionsMenu = createMenu({
251
- name: "document-options",
252
- groups: ["save"]
253
- });
226
+ var {
227
+ inject: injectIntoPageIndication,
228
+ Slot: PageIndicationSlot
229
+ } = (0, import_locations2.createLocation)();
230
+ var {
231
+ inject: injectIntoResponsive,
232
+ Slot: ResponsiveSlot
233
+ } = (0, import_locations2.createLocation)();
234
+ var {
235
+ inject: injectIntoPrimaryAction,
236
+ Slot: PrimaryActionSlot
237
+ } = (0, import_locations2.createLocation)();
238
+ var mainMenu = createMenu(["exits"]);
239
+ var toolsMenu = createMenu();
240
+ var utilitiesMenu = createMenu();
241
+ var documentOptionsMenu = createMenu(["save"]);
254
242
 
255
243
  // src/components/app-bar.tsx
256
244
  var React19 = __toESM(require("react"));
@@ -428,23 +416,20 @@ function UtilitiesMenuLocation() {
428
416
 
429
417
  // src/components/locations/primary-action-location.tsx
430
418
  var React16 = __toESM(require("react"));
431
- var import_locations6 = require("@elementor/locations");
432
419
  function PrimaryActionLocation() {
433
- return /* @__PURE__ */ React16.createElement(import_locations6.Slot, { location: LOCATION_PRIMARY_ACTION });
420
+ return /* @__PURE__ */ React16.createElement(PrimaryActionSlot, null);
434
421
  }
435
422
 
436
423
  // src/components/locations/page-indication-location.tsx
437
424
  var React17 = __toESM(require("react"));
438
- var import_locations8 = require("@elementor/locations");
439
425
  function PageIndicationLocation() {
440
- return /* @__PURE__ */ React17.createElement(import_locations8.Slot, { location: LOCATION_PAGE_INDICATION });
426
+ return /* @__PURE__ */ React17.createElement(PageIndicationSlot, null);
441
427
  }
442
428
 
443
429
  // src/components/locations/responsive-location.tsx
444
430
  var React18 = __toESM(require("react"));
445
- var import_locations10 = require("@elementor/locations");
446
431
  function ResponsiveLocation() {
447
- return /* @__PURE__ */ React18.createElement(import_locations10.Slot, { location: LOCATION_RESPONSIVE });
432
+ return /* @__PURE__ */ React18.createElement(ResponsiveSlot, null);
448
433
  }
449
434
 
450
435
  // src/components/app-bar.tsx
@@ -496,7 +481,7 @@ function SettingsButton() {
496
481
  // src/extensions/documents-indicator/index.ts
497
482
  function init() {
498
483
  injectIntoPageIndication({
499
- name: "document-settings-button",
484
+ id: "document-settings-button",
500
485
  filler: SettingsButton,
501
486
  options: {
502
487
  priority: 20
@@ -525,7 +510,7 @@ function useActionProps() {
525
510
  // src/extensions/documents-preview/index.ts
526
511
  function init2() {
527
512
  utilitiesMenu.registerAction({
528
- name: "document-preview-button",
513
+ id: "document-preview-button",
529
514
  priority: 30,
530
515
  // After help.
531
516
  useProps: useActionProps
@@ -666,19 +651,19 @@ function isEnabled(document2) {
666
651
  // src/extensions/documents-save/index.ts
667
652
  function init3() {
668
653
  injectIntoPrimaryAction({
669
- name: "document-primary-action",
654
+ id: "document-primary-action",
670
655
  filler: PrimaryAction
671
656
  });
672
657
  documentOptionsMenu.registerAction({
673
658
  group: "save",
674
- name: "document-save-draft",
659
+ id: "document-save-draft",
675
660
  priority: 10,
676
661
  // Before save as template.
677
662
  useProps: useDocumentSaveDraftProps
678
663
  });
679
664
  documentOptionsMenu.registerAction({
680
665
  group: "save",
681
- name: "document-save-as-template",
666
+ id: "document-save-as-template",
682
667
  priority: 20,
683
668
  // After save draft.
684
669
  useProps: useDocumentSaveTemplateProps
@@ -737,7 +722,7 @@ function useActionProps2() {
737
722
  function init4() {
738
723
  syncPanelTitle();
739
724
  toolsMenu.registerToggleAction({
740
- name: "open-elements-panel",
725
+ id: "open-elements-panel",
741
726
  priority: 1,
742
727
  useProps: useActionProps2
743
728
  });
@@ -764,7 +749,7 @@ function useActionProps3() {
764
749
  // src/extensions/finder/index.ts
765
750
  function init5() {
766
751
  utilitiesMenu.registerToggleAction({
767
- name: "toggle-finder",
752
+ id: "toggle-finder",
768
753
  priority: 10,
769
754
  // Before help.
770
755
  useProps: useActionProps3
@@ -776,7 +761,7 @@ var import_i18n11 = require("@wordpress/i18n");
776
761
  var import_icons10 = require("@elementor/icons");
777
762
  function init6() {
778
763
  utilitiesMenu.registerLink({
779
- name: "open-help-center",
764
+ id: "open-help-center",
780
765
  priority: 20,
781
766
  // After Finder.
782
767
  useProps: () => {
@@ -808,7 +793,7 @@ function useActionProps4() {
808
793
  // src/extensions/history/index.ts
809
794
  function init7() {
810
795
  mainMenu.registerToggleAction({
811
- name: "open-history",
796
+ id: "open-history",
812
797
  priority: 20,
813
798
  useProps: useActionProps4
814
799
  });
@@ -829,7 +814,7 @@ function useActionProps5() {
829
814
  // src/extensions/keyboard-shortcuts/index.ts
830
815
  function init8() {
831
816
  mainMenu.registerAction({
832
- name: "open-keyboard-shortcuts",
817
+ id: "open-keyboard-shortcuts",
833
818
  group: "default",
834
819
  priority: 40,
835
820
  // After user preferences.
@@ -915,11 +900,11 @@ function useActionProps6() {
915
900
  // src/extensions/site-settings/index.ts
916
901
  function init9() {
917
902
  (0, import_editor.injectIntoTop)({
918
- name: "site-settings-primary-action-portal",
903
+ id: "site-settings-primary-action-portal",
919
904
  filler: PortalledPrimaryAction
920
905
  });
921
906
  toolsMenu.registerToggleAction({
922
- name: "toggle-site-settings",
907
+ id: "toggle-site-settings",
923
908
  priority: 2,
924
909
  useProps: useActionProps6
925
910
  });
@@ -943,7 +928,7 @@ function useActionProps7() {
943
928
  // src/extensions/structure/index.ts
944
929
  function init10() {
945
930
  toolsMenu.registerToggleAction({
946
- name: "toggle-structure-view",
931
+ id: "toggle-structure-view",
947
932
  priority: 3,
948
933
  useProps: useActionProps7
949
934
  });
@@ -964,7 +949,7 @@ function useActionProps8() {
964
949
  // src/extensions/theme-builder/index.ts
965
950
  function init11() {
966
951
  mainMenu.registerAction({
967
- name: "open-theme-builder",
952
+ id: "open-theme-builder",
968
953
  useProps: useActionProps8
969
954
  });
970
955
  }
@@ -987,7 +972,7 @@ function useActionProps9() {
987
972
  // src/extensions/user-preferences/index.ts
988
973
  function init12() {
989
974
  mainMenu.registerToggleAction({
990
- name: "open-user-preferences",
975
+ id: "open-user-preferences",
991
976
  priority: 30,
992
977
  // After history.
993
978
  useProps: useActionProps9
@@ -1000,7 +985,7 @@ var import_icons17 = require("@elementor/icons");
1000
985
  var import_editor_documents7 = require("@elementor/editor-documents");
1001
986
  function init13() {
1002
987
  mainMenu.registerLink({
1003
- name: "exit-to-wordpress",
988
+ id: "exit-to-wordpress",
1004
989
  group: "exits",
1005
990
  useProps: () => {
1006
991
  const document2 = (0, import_editor_documents7.useActiveDocument)();
@@ -1035,7 +1020,7 @@ function init15() {
1035
1020
  redirectOldMenus();
1036
1021
  init14();
1037
1022
  (0, import_editor2.injectIntoTop)({
1038
- name: "app-bar",
1023
+ id: "app-bar",
1039
1024
  filler: AppBar
1040
1025
  });
1041
1026
  }