plutonium 0.15.21 → 0.15.23

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,11 +8,11 @@ module Plutonium
8
8
 
9
9
  class Builder < Builder
10
10
  def association_tag(**, &)
11
- create_component(Plutonium::UI::Display::Component::Association, :association, **, &)
11
+ create_component(Plutonium::UI::Display::Component::AssociationField, :association, **, &)
12
12
  end
13
13
 
14
14
  def markdown_tag(**, &)
15
- create_component(Plutonium::UI::Display::Component::Markdown, :markdown, **, &)
15
+ create_component(Plutonium::UI::Display::Component::MarkdownField, :markdown, **, &)
16
16
  end
17
17
  end
18
18
 
@@ -4,7 +4,7 @@ module Plutonium
4
4
  module UI
5
5
  module Display
6
6
  module Component
7
- class Association < Phlexi::Display::Components::Association
7
+ class AssociationField < Phlexi::Display::Components::Association
8
8
  include Plutonium::UI::Component::Methods
9
9
 
10
10
  def render_value(value)
@@ -6,7 +6,7 @@ module Plutonium
6
6
  module UI
7
7
  module Display
8
8
  module Component
9
- class Markdown < Phlexi::Display::Components::Base
9
+ class MarkdownField < Phlexi::Display::Components::Base
10
10
  include Phlexi::Display::Components::Concerns::DisplaysValue
11
11
 
12
12
  RENDERER = Redcarpet::Markdown.new(Redcarpet::Render::HTML, autolink: true, tables: true)
@@ -16,6 +16,16 @@ module Plutonium
16
16
  unsafe_raw RENDERER.render(value)
17
17
  end
18
18
  end
19
+
20
+ private
21
+
22
+ def normalize_value(value)
23
+ if value.respond_to?(:to_plain_text)
24
+ value.to_plain_text
25
+ else
26
+ value.to_s
27
+ end
28
+ end
19
29
  end
20
30
  end
21
31
  end
@@ -10,7 +10,7 @@ module Plutonium
10
10
  include Plutonium::UI::Form::Options::InferredTypes
11
11
 
12
12
  def easymde_tag(**, &)
13
- create_component(Plutonium::UI::Form::Components::Easymde, :easymde, **, &)
13
+ create_component(Plutonium::UI::Form::Components::EasymdeInput, :easymde, **, &)
14
14
  end
15
15
  alias_method :markdown_tag, :easymde_tag
16
16
 
@@ -19,6 +19,10 @@ module Plutonium
19
19
  basic_select_tag(**, data_controller: "slim-select", class!: "", &)
20
20
  end
21
21
  alias_method :select_tag, :slim_select_tag
22
+
23
+ def flatpickr_tag(**, &)
24
+ create_component(Plutonium::UI::Form::Components::FlatpickrInput, :flatpickr, **, &)
25
+ end
22
26
  end
23
27
 
24
28
  private
@@ -4,11 +4,21 @@ module Plutonium
4
4
  module UI
5
5
  module Form
6
6
  module Components
7
- class Easymde < Phlexi::Form::Components::Base
7
+ class EasymdeInput < Phlexi::Form::Components::Base
8
8
  include Phlexi::Form::Components::Concerns::HandlesInput
9
9
 
10
10
  def view_template
11
- textarea(**attributes, data_controller: "easymde") { field.dom.value }
11
+ textarea(**attributes, data_controller: "easymde") { normalize_value(field.value) }
12
+ end
13
+
14
+ private
15
+
16
+ def normalize_value(value)
17
+ if value.respond_to?(:to_plain_text)
18
+ value.to_plain_text
19
+ else
20
+ value.to_s
21
+ end
12
22
  end
13
23
  end
14
24
  end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Plutonium
4
+ module UI
5
+ module Form
6
+ module Components
7
+ class FlatpickrInput < Phlexi::Form::Components::Input
8
+ private
9
+
10
+ def build_input_attributes
11
+ super
12
+ attributes[:data_controller] = tokens(attributes[:data_controller], :flatpickr)
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -8,10 +8,14 @@ module Plutonium
8
8
  private
9
9
 
10
10
  def infer_field_component
11
+ return :markdown if inferred_field_type == :rich_text
12
+
11
13
  component = super
12
14
  case component
13
15
  when :select
14
16
  :slim_select
17
+ when :date, :time, :datetime
18
+ :flatpickr
15
19
  else
16
20
  component
17
21
  end
@@ -37,7 +37,12 @@ module Plutonium
37
37
  # error themes
38
38
  error: "mt-2 text-sm text-red-600 dark:text-red-500",
39
39
  # button themes
40
- button: "px-4 py-2 bg-primary-600 text-white rounded-md hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-primary-500"
40
+ button: "px-4 py-2 bg-primary-600 text-white rounded-md hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-primary-500",
41
+ # flatpickr
42
+ flatpickr: :input,
43
+ valid_flatpickr: :valid_input,
44
+ invalid_flatpickr: :invalid_input,
45
+ neutral_flatpickr: :neutral_input
41
46
  })
42
47
  end
43
48
  end
@@ -126,6 +126,12 @@ module Plutonium
126
126
  end
127
127
 
128
128
  def render_external_styles
129
+ link(
130
+ rel: "stylesheet",
131
+ href: "https://cdn.jsdelivr.net/npm/flatpickr@4.6.13/dist/flatpickr.min.css",
132
+ integrity: "sha384-RkASv+6KfBMW9eknReJIJ6b3UnjKOKC5bOUaNgIY778NFbQ8MtWq9Lr/khUgqtTt",
133
+ crossorigin: "anonymous"
134
+ )
129
135
  end
130
136
 
131
137
  def render_scripts
@@ -146,6 +152,11 @@ module Plutonium
146
152
  integrity: "sha384-WKsmo+vSs0gqrT+es6wFEojVFn4P0kNaHpHTIkn84iHY8T4rF2V2McZeSbLPLlHy",
147
153
  crossorigin: "anonymous"
148
154
  )
155
+ script(
156
+ src: "https://cdn.jsdelivr.net/npm/flatpickr@4.6.13/dist/flatpickr.min.js",
157
+ integrity: "sha384-5JqMv4L/Xa0hfvtF06qboNdhvuYXUku9ZrhZh3bSk8VXF0A/RuSLHpLsSV9Zqhl6",
158
+ crossorigin: "anonymous"
159
+ )
149
160
  end
150
161
 
151
162
  def render_body_scripts
@@ -1,5 +1,5 @@
1
1
  module Plutonium
2
- VERSION = "0.15.21"
2
+ VERSION = "0.15.23"
3
3
  NEXT_MAJOR_VERSION = VERSION.split(".").tap { |v|
4
4
  v[1] = v[1].to_i + 1
5
5
  v[2] = 0
data/package-lock.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@radioactive-labs/plutonium",
3
- "version": "0.1.11",
3
+ "version": "0.1.12",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@radioactive-labs/plutonium",
9
- "version": "0.1.11",
9
+ "version": "0.1.12",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@hotwired/stimulus": "^3.2.2",
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@radioactive-labs/plutonium",
3
- "version": "0.1.11",
3
+ "version": "0.1.12",
4
4
  "description": "Core assets for the Plutonium gem",
5
5
  "type": "module",
6
6
  "main": "src/js/core.js",
@@ -0,0 +1,28 @@
1
+ import { Controller } from "@hotwired/stimulus"
2
+
3
+ // Connects to data-controller="flatpickr"
4
+ export default class extends Controller {
5
+ connect() {
6
+ console.log(`flatpickr connected: ${this.element}`)
7
+ self.picker = new flatpickr(this.element, this.#buildOptions())
8
+ }
9
+
10
+ disconnect() {
11
+ self.picker.destroy()
12
+ self.picker = null
13
+ }
14
+
15
+ #buildOptions() {
16
+ let options = { altInput: true }
17
+ if (this.element.attributes.type.value == "datetime-local") {
18
+ options.enableTime = true
19
+ }
20
+ else if (this.element.attributes.type.value == "time") {
21
+ options.enableTime = true
22
+ options.noCalendar = true
23
+ // options.time_24hr = true
24
+ // options.altFormat = "H:i"
25
+ }
26
+ return options
27
+ }
28
+ }
@@ -23,6 +23,7 @@ import FrameNavigatorController from "./frame_navigator_controller.js"
23
23
  import ColorModeController from "./color_mode_controller.js"
24
24
  import EasyMDEController from "./easymde_controller.js"
25
25
  import SlimSelectController from "./slim_select_controller.js"
26
+ import FlatpickrController from "./flatpickr_controller.js"
26
27
 
27
28
  export default function (application) {
28
29
  // Register controllers here
@@ -50,4 +51,5 @@ export default function (application) {
50
51
  application.register("color-mode", ColorModeController)
51
52
  application.register("easymde", EasyMDEController)
52
53
  application.register("slim-select", SlimSelectController)
54
+ application.register("flatpickr", FlatpickrController)
53
55
  }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: plutonium
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.21
4
+ version: 0.15.23
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefan Froelich
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-11-26 00:00:00.000000000 Z
11
+ date: 2024-11-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: zeitwerk
@@ -1400,15 +1400,16 @@ files:
1400
1400
  - lib/plutonium/ui/component/kit.rb
1401
1401
  - lib/plutonium/ui/component/methods.rb
1402
1402
  - lib/plutonium/ui/display/base.rb
1403
- - lib/plutonium/ui/display/component/association.rb
1404
- - lib/plutonium/ui/display/component/markdown.rb
1403
+ - lib/plutonium/ui/display/component/association_field.rb
1404
+ - lib/plutonium/ui/display/component/markdown_field.rb
1405
1405
  - lib/plutonium/ui/display/resource.rb
1406
1406
  - lib/plutonium/ui/display/theme.rb
1407
1407
  - lib/plutonium/ui/dyna_frame/content.rb
1408
1408
  - lib/plutonium/ui/dyna_frame/host.rb
1409
1409
  - lib/plutonium/ui/empty_card.rb
1410
1410
  - lib/plutonium/ui/form/base.rb
1411
- - lib/plutonium/ui/form/components/easymde.rb
1411
+ - lib/plutonium/ui/form/components/easymde_input.rb
1412
+ - lib/plutonium/ui/form/components/flatpickr_input.rb
1412
1413
  - lib/plutonium/ui/form/concerns/renders_nested_resource_fields.rb
1413
1414
  - lib/plutonium/ui/form/interaction.rb
1414
1415
  - lib/plutonium/ui/form/options/inferred_types.rb
@@ -1461,6 +1462,7 @@ files:
1461
1462
  - src/css/slim_select.css
1462
1463
  - src/js/controllers/color_mode_controller.js
1463
1464
  - src/js/controllers/easymde_controller.js
1465
+ - src/js/controllers/flatpickr_controller.js
1464
1466
  - src/js/controllers/form_controller.js
1465
1467
  - src/js/controllers/frame_navigator_controller.js
1466
1468
  - src/js/controllers/has_many_panel_controller.js