From f4ef8b3d8ac4677394070456e2c241c72bb8f278 Mon Sep 17 00:00:00 2001 From: Chris Oakman Date: Sun, 16 Apr 2023 10:21:35 -0500 Subject: [PATCH 1/3] WIP WIP WIP --- examples/2008-coordinates.example | 36 +++++++++++++++++++++ src-cljs/com/oakmac/chessboard2/api.cljs | 4 +++ src-cljs/com/oakmac/chessboard2/config.cljs | 12 ++++++- src-cljs/com/oakmac/chessboard2/core.cljs | 26 ++++++++------- src-cljs/com/oakmac/chessboard2/html.cljs | 23 ++++++------- src-cljs/com/oakmac/chessboard2/js_api.cljs | 33 +++++++++++++++++++ src-css/chessboard2.css | 28 ++++++++++------ 7 files changed, 129 insertions(+), 33 deletions(-) create mode 100644 examples/2008-coordinates.example diff --git a/examples/2008-coordinates.example b/examples/2008-coordinates.example new file mode 100644 index 0000000..bbef442 --- /dev/null +++ b/examples/2008-coordinates.example @@ -0,0 +1,36 @@ +===== id +2008-coordinates + +===== Name +Coordinates + +===== DescriptionMD +Use the `coordinates` property to control how coordinates display on the board. + +===== HTML +
+ + + + + +===== JS +const boardConfig = { + coordinates: 'default', + // coordinates: 'bottom left' + // coordinates: ["left", "top", "right"] + position: 'start' +} +const board = Chessboard2('myBoard', boardConfig) + +attachEvent('showCoordinatesBtn', 'click', () => { + board.showCoordinates() +}) + +attachEvent('hideCoordinatesBtn', 'click', () => { + board.hideCoordinates() +}) + +attachEvent('toggleCoordinatesBtn', 'click', () => { + board.toggleCoordinates() +}) diff --git a/src-cljs/com/oakmac/chessboard2/api.cljs b/src-cljs/com/oakmac/chessboard2/api.cljs index 83f76b1..5604afe 100644 --- a/src-cljs/com/oakmac/chessboard2/api.cljs +++ b/src-cljs/com/oakmac/chessboard2/api.cljs @@ -412,3 +412,7 @@ cfg2)] (swap! board-state merge validated-config) nil)) + +;; 9dabd59f-5ce7-483f-955a-57b0bccf30c9 +;; 21ec2a77-34e4-492e-ab1e-59e39e8ac241 +;; f02e8c66-7811-4e9c-b871-37fc083183e9 diff --git a/src-cljs/com/oakmac/chessboard2/config.cljs b/src-cljs/com/oakmac/chessboard2/config.cljs index 6f5e75a..28dc5aa 100644 --- a/src-cljs/com/oakmac/chessboard2/config.cljs +++ b/src-cljs/com/oakmac/chessboard2/config.cljs @@ -18,8 +18,18 @@ "black" "white")) +(defn valid-js-coords? [c] + (cond + (= c "default") true + ;; FIXME: validate the config here + :else false)) + (def config-props - {:draggable + {:coordinates + {:default-val nil + :valid-fn valid-js-coords?} + + :draggable {:default-val false :valid-fn boolean?} diff --git a/src-cljs/com/oakmac/chessboard2/core.cljs b/src-cljs/com/oakmac/chessboard2/core.cljs index fe749e9..f3b7f8e 100644 --- a/src-cljs/com/oakmac/chessboard2/core.cljs +++ b/src-cljs/com/oakmac/chessboard2/core.cljs @@ -80,6 +80,7 @@ ;; FIXME: need "source" here ;; "source" "FIXME" "square" square)) + ;; FIXME: add "file" and "rank" values here? (catch js/Error err (error-log "Runtime error with provided onDragStart function:" err) nil))))] @@ -161,7 +162,7 @@ ;; return null nil)) -(defn on-mousedown-root-el +(defn on-mousedown-items-el "This function fires on every 'mousedown' event inside the root DOM element" [board-state js-evt] (dom-util/safe-prevent-default js-evt) @@ -203,7 +204,7 @@ ;; return null nil)) -(defn on-mouseup-root-el +(defn on-mouseup-items-el "This function fires on every 'mouseup' event inside the root DOM element" [board-state js-evt] (let [{:keys [onMouseupSquare orientation position square->square-ids]} @board-state @@ -245,7 +246,7 @@ ;; NOTE: this function has the potential to be a perf bottleneck ;; need to benchmark and optimize this function -(defn on-mousemove-root-el +(defn on-mousemove-items-el [board-state js-evt] (let [clientX (gobj/get js-evt "clientX") clientY (gobj/get js-evt "clientY") @@ -278,7 +279,7 @@ "fromSquare" (if prev-square prev-square "off-board"))] (onMouseenterSquare js-board-info js-evt)))))) -(defn on-mouseleave-root-el +(defn on-mouseleave-items-el "Clear the current mouse position when the cursor leaves the board." [board-state _js-evt] (swap! board-state assoc :square-mouse-is-currently-hovering-over nil)) @@ -413,13 +414,14 @@ (fn [] (api/resize! board-state)) 10)) ;; TODO: make this debounce value configurable - ;; events on the root element - (.addEventListener root-el "mouseleave" (fn [js-evt] (on-mouseleave-root-el board-state js-evt))) - (.addEventListener root-el "mousemove" (fn [js-evt] (on-mousemove-root-el board-state js-evt))) - (.addEventListener root-el "mousedown" (fn [js-evt] (on-mousedown-root-el board-state js-evt))) - (.addEventListener root-el "mouseup" (fn [js-evt] (on-mouseup-root-el board-state js-evt))) - (.addEventListener root-el "touchstart" (fn [js-evt] (on-touch-start board-state js-evt))) - (.addEventListener root-el "transitionend" (fn [js-evt] (on-transition-end board-state js-evt)))) + ;; events on the Items Container element + (let [items-el (dom-util/get-element (:items-container-id @board-state))] + (.addEventListener items-el "mouseleave" (fn [js-evt] (on-mouseleave-items-el board-state js-evt))) + (.addEventListener items-el "mousemove" (fn [js-evt] (on-mousemove-items-el board-state js-evt))) + (.addEventListener items-el "mousedown" (fn [js-evt] (on-mousedown-items-el board-state js-evt))) + (.addEventListener items-el "mouseup" (fn [js-evt] (on-mouseup-items-el board-state js-evt))) + (.addEventListener items-el "touchstart" (fn [js-evt] (on-touch-start board-state js-evt))) + (.addEventListener items-el "transitionend" (fn [js-evt] (on-transition-end board-state js-evt))))) ;; TODO: move this to util ns (defn toggle-orientation [o] @@ -1019,7 +1021,7 @@ ;; FIXME: implement these ;; https://github.com/oakmac/chessboard2/issues/25 "coordinates" #() ;; FIXME: returns the current state with 0 arg, allows changing with other args - "getCoordinates" #() ;; FIXME: returns the config object + "getCoordinates" (partial js-api/get-coordinates board-state) "hideCoordinates" (partial hide-coordinates! board-state) "setCoordinates" #() ;; FIXME: sets the config object (do we need this? just use .setConfig() ?) "showCoordinates" (partial show-coordinates! board-state) diff --git a/src-cljs/com/oakmac/chessboard2/html.cljs b/src-cljs/com/oakmac/chessboard2/html.cljs index e434490..e1416a7 100644 --- a/src-cljs/com/oakmac/chessboard2/html.cljs +++ b/src-cljs/com/oakmac/chessboard2/html.cljs @@ -12,7 +12,7 @@ (declare piece->imgsrc) -(defn NotationFiles +(defn FileCoordinates [_cfg] (let [num-files 8 files (range 0 num-files)] @@ -22,10 +22,10 @@ (str "
" (idx->alpha f) "
"))) (apply str)))) -(defn NotationRanks +(defn RankCoordinates [_cfg] (let [num-ranks 8 - ranks (range 0 num-ranks)] + ranks (reverse (range 1 (inc num-ranks)))] (->> ranks (map (fn [r] @@ -204,11 +204,11 @@ @html)) (defn BoardContainer - [{:keys [container-id orientation show-notation? items-container-id squares-container-id] :as opts}] + [{:keys [container-id orientation items-container-id squares-container-id] :as opts}] (template (str - "
" - "
" + "
" + "
" "
" "
{Squares}" "
" ;; end .squares-2dea6 - "
{NotationFiles}
" - "
{NotationRanks}
" + "
{FileCoordinates}
" + "
{RankCoordinates}
" + "
{FileCoordinates}
" + "
{RankCoordinates}
" "
" ;; end .board-container-41a68 "
") ;; end .chessboard-21da3 {:container-id container-id + :FileCoordinates (FileCoordinates opts) :items-container-id items-container-id - :NotationFiles (NotationFiles opts) - :NotationRanks (NotationRanks opts) - :show-notation (if show-notation? "" " hide-notation-cbe71") + :RankCoordinates (RankCoordinates opts) :Squares (Squares opts) :squares-container-id squares-container-id})) diff --git a/src-cljs/com/oakmac/chessboard2/js_api.cljs b/src-cljs/com/oakmac/chessboard2/js_api.cljs index 212b3fd..9e2f44e 100644 --- a/src-cljs/com/oakmac/chessboard2/js_api.cljs +++ b/src-cljs/com/oakmac/chessboard2/js_api.cljs @@ -310,3 +310,36 @@ (string? arg1) (set-config board-state arg1 arg2) (goog/isObject arg1) (set-config board-state arg1 nil) :else (warn-log "Invalid args passed to config():" arg1 arg2))))) + +(defn get-coordinates + "Returns a JS Object of the current coordinates config." + [board-state] + (clj->js (:coords @board-state))) + +(defn set-coordinates + "Set the coordinate config." + [board-state js-coords-cfg]) + ;; FIXME: validate js-coords-cfg here + +(defn toggle-coordinates + [board-state]) + ;; FIXME: write me + +(defn coordinates + "Get or Set the coordinates." + [board-state]) + ;; FIXME: write me + ; (let [js-args (array)] + ; (copy-arguments js-args) + ; (.shift js-args) + ; (let [arg1 (aget js-args 0)] + ; ; arg2 (aget js-args 1)] + ; (cond + ; (not arg1) (get-config board-state) + ; (string? arg1) (set-config board-state arg1 arg2) + ; (goog/isObject arg1) (set-config board-state arg1 nil) + ; :else (warn-log "Invalid args passed to config():" arg1 arg2))))) + +;; TODO: actually add or remove coordinate elements from the DOM + +;; 583bb76a-10aa-4079-8d19-83a62ab0bf45 diff --git a/src-css/chessboard2.css b/src-css/chessboard2.css index c931784..f8766a4 100644 --- a/src-css/chessboard2.css +++ b/src-css/chessboard2.css @@ -107,15 +107,25 @@ border-radius: 100%; } -.hide-notation-cbe71 .notation-files-c3c0a { - display: none; +.coordinates-top-f30c9 { + top: -20px; + display: flex; + flex-direction: row; + left: 0; + position: absolute; + right: 0; } -.hide-notation-cbe71 .notation-ranks-d3f97 { - display: none; +.coordinates-right-7fc08 { + bottom: 0; + display: flex; + flex-direction: column; + position: absolute; + right: -20px; + top: 0; } -.notation-files-c3c0a { +.coordinates-bottom-ac241 { bottom: -20px; display: flex; flex-direction: row; @@ -124,13 +134,13 @@ right: 0; } -.notation-ranks-d3f97 { - bottom: -15px; +.coordinates-left-183e9 { + bottom: 0; + left: -15px; display: flex; flex-direction: column; position: absolute; - right: -15px; - top: 15px; + top: 0; } .file-44ae4 { From c60992e8a2e6b244477fb84463dc4a6e0b715565 Mon Sep 17 00:00:00 2001 From: Chris Oakman Date: Sun, 16 Apr 2023 11:36:14 -0500 Subject: [PATCH 2/3] WIP WIP WIP --- ...nates.example => 3005-coordinates.example} | 2 +- scripts/website.js | 1 + src-cljs/com/oakmac/chessboard2/core.cljs | 84 +++++++++++++------ src-cljs/com/oakmac/chessboard2/css.cljs | 6 ++ src-cljs/com/oakmac/chessboard2/html.cljs | 48 ++++++++--- 5 files changed, 102 insertions(+), 39 deletions(-) rename examples/{2008-coordinates.example => 3005-coordinates.example} (98%) diff --git a/examples/2008-coordinates.example b/examples/3005-coordinates.example similarity index 98% rename from examples/2008-coordinates.example rename to examples/3005-coordinates.example index bbef442..3f8e41e 100644 --- a/examples/2008-coordinates.example +++ b/examples/3005-coordinates.example @@ -1,5 +1,5 @@ ===== id -2008-coordinates +3005-coordinates ===== Name Coordinates diff --git a/scripts/website.js b/scripts/website.js index 9fbde4c..61e3a04 100755 --- a/scripts/website.js +++ b/scripts/website.js @@ -129,6 +129,7 @@ const examplesGroups = [ '3023-set-random-position', '3003-clear', '3004-move-pieces', + '3005-coordinates', '3008-analysis-arrows', '3009-circles', '3005-orientation', diff --git a/src-cljs/com/oakmac/chessboard2/core.cljs b/src-cljs/com/oakmac/chessboard2/core.cljs index f3b7f8e..fd0d5c0 100644 --- a/src-cljs/com/oakmac/chessboard2/core.cljs +++ b/src-cljs/com/oakmac/chessboard2/core.cljs @@ -857,44 +857,79 @@ (defn hide-coordinates! [board-state] - (swap! board-state assoc :show-coords? false)) - ; (let [container-id (:container-id @board-state)] - ; (add-class! (dom-util/get-element container-id) "hide-notation-cbe71") - ; (swap! board-state assoc :show-notation? false))) + (swap! board-state update :coords + (fn [coords-map] + (reduce + (fn [new-coords [position cfg]] + (assoc new-coords position (assoc cfg :show? false))) + {} + coords-map)))) (defn show-coordinates! [board-state] - (swap! board-state assoc :show-coords? true)) - ; (let [container-id (:container-id @board-state)] - ; (remove-class! (dom-util/get-element container-id) "hide-notation-cbe71") - ; (swap! board-state assoc :show-notation? true))) + (swap! board-state update :coords + (fn [coords-map] + (reduce + (fn [new-coords [position cfg]] + (assoc new-coords position (assoc cfg :show? true))) + {} + coords-map)))) (defn toggle-coordinates! [board-state] - (swap! board-state update :show-coords? not)) - ; (if (:show-notation? @board-state) - ; (hide-coordinates! board-state) - ; (show-coordinates! board-state))) + (swap! board-state update :coords + (fn [coords-map] + (reduce + (fn [new-coords [position cfg]] + (assoc new-coords position (update cfg :show? not))) + {} + coords-map)))) ;; ----------------------------------------------------------------------------- ;; Constructor -(defn init-dom! - [board-state] - (let [{:keys [root-el] :as board-cfg} @board-state] - ;; write the container
s to the DOM - (dom-util/set-inner-html! root-el (html/BoardContainer board-cfg)) - ;; calculate width / height - (api/resize! board-state))) - ;; recommend they style the coordinate text using CSS ;; the chessboard API can support the "on/off" and position stuff + +;; FIXME: I think this needs to change +;; * "inside" or "outside" can be controlled using CSS +;; * "letters" or "numbers" is determined by ranks / files (def default-coords {:bottom {:position "outside", :show? false, :type "letters"} :left {:position "outside", :show? false, :type "numbers"} :right {:position "outside", :show? false, :type "numbers"} :top {:position "outside", :show? false, :type "letters"}}) +;; TODO: move this to DOM ops? +(defn update-coords! + "Update the DOM to match the coordinate config." + [board-state coords-config] + ; (js/console.log "updating coords:" (pr-str coords-config)) + (let [{:keys [container-id] :as _board-state} @board-state + board-container-sel (str "#" container-id " .board-container-41a68") + board-container-el (dom-util/get-element board-container-sel) + _ (when flags/runtime-checks? + (when-not board-container-el + (error-log "Unable to find board-container-el in update-coords!")))] + (doseq [[position-trbl css-class] css/coords->css] + (let [sel (str "#" container-id " ." css-class) + el (dom-util/get-element sel) + cfg (get coords-config position-trbl) + show? (true? (:show? cfg))] + (dom-util/remove-element! el) + (when show? + ;; FIXME: Pass their custom formatting fn here + (dom-util/append-html! board-container-el (html/CoordinateRow position-trbl))))))) + +(defn init-dom! + [board-state] + (let [{:keys [coords root-el] :as board-cfg} @board-state] + ;; write the container
s to the DOM + (dom-util/set-inner-html! root-el (html/BoardContainer board-cfg)) + ;; calculate width / height + (api/resize! board-state) + (update-coords! board-state coords))) + (def default-animate-speed-ms 80) ; (def default-animate-speed-ms 2500) @@ -906,12 +941,9 @@ (if (= "white" (:orientation new-state)) (set-white-orientation! board-atom) (set-black-orientation! board-atom))) - ;; FIXME: coordinate config change - ;; show / hide coordinates - (when-not (= (:show-coords? old-state) (:show-coords? new-state)) - (if (:show-coords? new-state) - (remove-class! (dom-util/get-element (:container-id new-state)) "hide-notation-cbe71") - (add-class! (dom-util/get-element (:container-id new-state)) "hide-notation-cbe71"))) + ;; coordinate config change + (when-not (= (:coords old-state) (:coords new-state)) + (update-coords! board-atom (:coords new-state))) ;; fire their onChange event (let [on-change-fn (:onChange new-state) old-position (:position old-state) diff --git a/src-cljs/com/oakmac/chessboard2/css.cljs b/src-cljs/com/oakmac/chessboard2/css.cljs index d4661f1..9c0d432 100644 --- a/src-cljs/com/oakmac/chessboard2/css.cljs +++ b/src-cljs/com/oakmac/chessboard2/css.cljs @@ -1,5 +1,11 @@ (ns com.oakmac.chessboard2.css) +(def coords->css + {:top "coordinates-top-f30c9" + :right "coordinates-right-7fc08" + :bottom "coordinates-bottom-ac241" + :left "coordinates-left-183e9"}) + ;; TODO: probably convert this to a map (def orientation-white "orientation-white-4de03") diff --git a/src-cljs/com/oakmac/chessboard2/html.cljs b/src-cljs/com/oakmac/chessboard2/html.cljs index e1416a7..b3cde0d 100644 --- a/src-cljs/com/oakmac/chessboard2/html.cljs +++ b/src-cljs/com/oakmac/chessboard2/html.cljs @@ -13,23 +13,37 @@ (declare piece->imgsrc) (defn FileCoordinates - [_cfg] + [position custom-fn] (let [num-files 8 - files (range 0 num-files)] + files (range 0 num-files) + html-fn (if (fn? custom-fn) + custom-fn + str)] (->> files (map (fn [f] - (str "
" (idx->alpha f) "
"))) + (template + (str "
{fileHTML}
") + {:file (idx->alpha f) + ;; FIXME: this function also should receive the position (top, right, bottom, left) + :fileHTML (html-fn (idx->alpha f))}))) (apply str)))) (defn RankCoordinates - [_cfg] + [position custom-fn] (let [num-ranks 8 - ranks (reverse (range 1 (inc num-ranks)))] + ranks (reverse (range 1 (inc num-ranks))) + html-fn (if (fn? custom-fn) + custom-fn + str)] (->> ranks (map (fn [r] - (str "
" r "
"))) + (template + (str "
{rankHTML}
") + {:rank r + ;; FIXME: this function also should receive the position (top, right, bottom, left) + :rankHTML (html-fn r)}))) (apply str)))) (defn DraggingPiece @@ -217,15 +231,25 @@ ;; NOTE: Squares container starts off with zero height and then is adjusted "' style='height:0'>{Squares}" "
" ;; end .squares-2dea6 - "
{FileCoordinates}
" - "
{RankCoordinates}
" - "
{FileCoordinates}
" - "
{RankCoordinates}
" + ; "
{FileCoordinates}
" + ; "
{RankCoordinates}
" + ; "
{FileCoordinates}
" + ; "
{RankCoordinates}
" "
" ;; end .board-container-41a68 "
") ;; end .chessboard-21da3 {:container-id container-id - :FileCoordinates (FileCoordinates opts) + ; :FileCoordinates (FileCoordinates opts) :items-container-id items-container-id - :RankCoordinates (RankCoordinates opts) + ; :RankCoordinates (RankCoordinates opts) :Squares (Squares opts) :squares-container-id squares-container-id})) + +;; TODO: pass their custom rank / file function here +(defn CoordinateRow + [trbl-position] + (template + "
{items}
" + {:cssClass (get css/coords->css trbl-position) + :items (case trbl-position + (:top :bottom) (FileCoordinates (name trbl-position) nil) + (:left :right) (RankCoordinates (name trbl-position) nil))})) From 60de4004d82b68bdc8120904003f27bdcde61d36 Mon Sep 17 00:00:00 2001 From: Chris Oakman Date: Wed, 19 Apr 2023 17:53:10 -0500 Subject: [PATCH 3/3] WIP WIP WIP --- src-cljs/com/oakmac/chessboard2/api.cljs | 4 -- src-cljs/com/oakmac/chessboard2/core.cljs | 20 +++++----- src-cljs/com/oakmac/chessboard2/js_api.cljs | 7 +++- src-cljs/test/chessboard2/js_api_test.cljs | 43 ++++++++++++++++++++- 4 files changed, 57 insertions(+), 17 deletions(-) diff --git a/src-cljs/com/oakmac/chessboard2/api.cljs b/src-cljs/com/oakmac/chessboard2/api.cljs index 5604afe..83f76b1 100644 --- a/src-cljs/com/oakmac/chessboard2/api.cljs +++ b/src-cljs/com/oakmac/chessboard2/api.cljs @@ -412,7 +412,3 @@ cfg2)] (swap! board-state merge validated-config) nil)) - -;; 9dabd59f-5ce7-483f-955a-57b0bccf30c9 -;; 21ec2a77-34e4-492e-ab1e-59e39e8ac241 -;; f02e8c66-7811-4e9c-b871-37fc083183e9 diff --git a/src-cljs/com/oakmac/chessboard2/core.cljs b/src-cljs/com/oakmac/chessboard2/core.cljs index fd0d5c0..db38872 100644 --- a/src-cljs/com/oakmac/chessboard2/core.cljs +++ b/src-cljs/com/oakmac/chessboard2/core.cljs @@ -888,17 +888,17 @@ ;; ----------------------------------------------------------------------------- ;; Constructor -;; recommend they style the coordinate text using CSS -;; the chessboard API can support the "on/off" and position stuff - -;; FIXME: I think this needs to change -;; * "inside" or "outside" can be controlled using CSS -;; * "letters" or "numbers" is determined by ranks / files +;; Notes on Coordinates: +;; * recommend they style the coordinate text using CSS +;; * chessboard2 API can support show / hide +;; * TRBL positioning options +;; * "style" can be String, Map, or Function +;; * "renderHTML" can be String or Function (def default-coords - {:bottom {:position "outside", :show? false, :type "letters"} - :left {:position "outside", :show? false, :type "numbers"} - :right {:position "outside", :show? false, :type "numbers"} - :top {:position "outside", :show? false, :type "letters"}}) + {:top {:show? false, :type "files", :style ""} + :right {:show? false, :type "ranks", :style ""} + :bottom {:show? false, :type "files", :style ""} + :left {:show? false, :type "ranks", :style ""}}) ;; TODO: move this to DOM ops? (defn update-coords! diff --git a/src-cljs/com/oakmac/chessboard2/js_api.cljs b/src-cljs/com/oakmac/chessboard2/js_api.cljs index 9e2f44e..7587bef 100644 --- a/src-cljs/com/oakmac/chessboard2/js_api.cljs +++ b/src-cljs/com/oakmac/chessboard2/js_api.cljs @@ -146,6 +146,11 @@ (apply merge)) {})) +; (defn parse-set-coordinates-arg +; "TODO: write me :-)" +; [arg] +; nil) + ;; FIXME: handle 0-0 and 0-0-0, user will have to specify white or black ;; FIXME: the .move() method should support pieces or item-ids ;; .movePiece() --> only Pieces @@ -341,5 +346,3 @@ ; :else (warn-log "Invalid args passed to config():" arg1 arg2))))) ;; TODO: actually add or remove coordinate elements from the DOM - -;; 583bb76a-10aa-4079-8d19-83a62ab0bf45 diff --git a/src-cljs/test/chessboard2/js_api_test.cljs b/src-cljs/test/chessboard2/js_api_test.cljs index 69df423..77f489e 100644 --- a/src-cljs/test/chessboard2/js_api_test.cljs +++ b/src-cljs/test/chessboard2/js_api_test.cljs @@ -2,7 +2,10 @@ (:require [cljs.test :refer [deftest is]] [com.oakmac.chessboard2.constants :refer [animate-speed-strings->times start-position]] - [com.oakmac.chessboard2.js-api :refer [parse-constructor-second-arg parse-move-args parse-set-position-args]] + [com.oakmac.chessboard2.js-api :refer [parse-constructor-second-arg + parse-move-args + parse-set-coordinates-args + parse-set-position-args]] [com.oakmac.chessboard2.util.fen :refer [fen->position]])) (def ruy-lopez-fen "r1bqkbnr/pppp1ppp/2n5/1B2p3/4P3/5N2/PPPP1PPP/RNBQK2R") @@ -111,3 +114,41 @@ (let [callback-fn1 (fn [] 1)] (is (= (parse-set-position-args [212 (js-obj "onComplete" callback-fn1)]) {:animateSpeed 212, :onComplete callback-fn1})))) + +;; TODO: make this work +; (deftest parse-set-coordinates-args-test +; (is (= (parse-set-coordinates-args nil) +; {})) +; (is (= (parse-set-coordinates-args "") +; {})) +; (is (= (parse-set-coordinates-args "tl") +; {:top {:type "ranks"} +; :left {:type "files"}})) +; (is (= (parse-set-coordinates-args "trbl") +; {:top {:type "ranks"} +; :right {:type "files"} +; :bottom {:type "ranks"} +; :left {:type "files"}})) +; (is (= (parse-set-coordinates-args "tlaz") +; {:top {:type "ranks"} +; :left {:type "files"}}) +; "invalid TRBL values are ignored") +; (is (= (parse-set-coordinates-args (array)) +; {})) +; (is (= (parse-set-coordinates-args (array "left" "bottom")) +; {:left {:type "files"} +; :bottom {:type "ranks"}})) +; (is (= (parse-set-coordinates-args (array "bottom" "left")) +; {:left {:type "files"} +; :bottom {:type "ranks"}}) +; "order does not matter") +; (is (= (parse-set-coordinates-args (array "left" "bottom" "foo")) +; {:left {:type "files"} +; :bottom {:type "ranks"}}) +; "invalid TRBL values are ignored") +; (is (= (parse-set-coordinates-args (js-obj "left" (js-obj "style" "font-size: 13px; color: blue;") +; "bottom" (js-obj "style" "text-transform: uppercase;"))) +; {:left {:type "files" +; :style "font-size: 13px; color: blue;"} +; :bottom {:type "ranks" +; :style "text-transform: uppercase;"}})))