@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/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  // src/locations/menus.tsx
2
2
  import * as React8 from "react";
3
3
  import { useMemo } from "react";
4
- import { inject, useInjectionsOf } from "@elementor/locations";
4
+ import { createLocation } from "@elementor/locations";
5
5
 
6
6
  // src/components/actions/action.tsx
7
7
  import * as React4 from "react";
@@ -112,30 +112,30 @@ function Link({ icon: Icon, title, visible = true, ...props }) {
112
112
  }
113
113
 
114
114
  // src/locations/menus.tsx
115
- function createMenu({ name: menuName, groups = [] }) {
115
+ function createMenu(groups = []) {
116
116
  const menuGroups = [
117
117
  ...groups,
118
118
  "default"
119
119
  ];
120
- const registerAction = createRegisterMenuItem({
121
- menuName,
122
- menuGroups,
123
- component: Action
124
- });
125
- const registerToggleAction = createRegisterMenuItem({
126
- menuName,
127
- menuGroups,
128
- component: ToggleAction
129
- });
130
- const registerLink = createRegisterMenuItem({
131
- menuName,
132
- menuGroups,
133
- component: Link
134
- });
135
- const useMenuItems5 = createUseMenuItems({
136
- menuName,
137
- menuGroups
138
- });
120
+ const locations = menuGroups.reduce(
121
+ (carry, group) => ({
122
+ ...carry,
123
+ [group]: createLocation()
124
+ }),
125
+ {}
126
+ );
127
+ const [
128
+ registerAction,
129
+ registerToggleAction,
130
+ registerLink
131
+ ] = [Action, ToggleAction, Link].map(
132
+ (Component) => createRegisterMenuItem({
133
+ locations,
134
+ menuGroups,
135
+ component: Component
136
+ })
137
+ );
138
+ const useMenuItems5 = createUseMenuItems(locations);
139
139
  return {
140
140
  registerAction,
141
141
  registerToggleAction,
@@ -143,8 +143,8 @@ function createMenu({ name: menuName, groups = [] }) {
143
143
  useMenuItems: useMenuItems5
144
144
  };
145
145
  }
146
- function createRegisterMenuItem({ menuName, menuGroups, component }) {
147
- return ({ group = "default", name, overwrite, priority, ...args }) => {
146
+ function createRegisterMenuItem({ locations, menuGroups, component }) {
147
+ return ({ group = "default", id, overwrite, priority, ...args }) => {
148
148
  if (!menuGroups.includes(group)) {
149
149
  return;
150
150
  }
@@ -154,10 +154,8 @@ function createRegisterMenuItem({ menuName, menuGroups, component }) {
154
154
  const componentProps = useProps();
155
155
  return /* @__PURE__ */ React8.createElement(Component, { ...props, ...componentProps });
156
156
  };
157
- const location = getMenuLocationId(menuName, group);
158
- inject({
159
- location,
160
- name,
157
+ locations[group].inject({
158
+ id,
161
159
  filler: Filler,
162
160
  options: {
163
161
  priority,
@@ -166,54 +164,44 @@ function createRegisterMenuItem({ menuName, menuGroups, component }) {
166
164
  });
167
165
  };
168
166
  }
169
- function createUseMenuItems({ menuName, menuGroups }) {
170
- const locations = menuGroups.map((group) => getMenuLocationId(menuName, group));
167
+ function createUseMenuItems(locations) {
171
168
  return () => {
172
- const injectionsGroups = useInjectionsOf(locations);
173
169
  return useMemo(() => {
174
- return injectionsGroups.reduce((acc, injections, index) => {
175
- const groupName = menuGroups[index];
176
- return {
177
- ...acc,
178
- [groupName]: injections.map((injection) => ({
170
+ return Object.entries(locations).reduce(
171
+ (carry, [groupName, location]) => {
172
+ const items = location.getInjections().map((injection) => ({
179
173
  id: injection.id,
180
174
  MenuItem: injection.filler
181
- }))
182
- };
183
- }, {});
184
- }, [injectionsGroups]);
175
+ }));
176
+ return {
177
+ ...carry,
178
+ [groupName]: items
179
+ };
180
+ },
181
+ {}
182
+ );
183
+ }, []);
185
184
  };
186
185
  }
187
- function getMenuLocationId(menu, group) {
188
- return `editor/app-bar/${menu}/${group}`;
189
- }
190
-
191
- // src/locations/index.ts
192
- import { createInjectorFor } from "@elementor/locations";
193
-
194
- // src/locations/consts.ts
195
- var LOCATION_PAGE_INDICATION = "editor/app-bar/page-indication";
196
- var LOCATION_RESPONSIVE = "editor/app-bar/responsive";
197
- var LOCATION_PRIMARY_ACTION = "editor/app-bar/primary-action";
198
186
 
199
187
  // src/locations/index.ts
200
- var injectIntoPageIndication = createInjectorFor(LOCATION_PAGE_INDICATION);
201
- var injectIntoResponsive = createInjectorFor(LOCATION_RESPONSIVE);
202
- var injectIntoPrimaryAction = createInjectorFor(LOCATION_PRIMARY_ACTION);
203
- var mainMenu = createMenu({
204
- name: "main",
205
- groups: ["exits"]
206
- });
207
- var toolsMenu = createMenu({
208
- name: "tools"
209
- });
210
- var utilitiesMenu = createMenu({
211
- name: "utilities"
212
- });
213
- var documentOptionsMenu = createMenu({
214
- name: "document-options",
215
- groups: ["save"]
216
- });
188
+ import { createLocation as createLocation2 } from "@elementor/locations";
189
+ var {
190
+ inject: injectIntoPageIndication,
191
+ Slot: PageIndicationSlot
192
+ } = createLocation2();
193
+ var {
194
+ inject: injectIntoResponsive,
195
+ Slot: ResponsiveSlot
196
+ } = createLocation2();
197
+ var {
198
+ inject: injectIntoPrimaryAction,
199
+ Slot: PrimaryActionSlot
200
+ } = createLocation2();
201
+ var mainMenu = createMenu(["exits"]);
202
+ var toolsMenu = createMenu();
203
+ var utilitiesMenu = createMenu();
204
+ var documentOptionsMenu = createMenu(["save"]);
217
205
 
218
206
  // src/components/app-bar.tsx
219
207
  import * as React19 from "react";
@@ -391,23 +379,20 @@ function UtilitiesMenuLocation() {
391
379
 
392
380
  // src/components/locations/primary-action-location.tsx
393
381
  import * as React16 from "react";
394
- import { Slot } from "@elementor/locations";
395
382
  function PrimaryActionLocation() {
396
- return /* @__PURE__ */ React16.createElement(Slot, { location: LOCATION_PRIMARY_ACTION });
383
+ return /* @__PURE__ */ React16.createElement(PrimaryActionSlot, null);
397
384
  }
398
385
 
399
386
  // src/components/locations/page-indication-location.tsx
400
387
  import * as React17 from "react";
401
- import { Slot as Slot2 } from "@elementor/locations";
402
388
  function PageIndicationLocation() {
403
- return /* @__PURE__ */ React17.createElement(Slot2, { location: LOCATION_PAGE_INDICATION });
389
+ return /* @__PURE__ */ React17.createElement(PageIndicationSlot, null);
404
390
  }
405
391
 
406
392
  // src/components/locations/responsive-location.tsx
407
393
  import * as React18 from "react";
408
- import { Slot as Slot3 } from "@elementor/locations";
409
394
  function ResponsiveLocation() {
410
- return /* @__PURE__ */ React18.createElement(Slot3, { location: LOCATION_RESPONSIVE });
395
+ return /* @__PURE__ */ React18.createElement(ResponsiveSlot, null);
411
396
  }
412
397
 
413
398
  // src/components/app-bar.tsx
@@ -459,7 +444,7 @@ function SettingsButton() {
459
444
  // src/extensions/documents-indicator/index.ts
460
445
  function init() {
461
446
  injectIntoPageIndication({
462
- name: "document-settings-button",
447
+ id: "document-settings-button",
463
448
  filler: SettingsButton,
464
449
  options: {
465
450
  priority: 20
@@ -488,7 +473,7 @@ function useActionProps() {
488
473
  // src/extensions/documents-preview/index.ts
489
474
  function init2() {
490
475
  utilitiesMenu.registerAction({
491
- name: "document-preview-button",
476
+ id: "document-preview-button",
492
477
  priority: 30,
493
478
  // After help.
494
479
  useProps: useActionProps
@@ -638,19 +623,19 @@ function isEnabled(document2) {
638
623
  // src/extensions/documents-save/index.ts
639
624
  function init3() {
640
625
  injectIntoPrimaryAction({
641
- name: "document-primary-action",
626
+ id: "document-primary-action",
642
627
  filler: PrimaryAction
643
628
  });
644
629
  documentOptionsMenu.registerAction({
645
630
  group: "save",
646
- name: "document-save-draft",
631
+ id: "document-save-draft",
647
632
  priority: 10,
648
633
  // Before save as template.
649
634
  useProps: useDocumentSaveDraftProps
650
635
  });
651
636
  documentOptionsMenu.registerAction({
652
637
  group: "save",
653
- name: "document-save-as-template",
638
+ id: "document-save-as-template",
654
639
  priority: 20,
655
640
  // After save draft.
656
641
  useProps: useDocumentSaveTemplateProps
@@ -709,7 +694,7 @@ function useActionProps2() {
709
694
  function init4() {
710
695
  syncPanelTitle();
711
696
  toolsMenu.registerToggleAction({
712
- name: "open-elements-panel",
697
+ id: "open-elements-panel",
713
698
  priority: 1,
714
699
  useProps: useActionProps2
715
700
  });
@@ -736,7 +721,7 @@ function useActionProps3() {
736
721
  // src/extensions/finder/index.ts
737
722
  function init5() {
738
723
  utilitiesMenu.registerToggleAction({
739
- name: "toggle-finder",
724
+ id: "toggle-finder",
740
725
  priority: 10,
741
726
  // Before help.
742
727
  useProps: useActionProps3
@@ -748,7 +733,7 @@ import { __ as __11 } from "@wordpress/i18n";
748
733
  import { HelpIcon } from "@elementor/icons";
749
734
  function init6() {
750
735
  utilitiesMenu.registerLink({
751
- name: "open-help-center",
736
+ id: "open-help-center",
752
737
  priority: 20,
753
738
  // After Finder.
754
739
  useProps: () => {
@@ -780,7 +765,7 @@ function useActionProps4() {
780
765
  // src/extensions/history/index.ts
781
766
  function init7() {
782
767
  mainMenu.registerToggleAction({
783
- name: "open-history",
768
+ id: "open-history",
784
769
  priority: 20,
785
770
  useProps: useActionProps4
786
771
  });
@@ -801,7 +786,7 @@ function useActionProps5() {
801
786
  // src/extensions/keyboard-shortcuts/index.ts
802
787
  function init8() {
803
788
  mainMenu.registerAction({
804
- name: "open-keyboard-shortcuts",
789
+ id: "open-keyboard-shortcuts",
805
790
  group: "default",
806
791
  priority: 40,
807
792
  // After user preferences.
@@ -887,11 +872,11 @@ function useActionProps6() {
887
872
  // src/extensions/site-settings/index.ts
888
873
  function init9() {
889
874
  injectIntoTop({
890
- name: "site-settings-primary-action-portal",
875
+ id: "site-settings-primary-action-portal",
891
876
  filler: PortalledPrimaryAction
892
877
  });
893
878
  toolsMenu.registerToggleAction({
894
- name: "toggle-site-settings",
879
+ id: "toggle-site-settings",
895
880
  priority: 2,
896
881
  useProps: useActionProps6
897
882
  });
@@ -915,7 +900,7 @@ function useActionProps7() {
915
900
  // src/extensions/structure/index.ts
916
901
  function init10() {
917
902
  toolsMenu.registerToggleAction({
918
- name: "toggle-structure-view",
903
+ id: "toggle-structure-view",
919
904
  priority: 3,
920
905
  useProps: useActionProps7
921
906
  });
@@ -936,7 +921,7 @@ function useActionProps8() {
936
921
  // src/extensions/theme-builder/index.ts
937
922
  function init11() {
938
923
  mainMenu.registerAction({
939
- name: "open-theme-builder",
924
+ id: "open-theme-builder",
940
925
  useProps: useActionProps8
941
926
  });
942
927
  }
@@ -959,7 +944,7 @@ function useActionProps9() {
959
944
  // src/extensions/user-preferences/index.ts
960
945
  function init12() {
961
946
  mainMenu.registerToggleAction({
962
- name: "open-user-preferences",
947
+ id: "open-user-preferences",
963
948
  priority: 30,
964
949
  // After history.
965
950
  useProps: useActionProps9
@@ -972,7 +957,7 @@ import { WordpressIcon } from "@elementor/icons";
972
957
  import { useActiveDocument as useActiveDocument6 } from "@elementor/editor-documents";
973
958
  function init13() {
974
959
  mainMenu.registerLink({
975
- name: "exit-to-wordpress",
960
+ id: "exit-to-wordpress",
976
961
  group: "exits",
977
962
  useProps: () => {
978
963
  const document2 = useActiveDocument6();
@@ -1007,7 +992,7 @@ function init15() {
1007
992
  redirectOldMenus();
1008
993
  init14();
1009
994
  injectIntoTop2({
1010
- name: "app-bar",
995
+ id: "app-bar",
1011
996
  filler: AppBar
1012
997
  });
1013
998
  }