module Coco module App class SlideEditor < Coco::Component include Coco::AppComponentsHelper include Coco::BookComponentsHelper include Coco::FormatHelper DEFAULT_LAYOUT = "one-col-title" renders_one :title, ->(value = nil, **textarea_options) do Coco::SeamlessTextarea.new(**textarea_options, value: value, multiline: false, focus: true, data: {role: "title-editor"}, x: {modelable: "value", model: "title"}) end renders_one :text_1, ->(value = nil, **textarea_options) do Coco::SeamlessTextarea.new(**textarea_options, value: value, multiline: true, data: {role: "text-1-editor"}, x: {modelable: "value", model: "text1"}) end renders_one :text_2, ->(value = nil, **textarea_options) do Coco::SeamlessTextarea.new(**textarea_options, value: value, multiline: true, data: {role: "text-2-editor"}, x: {modelable: "value", model: "text2"}) end renders_one :image_1, ->(src = nil, **image_options) do @image_1_options = {src: src, **image_options} end renders_one :image_2, ->(src = nil, **image_options) do @image_2_options = {src: src, **image_options} end renders_one :bg_color, ->(value = nil, **input_options) do @bg_color_options = {selected: value, **input_options} end renders_one :text_color, ->(value = nil, **input_options) do @text_color_options = {selected: value, **input_options} end renders_one :bg_image, ->(src = nil, **input_options) do @bg_image_options = {src: src, **input_options} end renders_one :layout, ->(value = DEFAULT_LAYOUT, **input_options) do @layout_options = {selected: value&.to_s&.tr("_", "-"), **input_options} end def initialize(generate_thumbnail: true, **kwargs) @generate_thumbnail = generate_thumbnail end def generate_thumbnail? = @generate_thumbnail def slide_args { bg_image: bg_image_src, bg_color_hex: bg_color_css, text_color_hex: text_color_css, layout: current_layout, render_empty: true } end def alpine_props { bg_color: bg_color_css, text_color: text_color_css, title: title&.value, text_1: text_1&.value, text_2: text_2&.value, image_1: image_1_src, image_2: image_2_src, bg_image: bg_image_src, layout: current_layout } end def bg_color_css @bg_color_options[:selected] if @bg_color_options end def text_color_css @text_color_options[:selected] if @text_color_options end def bg_image_src @bg_image_options[:src] if @bg_image_options end def image_1_src @image_1_options[:src] if @image_1_options end def image_2_src @image_2_options[:src] if @image_2_options end def current_layout @layout_options&.fetch(:selected, DEFAULT_LAYOUT) || DEFAULT_LAYOUT end end end end