diff --git a/app/javascript/alchemy_admin/picture_editors.js b/app/javascript/alchemy_admin/picture_editors.js index 14af193aa7..ae2a3679ca 100644 --- a/app/javascript/alchemy_admin/picture_editors.js +++ b/app/javascript/alchemy_admin/picture_editors.js @@ -1,5 +1,5 @@ import debounce from "alchemy_admin/utils/debounce" -import max from "lodash-es/max" +import max from "alchemy_admin/utils/max" import { get } from "alchemy_admin/utils/ajax" import ImageLoader from "alchemy_admin/image_loader" diff --git a/app/javascript/alchemy_admin/utils/max.js b/app/javascript/alchemy_admin/utils/max.js new file mode 100644 index 0000000000..9e666c0074 --- /dev/null +++ b/app/javascript/alchemy_admin/utils/max.js @@ -0,0 +1,3 @@ +export default function (a, b) { + return a >= b ? a : b +} diff --git a/config/importmap.rb b/config/importmap.rb index 46d809504e..57a2618f27 100644 --- a/config/importmap.rb +++ b/config/importmap.rb @@ -1,6 +1,5 @@ pin "@ungap/custom-elements", to: "https://ga.jspm.io/npm:@ungap/custom-elements@1.3.0/index.js", preload: true pin "flatpickr", to: "https://ga.jspm.io/npm:flatpickr@4.6.13/dist/esm/index.js", preload: true -pin "lodash-es/max", to: "https://ga.jspm.io/npm:lodash-es@4.17.21/max.js", preload: true pin "sortablejs", to: "https://ga.jspm.io/npm:sortablejs@1.15.1/modular/sortable.esm.js", preload: true pin "@hotwired/turbo-rails", to: "turbo.min.js", preload: true pin "@shoelace/animation-registry", to: "https://cdn.jsdelivr.net/npm/@shoelace-style/shoelace@2.12.0/cdn/utilities/animation-registry.js", preload: true diff --git a/spec/javascript/alchemy_admin/utils/max.spec.js b/spec/javascript/alchemy_admin/utils/max.spec.js new file mode 100644 index 0000000000..d068d0b1c2 --- /dev/null +++ b/spec/javascript/alchemy_admin/utils/max.spec.js @@ -0,0 +1,21 @@ +import max from "alchemy_admin/utils/max.js" + +describe("max", () => { + it("should return the maximum value between two numbers", () => { + expect(max(2, 5)).toBe(5) + expect(max(-10, 0)).toBe(0) + expect(max(100, 100)).toBe(100) + }) + + it("should return the maximum value between two negative numbers", () => { + expect(max(-5, -2)).toBe(-2) + expect(max(-10, -10)).toBe(-10) + expect(max(-100, -50)).toBe(-50) + }) + + it("should return the maximum value between a positive and a negative number", () => { + expect(max(5, -2)).toBe(5) + expect(max(-10, 10)).toBe(10) + expect(max(-100, 50)).toBe(50) + }) +})