plutonium 0.20.4 → 0.21.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,6 +8,8 @@ module Plutonium
8
8
 
9
9
  attr_reader :resource_fields, :resource_definition
10
10
 
11
+ alias_method :record, :object
12
+
11
13
  def initialize(*, resource_fields:, resource_definition:, **, &)
12
14
  super(*, **, &)
13
15
  @resource_fields = resource_fields
@@ -59,12 +61,23 @@ module Plutonium
59
61
  input_definition = definition.defined_inputs[name] || {}
60
62
  input_options = input_definition[:options] || {}
61
63
 
64
+ condition = input_options[:condition] || field_options[:condition]
65
+ return if condition && !instance_exec(&condition)
66
+
62
67
  tag = input_options[:as] || field_options[:as]
63
- tag_attributes = input_options.except(:wrapper, :as)
64
- tag_block = input_definition[:block] || ->(f) {
65
- tag ||= f.inferred_field_component
66
- f.send(:"#{tag}_tag", **tag_attributes)
67
- }
68
+ tag_attributes =
69
+ input_options.except(:wrapper, :as, :pre_submit, :condition)
70
+ if input_options[:pre_submit]
71
+ tag_attributes[
72
+ "data-action"
73
+ ] = "change->form#preSubmit"
74
+ end
75
+ tag_block =
76
+ input_definition[:block] ||
77
+ ->(f) do
78
+ tag ||= f.inferred_field_component
79
+ f.send(:"#{tag}_tag", **tag_attributes)
80
+ end
68
81
 
69
82
  wrapper_options = input_options[:wrapper] || {}
70
83
  if !wrapper_options[:class] || !wrapper_options[:class].include?("col-span")
@@ -73,8 +86,10 @@ module Plutonium
73
86
  wrapper_options[:class] = tokens("col-span-full", wrapper_options[:class])
74
87
  end
75
88
 
76
- field_options = field_options.except(:as)
77
- render form.field(name, **field_options).wrapped(**wrapper_options) do |f|
89
+ field_options = field_options.except(:as, :condition)
90
+ render form.field(name, **field_options).wrapped(
91
+ **wrapper_options
92
+ ) do |f|
78
93
  render instance_exec(f, &tag_block)
79
94
  end
80
95
  end
@@ -37,7 +37,7 @@ module Plutonium
37
37
  # file
38
38
  # file: "w-full border rounded-md shadow-sm font-medium text-sm dark:bg-gray-700 focus:outline-none",
39
39
  # hint themes
40
- hint: "mt-2 text-sm text-gray-500 dark:text-gray-200",
40
+ hint: "mt-2 text-sm text-gray-500 dark:text-gray-200 whitespace-pre",
41
41
  # error themes
42
42
  error: "mt-2 text-sm text-red-600 dark:text-red-500",
43
43
  # button themes
@@ -1,5 +1,5 @@
1
1
  module Plutonium
2
- VERSION = "0.20.4"
2
+ VERSION = "0.21.1"
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.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@radioactive-labs/plutonium",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "description": "Core assets for the Plutonium gem",
5
5
  "type": "module",
6
6
  "main": "src/js/core.js",
@@ -1,11 +1,27 @@
1
1
  import { Controller } from "@hotwired/stimulus"
2
- import debounce from "lodash.debounce";
3
2
 
4
3
  // Connects to data-controller="form"
5
4
  export default class extends Controller {
6
5
  connect() {
7
6
  }
7
+
8
+ preSubmit() {
9
+ // Create a hidden input field
10
+ const hiddenField = document.createElement('input');
11
+ hiddenField.type = 'hidden';
12
+ hiddenField.name = 'pre_submit';
13
+ hiddenField.value = 'true';
14
+
15
+ // Append it to the form
16
+ this.element.appendChild(hiddenField);
8
17
 
18
+ // Skip validation by setting novalidate attribute
19
+ this.element.setAttribute('novalidate', '');
20
+
21
+ // Submit the form
22
+ this.submit();
23
+ }
24
+
9
25
  submit() {
10
26
  this.element.requestSubmit()
11
27
  }
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.20.4
4
+ version: 0.21.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefan Froelich
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-03-15 00:00:00.000000000 Z
11
+ date: 2025-04-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: zeitwerk
@@ -750,6 +750,7 @@ files:
750
750
  - lib/plutonium/interaction/README.md
751
751
  - lib/plutonium/interaction/base.rb
752
752
  - lib/plutonium/interaction/concerns/workflow_dsl.rb
753
+ - lib/plutonium/interaction/nested_attributes.rb
753
754
  - lib/plutonium/interaction/outcome.rb
754
755
  - lib/plutonium/interaction/response/base.rb
755
756
  - lib/plutonium/interaction/response/failure.rb