@gopherium/godmin 0.30.0 → 0.32.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/README.md +2 -3
- package/dist/base.css +159 -29
- package/dist/breakpoints.d.ts +1 -1
- package/dist/breakpoints.js +1 -1
- package/dist/bulk-run.d.ts +10 -0
- package/dist/bulk-run.js +59 -10
- package/dist/bulk.d.ts +3 -0
- package/dist/confirm-dialog.d.ts +14 -14
- package/dist/confirm-dialog.js +8 -28
- package/dist/dialog-open.d.ts +63 -0
- package/dist/dialog-open.js +110 -0
- package/dist/focus-back.d.ts +20 -0
- package/dist/focus-back.js +36 -12
- package/dist/form-dialog.d.ts +14 -16
- package/dist/form-dialog.js +53 -13
- package/dist/index.d.ts +13 -13
- package/dist/index.js +7 -8
- package/dist/list-chrome/es-ES.js +3 -3
- package/dist/list-chrome/fr-FR.js +1 -0
- package/dist/list-run.js +39 -48
- package/dist/page-breadcrumbs.d.ts +28 -0
- package/dist/page-breadcrumbs.js +18 -0
- package/dist/page-tabs.js +18 -6
- package/dist/page.d.ts +8 -3
- package/dist/page.js +36 -9
- package/dist/rename-dialog.d.ts +24 -0
- package/dist/rename-dialog.js +16 -0
- package/dist/router.d.ts +2 -0
- package/dist/router.js +1 -0
- package/dist/toaster.js +21 -2
- package/dist/unsaved-changes-dialog.d.ts +19 -0
- package/dist/unsaved-changes-dialog.js +33 -0
- package/docs/build-and-versioning.md +92 -9
- package/docs/design-system/accessibility.md +12 -7
- package/docs/design-system/custom-properties.md +6 -2
- package/docs/design-system/dialogs.md +240 -0
- package/docs/design-system/layout.md +5 -3
- package/docs/design-system/lists.md +3 -1
- package/docs/design-system/loading.md +2 -0
- package/docs/design-system/motion.md +3 -2
- package/docs/design-system/overview.md +7 -1
- package/docs/design-system/record-pages.md +199 -0
- package/docs/design-system/toasts.md +13 -10
- package/docs/design-system/typography.md +1 -1
- package/docs/lists.md +321 -434
- package/docs/loading-and-feedback.md +14 -11
- package/docs/overview.md +2 -3
- package/docs/screens.md +87 -34
- package/docs/testing.md +11 -9
- package/package.json +20 -28
- package/dist/close-while-open.d.ts +0 -6
- package/dist/close-while-open.js +0 -21
- package/dist/confirm.d.ts +0 -21
- package/dist/confirm.js +0 -11
- package/dist/dialogs.d.ts +0 -4
- package/dist/dialogs.js +0 -3
- package/dist/form.d.ts +0 -28
- package/dist/form.js +0 -23
- package/dist/rename.d.ts +0 -20
- package/dist/rename.js +0 -14
- package/dist/run-confirm.d.ts +0 -22
- package/dist/run-confirm.js +0 -23
package/README.md
CHANGED
|
@@ -49,11 +49,10 @@ those two lines do for you.
|
|
|
49
49
|
|
|
50
50
|
| Entry point | Contents |
|
|
51
51
|
| --- | --- |
|
|
52
|
-
| `@gopherium/godmin` | `AdminRoot`, `Frame`, `Page`, `PageTitle`, `PageTabs`, `PageTab`, `SectionTitle`, `InitialsAvatar`, `NavigationScreen`, `MenuCount`, `ErrorNotice`, `LoadMore`, `LogList`, `LogItem`, `LogTime`, `LoadingScreen`, `Toaster`, `useToaster`, `RepeatRows`, `RowControls`, `useRowKeys`, `keyFromLabel`, `listChromeCatalogFor`, `LIST_CHROME_DOMAIN`, `ListEmpty`, `ListNoResults`, `
|
|
52
|
+
| `@gopherium/godmin` | `AdminRoot`, `Frame`, `Page`, `PageTitle`, `PageTabs`, `PageTab`, `PageBreadcrumbs`, `PageBreadcrumb`, `SectionTitle`, `InitialsAvatar`, `NavigationScreen`, `MenuCount`, `ErrorNotice`, `LoadMore`, `LogList`, `LogItem`, `LogTime`, `LoadingScreen`, `Toaster`, `useToaster`, `RepeatRows`, `RowControls`, `useRowKeys`, `keyFromLabel`, `listChromeCatalogFor`, `LIST_CHROME_DOMAIN`, `ListEmpty`, `ListNoResults`, `ConfirmDialog`, `FormDialog`, `RenameDialog`, `FileButton`, `useServerPaging`, `pageWindow`, `paginationOf`, `runEach`, `bulkNotes`, `useListRun`, `useBulkRun`, `useDialogRun`, `focusInDialog`, `useFocusBack`, `focusedTrigger`, `openOnTap`, `useUnsavedText`, `markLatest`, `viewNarrows`, `offeredView`, `offeredSize`, `sizedView`, `useMediaQuery`, `useTokenDocument`, the breakpoints `HUGE_BREAKPOINT`, `SIDEBAR_BREAKPOINT`, `EDGE_BREAKPOINT`, `DENSE_BREAKPOINT`, `SHEET_BREAKPOINT`, `TITLE_BREAKPOINT` and `SMALL_VIEWPORT`, `SUPPORTED_WPDS` |
|
|
53
53
|
| `@gopherium/godmin/base.css` | Cascade layer order, design tokens, host rules, frame and screen styles |
|
|
54
54
|
| `@gopherium/godmin/dates` | `startListDates`, `listDate`, the only entry that loads `@wordpress/date` |
|
|
55
|
-
| `@gopherium/godmin/
|
|
56
|
-
| `@gopherium/godmin/router` | `Navigation`, `NavigationList`, `NavigationItem`, `DrilldownItem`, `useCanAccess` and the `MenuItem` type with its optional `count`, `useListView`, `listSearch`, `openOnTap`, `useCanvas`, `useFrameLocation`, `routerDefaults`, the `canvas`, `Sidebar` and `capability` route static data |
|
|
55
|
+
| `@gopherium/godmin/router` | `Navigation`, `NavigationList`, `NavigationItem`, `DrilldownItem`, `useCanAccess` and the `MenuItem` type with its optional `count`, `useListView`, `listSearch`, `openOnTap`, `useCanvas`, `useFrameLocation`, `routerDefaults`, `UnsavedChangesDialog`, the `canvas`, `Sidebar` and `capability` route static data |
|
|
57
56
|
| `@gopherium/godmin/testing` | `installTestEnvironment`, `renderAdmin`, `setViewport` and its `TestViewport` type, `getAnnouncement`, `clearAnnouncements`, `assertElementPatched`, `WPDS_IGNORE_SELECTOR`, `textClasses`, `badgeClasses`, `buttonClasses`, `stubLayout` |
|
|
58
57
|
| `@gopherium/godmin/vite` | `godminDedupe`, `godminSingleCopy`, `godminStylesheetFirst`, `duplicateCopies`, `hoistStylesheet` |
|
|
59
58
|
| `@gopherium/godmin/stylelint` | The design system stylelint rules |
|
package/dist/base.css
CHANGED
|
@@ -415,6 +415,7 @@ body {
|
|
|
415
415
|
}
|
|
416
416
|
|
|
417
417
|
.godmin-toast__action {
|
|
418
|
+
position: relative;
|
|
418
419
|
flex: none;
|
|
419
420
|
margin-inline-start: var(--wpds-dimension-gap-2xl);
|
|
420
421
|
padding: 0;
|
|
@@ -429,6 +430,12 @@ body {
|
|
|
429
430
|
cursor: var(--wpds-cursor-control);
|
|
430
431
|
}
|
|
431
432
|
|
|
433
|
+
.godmin-toast__action::after {
|
|
434
|
+
content: '';
|
|
435
|
+
position: absolute;
|
|
436
|
+
inset: min(calc(-1 * var(--wpds-dimension-gap-sm)), calc(50% - 12px));
|
|
437
|
+
}
|
|
438
|
+
|
|
432
439
|
.godmin-toast__action:hover {
|
|
433
440
|
text-decoration: none;
|
|
434
441
|
}
|
|
@@ -690,7 +697,43 @@ body {
|
|
|
690
697
|
}
|
|
691
698
|
|
|
692
699
|
.godmin-page__head {
|
|
693
|
-
min-block-size: var(--wpds-dimension-size-
|
|
700
|
+
min-block-size: var(--wpds-dimension-size-md);
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
.godmin-page__heading {
|
|
704
|
+
display: flex;
|
|
705
|
+
flex: 1 1 calc(var(--wpds-dimension-surface-width-xs) / 2);
|
|
706
|
+
flex-wrap: wrap;
|
|
707
|
+
align-items: center;
|
|
708
|
+
min-inline-size: 0;
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
.godmin-page__heading > :last-child {
|
|
712
|
+
flex: 1 1 calc(var(--wpds-dimension-surface-width-xs) / 2);
|
|
713
|
+
overflow: hidden;
|
|
714
|
+
text-overflow: ellipsis;
|
|
715
|
+
white-space: nowrap;
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
.godmin-page__breadcrumbs {
|
|
719
|
+
flex: none;
|
|
720
|
+
max-inline-size: 100%;
|
|
721
|
+
overflow-wrap: anywhere;
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
.godmin-page__breadcrumbs ul {
|
|
725
|
+
display: flex;
|
|
726
|
+
flex-wrap: wrap;
|
|
727
|
+
align-items: center;
|
|
728
|
+
margin: 0;
|
|
729
|
+
padding: 0;
|
|
730
|
+
list-style: none;
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
.godmin-page__separator {
|
|
734
|
+
margin-inline: var(--wpds-dimension-gap-sm);
|
|
735
|
+
color: var(--wpds-color-stroke-surface-neutral);
|
|
736
|
+
user-select: none;
|
|
694
737
|
}
|
|
695
738
|
|
|
696
739
|
.godmin-page__subtitle {
|
|
@@ -698,23 +741,64 @@ body {
|
|
|
698
741
|
color: var(--wpds-color-foreground-content-neutral-weak);
|
|
699
742
|
}
|
|
700
743
|
|
|
744
|
+
.godmin-page:has(> .godmin-page__split) {
|
|
745
|
+
flex: 1 1 0;
|
|
746
|
+
min-block-size: 0;
|
|
747
|
+
}
|
|
748
|
+
|
|
701
749
|
.godmin-page__split {
|
|
750
|
+
--godmin-page-stacked: calc((2 * var(--wpds-dimension-surface-width-md) + var(--wpds-dimension-gap-xl) + 2 * var(--wpds-dimension-padding-xs) - 100cqi) * 999999);
|
|
751
|
+
container-type: inline-size;
|
|
702
752
|
display: flex;
|
|
753
|
+
flex: 1 1 auto;
|
|
703
754
|
flex-wrap: wrap;
|
|
755
|
+
align-content: flex-start;
|
|
704
756
|
align-items: flex-start;
|
|
705
|
-
gap: var(--wpds-dimension-gap-xl);
|
|
757
|
+
column-gap: calc(var(--wpds-dimension-gap-xl) - 2 * var(--wpds-dimension-padding-xs));
|
|
758
|
+
row-gap: calc(var(--wpds-dimension-gap-xl) - var(--godmin-canvas-gutter-block, 0px));
|
|
759
|
+
margin-inline: calc(-1 * var(--godmin-canvas-gutter, 0px));
|
|
760
|
+
margin-block-end: calc(-1 * var(--godmin-canvas-gutter-block, 0px));
|
|
761
|
+
padding-inline: calc(var(--godmin-canvas-gutter, 0px) - var(--wpds-dimension-padding-xs));
|
|
762
|
+
border-block-start: var(--wpds-border-width-xs) solid var(--wpds-color-stroke-surface-neutral-weak);
|
|
763
|
+
overflow: hidden auto;
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
.godmin-page > .godmin-page__tabs + .godmin-page__split {
|
|
767
|
+
margin-block-start: calc(-1 * var(--wpds-dimension-gap-lg));
|
|
768
|
+
border-block-start: none;
|
|
706
769
|
}
|
|
707
770
|
|
|
708
771
|
.godmin-page__main {
|
|
709
|
-
flex: 1 1
|
|
772
|
+
flex: 1 1 0;
|
|
773
|
+
padding-block-start: var(--wpds-dimension-padding-lg);
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
.godmin-page__aside {
|
|
777
|
+
flex: 0 1 min(100%, max(var(--wpds-dimension-surface-width-md) + 2 * var(--wpds-dimension-padding-xs), var(--godmin-page-stacked)));
|
|
778
|
+
padding-block-start: clamp(0px, calc(var(--wpds-dimension-padding-lg) - var(--godmin-page-stacked)), var(--wpds-dimension-padding-lg));
|
|
710
779
|
}
|
|
711
780
|
|
|
781
|
+
.godmin-page__main,
|
|
712
782
|
.godmin-page__aside {
|
|
713
|
-
|
|
714
|
-
|
|
783
|
+
box-sizing: border-box;
|
|
784
|
+
max-block-size: max(100%, var(--godmin-page-stacked));
|
|
785
|
+
padding-inline: var(--wpds-dimension-padding-xs);
|
|
786
|
+
padding-block-end: var(--godmin-canvas-gutter-block, 0px);
|
|
787
|
+
overflow: hidden auto;
|
|
715
788
|
overflow-wrap: anywhere;
|
|
716
789
|
}
|
|
717
790
|
|
|
791
|
+
.godmin-page__main > *,
|
|
792
|
+
.godmin-page__aside > * {
|
|
793
|
+
flex-shrink: 0;
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
.godmin-page__main .godmin-table-scroll,
|
|
797
|
+
.godmin-page__aside .godmin-table-scroll {
|
|
798
|
+
position: relative;
|
|
799
|
+
overflow-x: auto;
|
|
800
|
+
}
|
|
801
|
+
|
|
718
802
|
.godmin-page__aside:empty {
|
|
719
803
|
display: none;
|
|
720
804
|
}
|
|
@@ -750,6 +834,11 @@ body {
|
|
|
750
834
|
margin-inline: calc(-1 * min(var(--wpds-dimension-padding-2xl), var(--godmin-canvas-gutter, 0px)));
|
|
751
835
|
}
|
|
752
836
|
|
|
837
|
+
.godmin-page__main .godmin-list,
|
|
838
|
+
.godmin-page__aside .godmin-list {
|
|
839
|
+
margin-inline: 0;
|
|
840
|
+
}
|
|
841
|
+
|
|
753
842
|
.godmin-page > .godmin-page__list > :not(.dataviews-wrapper, .godmin-table-scroll, .godmin-table) {
|
|
754
843
|
margin-inline: var(--wpds-dimension-padding-2xl);
|
|
755
844
|
}
|
|
@@ -818,6 +907,10 @@ body {
|
|
|
818
907
|
overscroll-behavior-inline: none;
|
|
819
908
|
}
|
|
820
909
|
|
|
910
|
+
.godmin-page-tabs:not(.godmin-page-tabs--scrolling) {
|
|
911
|
+
overflow: visible;
|
|
912
|
+
}
|
|
913
|
+
|
|
821
914
|
.godmin-page-tabs:dir(rtl) {
|
|
822
915
|
--godmin-page-tabs-start: right;
|
|
823
916
|
--godmin-page-tabs-end: left;
|
|
@@ -841,6 +934,8 @@ body {
|
|
|
841
934
|
display: flex;
|
|
842
935
|
align-items: center;
|
|
843
936
|
position: relative;
|
|
937
|
+
z-index: 1;
|
|
938
|
+
cursor: var(--wpds-cursor-control);
|
|
844
939
|
block-size: 48px;
|
|
845
940
|
padding: 0;
|
|
846
941
|
scroll-margin: 24px;
|
|
@@ -853,35 +948,83 @@ body {
|
|
|
853
948
|
white-space: nowrap;
|
|
854
949
|
}
|
|
855
950
|
|
|
856
|
-
.godmin-page-tabs__tab
|
|
857
|
-
|
|
951
|
+
.godmin-page-tabs__tab--current {
|
|
952
|
+
cursor: default;
|
|
858
953
|
}
|
|
859
954
|
|
|
860
955
|
.godmin-page-tabs__tab:focus-visible {
|
|
861
956
|
outline: none;
|
|
862
957
|
}
|
|
863
958
|
|
|
959
|
+
.godmin-page-tabs__tab:not(.godmin-page-tabs__tab--current):is(:hover, :active),
|
|
960
|
+
.godmin-page-tabs__tab:focus-visible {
|
|
961
|
+
color: var(--wpds-color-foreground-interactive-neutral-active);
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
.godmin-page-tabs__tab::after,
|
|
864
965
|
.godmin-page-tabs__tab::before {
|
|
865
|
-
content: '';
|
|
866
966
|
position: absolute;
|
|
867
|
-
|
|
967
|
+
z-index: -1;
|
|
868
968
|
border-radius: var(--wpds-border-radius-sm);
|
|
869
|
-
outline: var(--wpds-border-width-focus) solid
|
|
969
|
+
outline: var(--wpds-border-width-focus) solid transparent;
|
|
870
970
|
opacity: 0;
|
|
871
971
|
pointer-events: none;
|
|
872
972
|
}
|
|
873
973
|
|
|
874
|
-
|
|
974
|
+
@media not (prefers-reduced-motion) {
|
|
975
|
+
.godmin-page-tabs__tab::after,
|
|
976
|
+
.godmin-page-tabs__tab::before {
|
|
977
|
+
transition: opacity 0.1s linear;
|
|
978
|
+
}
|
|
979
|
+
}
|
|
980
|
+
|
|
981
|
+
.godmin-page-tabs__tab::after {
|
|
982
|
+
content: '';
|
|
983
|
+
inset-block: calc(var(--wpds-dimension-padding-md) + var(--wpds-dimension-padding-xs));
|
|
984
|
+
inset-inline: 0;
|
|
985
|
+
outline-offset: var(--wpds-dimension-padding-xs);
|
|
986
|
+
}
|
|
987
|
+
|
|
988
|
+
.godmin-page-tabs__tab:focus-visible::after {
|
|
989
|
+
outline-color: var(--wpds-color-stroke-focus);
|
|
990
|
+
}
|
|
991
|
+
|
|
992
|
+
.godmin-page-tabs__tab:not(.godmin-page-tabs__tab--current):is(:hover, :active)::after,
|
|
993
|
+
.godmin-page-tabs__tab:focus-visible::after {
|
|
994
|
+
background-color: var(--wpds-color-background-interactive-neutral-weak-active);
|
|
995
|
+
box-shadow: 0 0 0 var(--wpds-dimension-padding-xs) var(--wpds-color-background-interactive-neutral-weak-active);
|
|
875
996
|
opacity: 1;
|
|
876
997
|
}
|
|
877
998
|
|
|
878
|
-
.godmin-page-tabs__tab
|
|
999
|
+
.godmin-page-tabs--scrolling .godmin-page-tabs__tab::before {
|
|
879
1000
|
content: '';
|
|
1001
|
+
z-index: 0;
|
|
1002
|
+
inset-block: var(--wpds-dimension-padding-md);
|
|
1003
|
+
inset-inline: round(up, var(--wpds-border-width-focus), 1px);
|
|
1004
|
+
}
|
|
1005
|
+
|
|
1006
|
+
.godmin-page-tabs--scrolling .godmin-page-tabs__tab:focus-visible::before {
|
|
1007
|
+
outline-color: var(--wpds-color-stroke-focus);
|
|
1008
|
+
opacity: 1;
|
|
1009
|
+
}
|
|
1010
|
+
|
|
1011
|
+
.godmin-page-tabs--scrolling .godmin-page-tabs__tab:focus-visible::after {
|
|
1012
|
+
outline-color: transparent;
|
|
1013
|
+
}
|
|
1014
|
+
|
|
1015
|
+
.godmin-page-tabs__line {
|
|
880
1016
|
position: absolute;
|
|
881
1017
|
inset-inline: 0;
|
|
882
1018
|
inset-block-end: 0;
|
|
883
1019
|
block-size: var(--wpds-border-width-focus);
|
|
884
|
-
background: var(--wpds-color-
|
|
1020
|
+
background-color: var(--wpds-color-foreground-interactive-neutral);
|
|
1021
|
+
outline: 2px solid transparent;
|
|
1022
|
+
outline-offset: -1px;
|
|
1023
|
+
pointer-events: none;
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1026
|
+
.godmin-page-tabs__tab:focus-visible .godmin-page-tabs__line {
|
|
1027
|
+
background-color: var(--wpds-color-foreground-interactive-neutral-active);
|
|
885
1028
|
}
|
|
886
1029
|
|
|
887
1030
|
.godmin-page:has(> .godmin-page__list) > .godmin-page__header {
|
|
@@ -903,22 +1046,8 @@ body {
|
|
|
903
1046
|
align-self: flex-start;
|
|
904
1047
|
}
|
|
905
1048
|
|
|
906
|
-
.godmin-
|
|
907
|
-
|
|
908
|
-
flex-direction: column;
|
|
909
|
-
gap: calc(var(--wpds-dimension-gap-lg) + var(--wpds-dimension-gap-xs));
|
|
910
|
-
}
|
|
911
|
-
|
|
912
|
-
.godmin-modal-body--copy {
|
|
913
|
-
gap: var(--wpds-dimension-gap-md);
|
|
914
|
-
}
|
|
915
|
-
|
|
916
|
-
.godmin-modal-body--create {
|
|
917
|
-
gap: var(--wpds-dimension-gap-lg);
|
|
918
|
-
}
|
|
919
|
-
|
|
920
|
-
.godmin-modal-body__question {
|
|
921
|
-
line-height: 1.4;
|
|
1049
|
+
.godmin-dialog-popup {
|
|
1050
|
+
overflow-wrap: anywhere;
|
|
922
1051
|
}
|
|
923
1052
|
|
|
924
1053
|
.godmin-form__row {
|
|
@@ -957,6 +1086,7 @@ body {
|
|
|
957
1086
|
font-size: var(--wpds-typography-font-size-md);
|
|
958
1087
|
line-height: var(--wpds-typography-line-height-sm);
|
|
959
1088
|
text-align: left;
|
|
1089
|
+
overflow-wrap: normal;
|
|
960
1090
|
}
|
|
961
1091
|
|
|
962
1092
|
.godmin-table th,
|
package/dist/breakpoints.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export declare const EDGE_BREAKPOINT = 782;
|
|
|
15
15
|
*/
|
|
16
16
|
export declare const DENSE_BREAKPOINT = 640;
|
|
17
17
|
/**
|
|
18
|
-
* The viewport width below which
|
|
18
|
+
* The viewport width below which toasts widen to the screen, the WordPress small breakpoint.
|
|
19
19
|
*/
|
|
20
20
|
export declare const SHEET_BREAKPOINT = 600;
|
|
21
21
|
/**
|
package/dist/breakpoints.js
CHANGED
|
@@ -15,7 +15,7 @@ export const EDGE_BREAKPOINT = 782;
|
|
|
15
15
|
*/
|
|
16
16
|
export const DENSE_BREAKPOINT = 640;
|
|
17
17
|
/**
|
|
18
|
-
* The viewport width below which
|
|
18
|
+
* The viewport width below which toasts widen to the screen, the WordPress small breakpoint.
|
|
19
19
|
*/
|
|
20
20
|
export const SHEET_BREAKPOINT = 600;
|
|
21
21
|
/**
|
package/dist/bulk-run.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import type { BulkWords } from './bulk.js';
|
|
2
|
+
import type { DialogAnswer } from './dialog-open.js';
|
|
2
3
|
import type { ListRun } from './list-run.js';
|
|
3
4
|
/** Runs one call over each item, reports what the run reached in the given words and then reloads the list. */
|
|
4
5
|
export type BulkRun<Item> = (items: Item[], call: (item: Item) => Promise<unknown>, words: BulkWords<Item>) => Promise<void>;
|
|
6
|
+
/** Runs a dialog's write over one item or several, and answers the dialog what to do next. */
|
|
7
|
+
export type DialogRun<Item> = (items: Item[], call: (item: Item) => Promise<unknown>, words: BulkWords<Item>) => Promise<DialogAnswer | undefined>;
|
|
5
8
|
/**
|
|
6
9
|
* Returns the handler that runs a call per item, marks the list reloading at the first that works, toasts at the last.
|
|
7
10
|
* @param list - What the list does around a run.
|
|
@@ -9,3 +12,10 @@ export type BulkRun<Item> = (items: Item[], call: (item: Item) => Promise<unknow
|
|
|
9
12
|
* @returns The run handler, the same while the list run and the refresh stay the same.
|
|
10
13
|
*/
|
|
11
14
|
export declare function useBulkRun<Item>(list: ListRun, refresh: (items: Item[]) => Promise<unknown>): BulkRun<Item>;
|
|
15
|
+
/**
|
|
16
|
+
* Returns the handler that runs a dialog's write on a list: one item that failed answers its words, else a toast.
|
|
17
|
+
* @param list - What the list does around a run.
|
|
18
|
+
* @param refresh - Reloads the list once the last call ended, given the items the run acted on.
|
|
19
|
+
* @returns The run handler, the same while the list run and the refresh stay the same.
|
|
20
|
+
*/
|
|
21
|
+
export declare function useDialogRun<Item>(list: ListRun, refresh: (items: Item[]) => Promise<unknown>): DialogRun<Item>;
|
package/dist/bulk-run.js
CHANGED
|
@@ -43,14 +43,38 @@ function bulkToast(items, outcome, words) {
|
|
|
43
43
|
return notes.notice ?? notes.toast;
|
|
44
44
|
}
|
|
45
45
|
/**
|
|
46
|
-
* Returns the
|
|
46
|
+
* Returns the action the toast of a run offers, the words' Undo once every item finished, none otherwise.
|
|
47
|
+
* @param items - The items the run was given.
|
|
48
|
+
* @param outcome - What the run reached.
|
|
49
|
+
* @param words - The words of the run.
|
|
50
|
+
* @returns The action, none when an item failed or the words give no Undo.
|
|
51
|
+
*/
|
|
52
|
+
function doneAction(items, outcome, words) {
|
|
53
|
+
return outcome.failures.length === 0 ? words.undo?.(items) : undefined;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Shows the one toast a run's outcome reads as, with the words' Undo once every item finished.
|
|
57
|
+
* @param toaster - Where the toast shows.
|
|
58
|
+
* @param items - The items the run was given.
|
|
59
|
+
* @param outcome - What the run reached.
|
|
60
|
+
* @param words - The words of the run.
|
|
61
|
+
*/
|
|
62
|
+
function toastOutcome(toaster, items, outcome, words) {
|
|
63
|
+
const message = bulkToast(items, outcome, words);
|
|
64
|
+
if (message !== undefined) {
|
|
65
|
+
toaster.show(message, doneAction(items, outcome, words));
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Returns the handler that runs a call per item, marks the list reloading at the first that works, reports at the last.
|
|
47
70
|
* @param list - What the list does around a run.
|
|
48
71
|
* @param refresh - Reloads the list once the last call ended, given the items the run acted on.
|
|
49
|
-
* @
|
|
72
|
+
* @param report - Reports what the run reached and gives what the handler answers.
|
|
73
|
+
* @returns The run handler, the same while the list run, the refresh and the report stay the same.
|
|
50
74
|
*/
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
75
|
+
function useListWrite(list, refresh, report) {
|
|
76
|
+
return useCallback(async (given, call, words) => {
|
|
77
|
+
const items = given.filter(() => true);
|
|
54
78
|
const settle = list.onStart();
|
|
55
79
|
const reload = reloadOnce(list);
|
|
56
80
|
const outcome = await runEach(items, reporting(call, reload.mark));
|
|
@@ -58,13 +82,38 @@ export function useBulkRun(list, refresh) {
|
|
|
58
82
|
.then(() => refresh(items))
|
|
59
83
|
.then(reload.end, reload.end);
|
|
60
84
|
try {
|
|
61
|
-
|
|
62
|
-
if (message !== undefined) {
|
|
63
|
-
toaster.show(message);
|
|
64
|
-
}
|
|
85
|
+
return report(items, outcome, words);
|
|
65
86
|
}
|
|
66
87
|
finally {
|
|
67
88
|
settle(outcome.done > 0);
|
|
68
89
|
}
|
|
69
|
-
}, [list, refresh,
|
|
90
|
+
}, [list, refresh, report]);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Returns the handler that runs a call per item, marks the list reloading at the first that works, toasts at the last.
|
|
94
|
+
* @param list - What the list does around a run.
|
|
95
|
+
* @param refresh - Reloads the list once the last call ended, given the items the run acted on.
|
|
96
|
+
* @returns The run handler, the same while the list run and the refresh stay the same.
|
|
97
|
+
*/
|
|
98
|
+
export function useBulkRun(list, refresh) {
|
|
99
|
+
const toaster = useToaster();
|
|
100
|
+
const report = useCallback((items, outcome, words) => toastOutcome(toaster, items, outcome, words), [toaster]);
|
|
101
|
+
return useListWrite(list, refresh, report);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Returns the handler that runs a dialog's write on a list: one item that failed answers its words, else a toast.
|
|
105
|
+
* @param list - What the list does around a run.
|
|
106
|
+
* @param refresh - Reloads the list once the last call ended, given the items the run acted on.
|
|
107
|
+
* @returns The run handler, the same while the list run and the refresh stay the same.
|
|
108
|
+
*/
|
|
109
|
+
export function useDialogRun(list, refresh) {
|
|
110
|
+
const toaster = useToaster();
|
|
111
|
+
const report = useCallback((items, outcome, words) => {
|
|
112
|
+
if (outcome.asked === 1 && outcome.done === 0) {
|
|
113
|
+
return { error: words.failed(outcome.failures, 1) };
|
|
114
|
+
}
|
|
115
|
+
toastOutcome(toaster, items, outcome, words);
|
|
116
|
+
return undefined;
|
|
117
|
+
}, [toaster]);
|
|
118
|
+
return useListWrite(list, refresh, report);
|
|
70
119
|
}
|
package/dist/bulk.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ToastAction } from './toaster.js';
|
|
1
2
|
/** An item a bulk run could not finish, with the error its call failed with. */
|
|
2
3
|
export interface BulkFailure<Item> {
|
|
3
4
|
/** The item the call was made for. */
|
|
@@ -27,6 +28,8 @@ export interface BulkWords<Item> {
|
|
|
27
28
|
done: (count: number, only: Item | undefined) => string;
|
|
28
29
|
/** The toast for the items that failed, shown instead of the done one, given each failure and how many were asked. */
|
|
29
30
|
failed: (failures: BulkFailure<Item>[], asked: number) => string;
|
|
31
|
+
/** The action the done toast offers once every item finished, such as Undo, given the items. */
|
|
32
|
+
undo?: (items: Item[]) => ToastAction;
|
|
30
33
|
}
|
|
31
34
|
/** The messages a bulk outcome reads as, each absent when nothing calls for it. */
|
|
32
35
|
export interface BulkNotes {
|
package/dist/confirm-dialog.d.ts
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
/** The props of a
|
|
1
|
+
import type { DialogAnswer } from './dialog-open.js';
|
|
2
|
+
/** The props of a dialog that asks one question before an action. */
|
|
3
3
|
export interface ConfirmDialogProps {
|
|
4
|
-
/** The question the dialog asks, its name
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
|
|
4
|
+
/** The question the dialog asks, its name. */
|
|
5
|
+
title: string;
|
|
6
|
+
/** What will happen, in plain words. */
|
|
7
|
+
description?: string;
|
|
8
|
+
/** Whether the action cannot be undone, which draws its button red. */
|
|
9
|
+
intent?: 'default' | 'irreversible';
|
|
10
10
|
/** The label of the button that carries the action out. */
|
|
11
11
|
confirmLabel: string;
|
|
12
12
|
/** The label of the button that closes the dialog. */
|
|
13
13
|
cancelLabel: string;
|
|
14
|
-
/** Carries the action out. Return nothing to close at once,
|
|
15
|
-
onConfirm: () => void |
|
|
16
|
-
/** Takes the dialog away
|
|
14
|
+
/** Carries the action out. Return nothing to close at once, the write to stay busy, or an answer to stay open. */
|
|
15
|
+
onConfirm: () => void | DialogAnswer | PromiseLike<unknown>;
|
|
16
|
+
/** Takes the dialog away, once its card has left the page. */
|
|
17
17
|
onClose: () => void;
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
20
|
-
* Renders a
|
|
21
|
-
* @param props - The question,
|
|
20
|
+
* Renders a dialog that asks one question before an action, on the WPDS alert dialog, with Cancel focused.
|
|
21
|
+
* @param props - The question, what will happen, the intent, the labels and the handlers.
|
|
22
22
|
* @returns The dialog.
|
|
23
23
|
*/
|
|
24
|
-
export declare function ConfirmDialog({
|
|
24
|
+
export declare function ConfirmDialog({ title, description, intent, confirmLabel, cancelLabel, onConfirm, onClose, }: ConfirmDialogProps): import("react").JSX.Element;
|
package/dist/confirm-dialog.js
CHANGED
|
@@ -1,34 +1,14 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { ConfirmBody } from './confirm.js';
|
|
3
|
+
import { AlertDialog } from '@wordpress/ui';
|
|
4
|
+
import { POPUP_CLASS, answered, refuseRepeatedEnter, refuseSecondClick, useDialogOpen, useFinalFocus, } from './dialog-open.js';
|
|
6
5
|
/**
|
|
7
|
-
* Renders a
|
|
8
|
-
* @param props - The question,
|
|
6
|
+
* Renders a dialog that asks one question before an action, on the WPDS alert dialog, with Cancel focused.
|
|
7
|
+
* @param props - The question, what will happen, the intent, the labels and the handlers.
|
|
9
8
|
* @returns The dialog.
|
|
10
9
|
*/
|
|
11
|
-
export function ConfirmDialog({
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
const close = () => {
|
|
16
|
-
if (open.current) {
|
|
17
|
-
open.current = false;
|
|
18
|
-
onClose();
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
const confirm = () => {
|
|
22
|
-
const running = onConfirm();
|
|
23
|
-
if (!(running instanceof Promise)) {
|
|
24
|
-
close();
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
setBusy(true);
|
|
28
|
-
void running.finally(() => {
|
|
29
|
-
setBusy(false);
|
|
30
|
-
close();
|
|
31
|
-
});
|
|
32
|
-
};
|
|
33
|
-
return (_jsx(Modal, { size: size, focusOnMount: "firstContentElement", title: title, __experimentalHideHeader: title === undefined, aria: { labelledby: question, describedby: title === undefined ? undefined : question }, onRequestClose: close, children: _jsx(ConfirmBody, { confirmLabel: confirmLabel, cancelLabel: cancelLabel, busy: busy, onConfirm: confirm, onCancel: close, children: _jsx("span", { id: question, children: children }) }) }));
|
|
10
|
+
export function ConfirmDialog({ title, description, intent, confirmLabel, cancelLabel, onConfirm, onClose, }) {
|
|
11
|
+
const { open, change, exitWatch } = useDialogOpen(onClose);
|
|
12
|
+
const finalFocus = useFinalFocus();
|
|
13
|
+
return (_jsx(AlertDialog.Root, { open: open, onOpenChange: change, onConfirm: () => answered(onConfirm), children: _jsx(AlertDialog.Popup, { className: POPUP_CLASS, intent: intent, title: title, description: description, confirmButtonText: confirmLabel, cancelButtonText: cancelLabel, finalFocus: finalFocus, onClickCapture: refuseSecondClick, onKeyDownCapture: refuseRepeatedEnter, children: exitWatch }) }));
|
|
34
14
|
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { KeyboardEvent, MouseEvent, ReactNode } from 'react';
|
|
2
|
+
/** The class every dialog's popup carries, so a long word breaks inside the card. */
|
|
3
|
+
export declare const POPUP_CLASS = "godmin-dialog-popup";
|
|
4
|
+
/** What a write may answer a dialog: words to show, or a plain stay. Any other answer closes it. */
|
|
5
|
+
export type DialogAnswer = {
|
|
6
|
+
error: string;
|
|
7
|
+
} | {
|
|
8
|
+
close: false;
|
|
9
|
+
};
|
|
10
|
+
/** What a dialog takes from the hook that holds it open. */
|
|
11
|
+
export interface DialogOpen {
|
|
12
|
+
/** Whether the dialog is open, false on the first render so its entry plays. */
|
|
13
|
+
open: boolean;
|
|
14
|
+
/** Takes the next open state, for the dialog's `onOpenChange`. */
|
|
15
|
+
change: (next: boolean) => void;
|
|
16
|
+
/** A child of the popup that draws nothing and reports when the popup left the page. */
|
|
17
|
+
exitWatch: ReactNode;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Holds a dialog open from its first commit and runs its close once the popup left the page.
|
|
21
|
+
* @param onClose - What runs after a close, once the popup left the page.
|
|
22
|
+
* @returns The open state, what changes it and the child that watches the popup leave.
|
|
23
|
+
*/
|
|
24
|
+
export declare function useDialogOpen(onClose: () => void): DialogOpen;
|
|
25
|
+
/**
|
|
26
|
+
* Notes the control that held the focus as a dialog was asked, for the place the focus goes once the popup left.
|
|
27
|
+
* @returns What answers `finalFocus`: that control while the focus sits on the page, otherwise false to leave it.
|
|
28
|
+
*/
|
|
29
|
+
export declare function useFinalFocus(): () => HTMLElement | false;
|
|
30
|
+
/**
|
|
31
|
+
* Reads what a write answered a dialog, whatever its shape.
|
|
32
|
+
* @param answer - What the write answered.
|
|
33
|
+
* @returns The words to show or a plain stay, none for a dialog that closes.
|
|
34
|
+
*/
|
|
35
|
+
export declare function answerOf(answer: unknown): DialogAnswer | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* Reports whether a value is a write still running, a promise or any object with a `then` method.
|
|
38
|
+
* @param value - What the write's handler returned.
|
|
39
|
+
* @returns Whether the value is one to wait for.
|
|
40
|
+
*/
|
|
41
|
+
export declare function isThenable(value: unknown): value is PromiseLike<unknown>;
|
|
42
|
+
/**
|
|
43
|
+
* Keeps a dialog open after a rejection and hands the rejection on to the app as one nobody caught.
|
|
44
|
+
* @param error - What the write rejected with.
|
|
45
|
+
* @returns A plain stay.
|
|
46
|
+
*/
|
|
47
|
+
export declare function passRejectionOn(error: unknown): DialogAnswer;
|
|
48
|
+
/**
|
|
49
|
+
* Carries a dialog's action out and reads what it answers, handing what it throws or rejects with on to the app.
|
|
50
|
+
* @param action - The action.
|
|
51
|
+
* @returns What the dialog reads, at once unless the action returned a write still running.
|
|
52
|
+
*/
|
|
53
|
+
export declare function answered(action: () => unknown): DialogAnswer | undefined | Promise<DialogAnswer | undefined>;
|
|
54
|
+
/**
|
|
55
|
+
* Refuses the second click of a double click, while Enter and Space still press.
|
|
56
|
+
* @param event - The click on its way into the popup.
|
|
57
|
+
*/
|
|
58
|
+
export declare function refuseSecondClick(event: MouseEvent): void;
|
|
59
|
+
/**
|
|
60
|
+
* Refuses an Enter a held key repeats, so holding it sends once.
|
|
61
|
+
* @param event - The key press on its way into the popup.
|
|
62
|
+
*/
|
|
63
|
+
export declare function refuseRepeatedEnter(event: KeyboardEvent): void;
|