|
3 | 3 | [athens.common-db :as common-db]
|
4 | 4 | [athens.common-events :as common-events]
|
5 | 5 | [athens.common-events.graph.atomic :as atomic-graph-ops]
|
| 6 | + [athens.common-events.graph.ops :as graph-ops] |
6 | 7 | [athens.common-events.resolver :as resolver]
|
7 | 8 | [athens.common-events.resolver.atomic :as atomic-resolver]
|
8 | 9 | [athens.common.utils :as common.utils]
|
|
900 | 901 | block-eid (common-db/e-by-av @db/dsdb :block/uid uid)
|
901 | 902 | do-nothing? (or (not block-eid)
|
902 | 903 | (= old-string new-string))
|
903 |
| - block-save-op (atomic-graph-ops/build-block-save-op @db/dsdb uid old-string new-string)] |
| 904 | + block-save-op (graph-ops/build-block-save-op @db/dsdb uid old-string new-string)] |
904 | 905 | (js/console.debug ":block/save local?" local?
|
905 | 906 | ", do-nothing?" do-nothing?)
|
906 | 907 | (when-not do-nothing?
|
|
959 | 960 |
|
960 | 961 | (reg-event-fx
|
961 | 962 | :enter/split-block
|
962 |
| - (fn [_ [_ {:keys [uid value index new-uid embed-id] :as args}]] |
| 963 | + (fn [_ [_ {:keys [parent-uid uid new-uid new-order old-string value index embed-id] :as args}]] |
963 | 964 | (js/console.debug ":enter/split-block" (pr-str args))
|
964 |
| - (let [local? (not (client/open?))] |
965 |
| - (js/console.debug ":enter/split-block local?" local?) |
| 965 | + (let [local? (not (client/open?)) |
| 966 | + split-block-op (graph-ops/build-block-split-op @db/dsdb |
| 967 | + {:parent-uid parent-uid |
| 968 | + :old-block-uid uid |
| 969 | + :new-block-uid new-uid |
| 970 | + :new-block-order new-order |
| 971 | + :old-string old-string |
| 972 | + :new-string value |
| 973 | + :index index})] |
| 974 | + (js/console.debug ":enter/split-block local?" local? "split-block-op" (pr-str split-block-op)) |
966 | 975 | (if local?
|
967 |
| - (let [split-block-event (common-events/build-split-block-event -1 |
968 |
| - uid |
969 |
| - value |
970 |
| - index |
971 |
| - new-uid) |
972 |
| - tx (resolver/resolve-event-to-tx @db/dsdb split-block-event)] |
| 976 | + (let [tx (atomic-resolver/resolve-atomic-op-to-tx @db/dsdb split-block-op)] |
973 | 977 | (js/console.debug ":enter/split-block tx:" (pr-str tx))
|
974 | 978 | {:fx [[:dispatch-n [[:transact tx]
|
975 | 979 | [:editing/uid (str new-uid (when embed-id
|
976 | 980 | (str "-embed-" embed-id)))]]]]})
|
977 | 981 |
|
978 |
| - {:fx [[:dispatch [:remote/split-block args]]]})))) |
| 982 | + {:fx [[:dispatch [:remote/split-block {:op split-block-op |
| 983 | + :new-uid new-uid |
| 984 | + :embed-id embed-id}]]]})))) |
979 | 985 |
|
980 | 986 |
|
981 | 987 | (reg-event-fx
|
|
1033 | 1039 | (.getAttribute "data-uid"))
|
1034 | 1040 | uid)
|
1035 | 1041 | [uid embed-id] (db/uid-and-embed-id uid)
|
1036 |
| - block (db/get-block [:block/uid uid]) |
1037 |
| - parent (db/get-parent [:block/uid uid]) |
| 1042 | + {:block/keys [string order] |
| 1043 | + :as block} (db/get-block [:block/uid uid]) |
| 1044 | + {parent-uid :block/uid |
| 1045 | + :as parent} (db/get-parent [:block/uid uid]) |
1038 | 1046 | is-parent-root-embed? (= (some-> d-key-down :target
|
1039 | 1047 | (.. (closest ".block-embed"))
|
1040 | 1048 | (. -firstChild)
|
1041 | 1049 | (.getAttribute "data-uid"))
|
1042 |
| - (str (:block/uid parent) "-embed-" embed-id)) |
| 1050 | + (str parent-uid "-embed-" embed-id)) |
1043 | 1051 | root-block? (boolean (:node/title parent))
|
1044 | 1052 | context-root-uid (get-in rfdb [:current-route :path-params :id])
|
1045 | 1053 | new-uid (common.utils/gen-block-uid)
|
|
1095 | 1103 | :embed-id embed-id}]
|
1096 | 1104 |
|
1097 | 1105 | (not (zero? start))
|
1098 |
| - [:enter/split-block {:uid uid |
1099 |
| - :value value |
1100 |
| - :index start |
1101 |
| - :new-uid new-uid |
1102 |
| - :embed-id embed-id}] |
| 1106 | + [:enter/split-block {:uid uid |
| 1107 | + :old-string string |
| 1108 | + :parent-uid parent-uid |
| 1109 | + :value value |
| 1110 | + :index start |
| 1111 | + :new-uid new-uid |
| 1112 | + :new-order (inc order) |
| 1113 | + :embed-id embed-id}] |
1103 | 1114 |
|
1104 | 1115 | (empty? value)
|
1105 | 1116 | [:unindent {:uid uid
|
|
0 commit comments