|
89 | 89 | " By default, returns the " [:code ":label"] ", " [:code ":id"] |
90 | 90 | ", or else a string of the entire value of the last item in " |
91 | 91 | [:code ":row-path"] "."]} |
| 92 | + {:name :corner-header |
| 93 | + :type "part" |
| 94 | + :validate-fn part? |
| 95 | + :description |
| 96 | + [:span "A string, hiccup, or function of " [:code "{:keys [row-index column-index]}"] "." |
| 97 | + " Both row-index and column-index are integers. By default, returns " [:code "nil"] "."]} |
92 | 98 | {:name :cell-wrapper |
93 | 99 | :type "part" |
94 | 100 | :validate-fn part? |
|
318 | 324 | [:span "Similar to " [:code ":column-header"] |
319 | 325 | ", but it should return a string value only." |
320 | 326 | " After the export button is clicked, " [:code "nested-grid"] " maps " |
321 | | - [:code ":on-export-column-header"] "over any cells marked for export, passing the " |
| 327 | + [:code ":on-export-column-header"] "over any column-headers marked for export, passing the " |
| 328 | + "results to " [:code ":on-export"] " via the " [:code ":header-rows"] " prop."]} |
| 329 | + {:name :on-export-corner-header |
| 330 | + :type "{:keys [row-index column-index]} -> string" |
| 331 | + :validate-fn ifn? |
| 332 | + :description |
| 333 | + [:span "Similar to " [:code ":corner-header"] |
| 334 | + ", but it should return a string value only." |
| 335 | + " After the export button is clicked, " [:code "nested-grid"] " maps " |
| 336 | + [:code ":on-export-column-header"] " over all the top-left corner cells, passing the " |
322 | 337 | "results to " [:code ":on-export"] " via the " [:code ":header-rows"] " prop."]} |
323 | 338 | {:name :show-selection-box? |
324 | 339 | :default false |
|
692 | 707 | remove-empty-row-space? remove-empty-column-space? |
693 | 708 | column-width column-header-height row-header-width row-height |
694 | 709 | show-export-button? on-export export-button |
695 | | - on-export-cell on-export-column-header on-export-row-header |
| 710 | + on-export-cell on-export-column-header on-export-row-header on-export-corner-header |
696 | 711 | on-init-export-fn |
697 | 712 | show-zebra-stripes? |
698 | 713 | show-selection-box? resize-columns? resize-rows? |
|
714 | 729 | show-zebra-stripes? true |
715 | 730 | on-export-column-header header-label |
716 | 731 | on-export-row-header header-label |
| 732 | + on-export-corner-header header-label |
717 | 733 | resize-columns? true |
718 | 734 | resize-rows? false |
719 | 735 | theme-cells? true |
|
785 | 801 | (take (count path) |
786 | 802 | (iterate pop path)))) |
787 | 803 | transpose (partial apply mapv vector) |
| 804 | + export-corner-headers #(mapv (fn [x] |
| 805 | + (mapv (fn [y] |
| 806 | + (on-export-corner-header {:row-index y :column-index x})) |
| 807 | + (range @row-depth))) |
| 808 | + (range @column-depth)) |
788 | 809 | export-column-headers #(let [export-path (fn [path] |
789 | 810 | (on-export-column-header {:path path :row-path path}))] |
790 | 811 | (transpose (mapv (fn [path] (mapv export-path (ancestry path))) |
|
813 | 834 | props (cond-> props cell-value (merge {:value (cell-value props)}))] |
814 | 835 | (on-export-cell props))) |
815 | 836 | column-paths))))) |
816 | | - export-spacers #(vec (repeat column-depth (vec (repeat row-depth nil)))) |
817 | 837 | default-export-button (fn [{:keys [on-click]}] |
818 | 838 | [buttons/md-icon-button |
819 | 839 | {:md-icon-name "zmdi zmdi-copy" |
|
825 | 845 | :on-click on-click}]) |
826 | 846 | export-fn #(let [column-headers (export-column-headers) |
827 | 847 | row-headers (export-row-headers) |
828 | | - spacers (export-spacers) |
| 848 | + corner-headers (export-corner-headers) |
829 | 849 | cells (export-cells) |
830 | | - header-rows (mapv into spacers column-headers) |
| 850 | + header-rows (mapv into corner-headers column-headers) |
831 | 851 | main-rows (mapv into row-headers cells) |
832 | 852 | rows (concat header-rows main-rows)] |
833 | 853 | (on-export |
834 | 854 | {:column-headers column-headers |
835 | 855 | :row-headers row-headers |
836 | | - :spacers spacers |
| 856 | + :corner-headers corner-headers |
837 | 857 | :cells cells |
838 | 858 | :header-rows header-rows |
839 | 859 | :main-rows main-rows |
|
842 | 862 | _ (when on-init-export-fn (on-init-export-fn export-fn)) |
843 | 863 | export-button (u/part export-button |
844 | 864 | (themed ::export-button |
845 | | - {:style {:position :fixed |
846 | | - :right 10} |
847 | | - :on-click export-fn}) |
| 865 | + {:style {:position :fixed |
| 866 | + :right 10} |
| 867 | + :on-click export-fn}) |
848 | 868 | :default default-export-button) |
849 | 869 | cell-grid-container [:div |
850 | 870 | (themed ::cell-grid-container |
851 | | - {:style {:max-height max-height |
852 | | - :max-width max-width |
853 | | - :display :grid |
854 | | - :grid-column-start 2 |
855 | | - :grid-row-start 2 |
856 | | - :grid-template-columns (grid-template cell-grid-columns) |
857 | | - :grid-template-rows (grid-template cell-grid-rows)}})] |
| 871 | + {:style {:max-height max-height |
| 872 | + :max-width max-width |
| 873 | + :display :grid |
| 874 | + :grid-column-start 2 |
| 875 | + :grid-row-start 2 |
| 876 | + :grid-template-columns (grid-template cell-grid-columns) |
| 877 | + :grid-template-rows (grid-template cell-grid-rows)}})] |
858 | 878 | column-header-cells (for [path column-paths |
859 | 879 | :let [edge (cond-> #{} |
860 | 880 | (start-branch? path column-paths) (conj :left) |
|
1024 | 1044 | ^{:key [::zebra-stripe i]} |
1025 | 1045 | [:div |
1026 | 1046 | (themed ::zebra-stripe |
1027 | | - {:style |
1028 | | - {:grid-column-start 1 |
1029 | | - :grid-column-end "end" |
1030 | | - :grid-row i |
1031 | | - :background-color "#999" |
1032 | | - :opacity 0.05 |
1033 | | - :z-index 1 |
1034 | | - :pointer-events "none"}})]) |
| 1047 | + {:style |
| 1048 | + {:grid-column-start 1 |
| 1049 | + :grid-column-end "end" |
| 1050 | + :grid-row i |
| 1051 | + :background-color "#999" |
| 1052 | + :opacity 0.05 |
| 1053 | + :z-index 1 |
| 1054 | + :pointer-events "none"}})]) |
1035 | 1055 | box-selector [selection-part |
1036 | 1056 | {:drag drag |
1037 | 1057 | :grid-columns cell-grid-columns |
|
1086 | 1106 | :children [export-button]}]] |
1087 | 1107 | outer-grid-container [:div |
1088 | 1108 | (themed ::outer-grid-container |
1089 | | - {:on-mouse-enter #(reset! hover? true) |
1090 | | - :on-mouse-leave #(reset! hover? false) |
1091 | | - :style |
1092 | | - (merge |
1093 | | - {:position :relative |
1094 | | - :display :grid |
1095 | | - :grid-template-columns (grid-template [(px row-header-total-width) |
1096 | | - (px column-header-total-width)]) |
1097 | | - :grid-template-rows (grid-template [(px column-header-total-height) |
1098 | | - "1fr"])} |
1099 | | - (when-not sticky? |
1100 | | - {:max-width (or max-width (when remove-empty-column-space? native-width)) |
1101 | | - :max-height (or max-height |
1102 | | - (when remove-empty-row-space? native-height)) |
1103 | | - :flex "1 1 auto" |
1104 | | - :overflow :auto}))})] |
| 1109 | + {:on-mouse-enter #(reset! hover? true) |
| 1110 | + :on-mouse-leave #(reset! hover? false) |
| 1111 | + :style |
| 1112 | + (merge |
| 1113 | + {:position :relative |
| 1114 | + :display :grid |
| 1115 | + :grid-template-columns (grid-template [(px row-header-total-width) |
| 1116 | + (px column-header-total-width)]) |
| 1117 | + :grid-template-rows (grid-template [(px column-header-total-height) |
| 1118 | + "1fr"])} |
| 1119 | + (when-not sticky? |
| 1120 | + {:max-width (or max-width (when remove-empty-column-space? native-width)) |
| 1121 | + :max-height (or max-height |
| 1122 | + (when remove-empty-row-space? native-height)) |
| 1123 | + :flex "1 1 auto" |
| 1124 | + :overflow :auto}))})] |
1105 | 1125 | corner-headers (into [:div (themed ::corner-header-grid-container |
1106 | | - {:style {:display :grid |
1107 | | - :box-sizing :border-box |
1108 | | - :position :sticky |
1109 | | - :top (cond-> sticky-top (and sticky? show-export-button?) (+ 25)) |
1110 | | - :left (if sticky? sticky-left 0) |
1111 | | - :grid-column-start 1 |
1112 | | - :grid-row-start 1 |
1113 | | - :z-index 3 |
1114 | | - :grid-template-columns (grid-template max-row-widths) |
1115 | | - :grid-template-rows (grid-template max-column-heights)}})] |
| 1126 | + {:style {:display :grid |
| 1127 | + :box-sizing :border-box |
| 1128 | + :position :sticky |
| 1129 | + :top (cond-> sticky-top (and sticky? show-export-button?) (+ 25)) |
| 1130 | + :left (if sticky? sticky-left 0) |
| 1131 | + :grid-column-start 1 |
| 1132 | + :grid-row-start 1 |
| 1133 | + :z-index 3 |
| 1134 | + :grid-template-columns (grid-template max-row-widths) |
| 1135 | + :grid-template-rows (grid-template max-column-heights)}})] |
1116 | 1136 | corner-header-cells) |
1117 | 1137 | column-headers (into [:div (themed ::column-header-grid-container |
1118 | | - {:style {:position :sticky |
1119 | | - :top (cond-> sticky-top (and sticky? show-export-button?) (+ 25)) |
1120 | | - :width :fit-content |
1121 | | - :z-index 2 |
1122 | | - :display :grid |
1123 | | - :grid-column-start 2 |
1124 | | - :grid-row-start 1 |
1125 | | - :grid-template-columns (grid-template cell-grid-columns) |
1126 | | - :grid-template-rows (grid-template max-column-heights)}})] |
| 1138 | + {:style {:position :sticky |
| 1139 | + :top (cond-> sticky-top (and sticky? show-export-button?) (+ 25)) |
| 1140 | + :width :fit-content |
| 1141 | + :z-index 2 |
| 1142 | + :display :grid |
| 1143 | + :grid-column-start 2 |
| 1144 | + :grid-row-start 1 |
| 1145 | + :grid-template-columns (grid-template cell-grid-columns) |
| 1146 | + :grid-template-rows (grid-template max-column-heights)}})] |
1127 | 1147 | column-header-cells) |
1128 | 1148 | row-headers (into [:div (themed ::row-header-grid-container |
1129 | | - {:style {:position :sticky |
1130 | | - :left (if sticky? sticky-left 0) |
1131 | | - :z-index 1 |
1132 | | - :display :grid |
1133 | | - :grid-column-start 1 |
1134 | | - :grid-row-start 2 |
1135 | | - :grid-template-columns (grid-template max-row-widths) |
1136 | | - :grid-template-rows (grid-template cell-grid-rows)}})] |
| 1149 | + {:style {:position :sticky |
| 1150 | + :left (if sticky? sticky-left 0) |
| 1151 | + :z-index 1 |
| 1152 | + :display :grid |
| 1153 | + :grid-column-start 1 |
| 1154 | + :grid-row-start 2 |
| 1155 | + :grid-template-columns (grid-template max-row-widths) |
| 1156 | + :grid-template-rows (grid-template cell-grid-rows)}})] |
1137 | 1157 | row-header-cells) |
1138 | 1158 | cells (-> cell-grid-container |
1139 | 1159 | (into cells) |
|
1143 | 1163 | (conj (when show-selection-box? box-selector)))] |
1144 | 1164 | [:div (merge |
1145 | 1165 | (themed ::wrapper |
1146 | | - {:src src |
1147 | | - :style (merge {:flex-direction :column} |
1148 | | - (when-not sticky? |
1149 | | - (merge {:flex "0 0 auto" |
1150 | | - :display :flex} |
1151 | | - (when remove-empty-column-space? |
1152 | | - {:max-width :fit-content}) |
1153 | | - (when remove-empty-row-space? |
1154 | | - {:max-height :fit-content}))))}) |
| 1166 | + {:src src |
| 1167 | + :style (merge {:flex-direction :column} |
| 1168 | + (when-not sticky? |
| 1169 | + (merge {:flex "0 0 auto" |
| 1170 | + :display :flex} |
| 1171 | + (when remove-empty-column-space? |
| 1172 | + {:max-width :fit-content}) |
| 1173 | + (when remove-empty-row-space? |
| 1174 | + {:max-height :fit-content}))))}) |
1155 | 1175 | (debug/->attr props)) |
1156 | 1176 | (when show-export-button? control-panel) |
1157 | 1177 | (conj |
|
0 commit comments