proscenium 0.15.0.beta.2-x86_64-darwin → 0.15.0.beta.4-x86_64-darwin

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6051f0c0a8867125f4a6059bd11e76b332236051450a6207e5d402d8977ec58f
4
- data.tar.gz: 32f1a4325433c459a4cfc839e6f0ef4453f3bc2f8c1e044f1f0ca6ce2c828fc0
3
+ metadata.gz: c8fe10f018fd22079605fce2d978031b9f923edb789804a2b80845eee8e78d0e
4
+ data.tar.gz: a0b5e9633788960be763f301e15f9d9a7a54949e8deac70e3f0abcace630d0e9
5
5
  SHA512:
6
- metadata.gz: 6df4aa018bf1cf70184d680a56cda8a25ebf03745266a434fe947f2f251e399a593a722c62efeadb0f281168ebc8f6c431fe71df8bb57e73a80edd2d7a67ccc9
7
- data.tar.gz: '002806890da6f9387db8af353b52afe4ae709a1dec76181f81e9ec58802114fe5559bd6abddd65403ad0549193748d36830c9c55bbdd4911167cb6a0dc7f72e4'
6
+ metadata.gz: 4d8bd75a53cd2315ae735942091c60928d70ac46a5ba96a1afc5ea19be20da53cf37debc500a53ae497f3d9afdd67bc170f19fe8d5b1279784b9846cf59ed8ee
7
+ data.tar.gz: f8e8ea0d947606710ae48fa012b45f0ab95349e6f7b58bc9e2b7b47b2cec413fae8d30d0845fb6495357f4f721d907589a7f3a0d9077ae2b6ba302fd72bb7767
@@ -8,12 +8,28 @@ module Proscenium
8
8
  class Rewriter < RubyNext::Language::Rewriters::Text
9
9
  NAME = 'proscenium-css-module'
10
10
 
11
- def safe_rewrite(source)
12
- source.gsub(/:@([\w_]+)/) do |_|
13
- context.track! self
11
+ def rewrite(source)
12
+ source = source.gsub(/%i\[((@[\w@ ]+)|([\w@ ]+ @[\w@ ]+))\]/) do |_|
13
+ arr = ::Regexp.last_match(1).split.map do |x|
14
+ x.start_with?('@') ? css_module_string(x[1..]) : ":#{x}"
15
+ end
16
+ "[#{arr.join(',')}]"
17
+ end
18
+
19
+ source.gsub(/:@([\w]+)/) do |_|
20
+ context.track!(self)
21
+ css_module_string(::Regexp.last_match(1))
22
+ end
23
+ end
24
+
25
+ private
14
26
 
15
- match = ::Regexp.last_match(1)
16
- "Proscenium::CssModule::Name.new(:@#{match}, css_module(:#{match}))"
27
+ def css_module_string(name)
28
+ if (path = Pathname.new(context.path).sub_ext('.module.css')).exist?
29
+ tname = Transformer.new(path).class_name!(name, name.dup).first
30
+ "Proscenium::CssModule::Name.new(:@#{name}, '#{tname}')"
31
+ else
32
+ "Proscenium::CssModule::Name.new(:@#{name}, css_module(:#{name}))"
17
33
  end
18
34
  end
19
35
  end
Binary file
@@ -0,0 +1,17 @@
1
+ import DataConfirm from "./data_confirm";
2
+ import DataDisableWith from "./data_disable_with";
3
+
4
+ export default class UJS {
5
+ constructor() {
6
+ const dc = new DataConfirm();
7
+ const ddw = new DataDisableWith();
8
+
9
+ document.body.addEventListener(
10
+ "submit",
11
+ (event) => {
12
+ dc.onSubmit(event) && ddw.onSubmit(event);
13
+ },
14
+ { capture: true }
15
+ );
16
+ }
17
+ }
@@ -0,0 +1,16 @@
1
+ export default class DataConfirm {
2
+ onSubmit = event => {
3
+ if (!event.target.matches('[data-turbo=true]') && 'confirm' in event.submitter.dataset) {
4
+ const v = event.submitter.dataset.confirm
5
+
6
+ if (v !== 'false' && !confirm(v === 'true' || v === '' ? 'Are you sure?' : v)) {
7
+ event.preventDefault()
8
+ event.stopPropagation()
9
+ event.stopImmediatePropagation()
10
+ return false
11
+ }
12
+ }
13
+
14
+ return true
15
+ }
16
+ }
@@ -0,0 +1,68 @@
1
+ export default class DataDisableWith {
2
+ onSubmit = event => {
3
+ const target = event.target
4
+ const formId = target.id
5
+
6
+ if (target.matches('[data-turbo=true]')) return
7
+
8
+ const submitElements = Array.from(
9
+ target.querySelectorAll(
10
+ ['input[type=submit][data-disable-with]', 'button[type=submit][data-disable-with]'].join(
11
+ ', '
12
+ )
13
+ )
14
+ )
15
+
16
+ submitElements.push(
17
+ ...Array.from(
18
+ document.querySelectorAll(
19
+ [
20
+ `input[type=submit][data-disable-with][form='${formId}']`,
21
+ `button[type=submit][data-disable-with][form='${formId}']`
22
+ ].join(', ')
23
+ )
24
+ )
25
+ )
26
+
27
+ for (const ele of submitElements) {
28
+ if (ele.hasAttribute('form') && ele.getAttribute('form') !== target.id) continue
29
+
30
+ this.#disableButton(ele)
31
+ }
32
+ }
33
+
34
+ #disableButton(ele) {
35
+ const defaultTextValue = 'Please wait...'
36
+ let textValue = ele.dataset.disableWith || defaultTextValue
37
+ if (textValue === 'false') return
38
+ if (textValue === 'true') {
39
+ textValue = defaultTextValue
40
+ }
41
+
42
+ ele.disabled = true
43
+
44
+ if (ele.matches('button')) {
45
+ ele.dataset.valueBeforeDisabled = ele.innerHTML
46
+ ele.innerHTML = textValue
47
+ } else {
48
+ ele.dataset.valueBeforeDisabled = ele.value
49
+ ele.value = textValue
50
+ }
51
+
52
+ if (ele.resetDisableWith === undefined) {
53
+ // This function can be called on the element to reset the disabled state. Useful for when
54
+ // form submission fails, and the button should be re-enabled.
55
+ ele.resetDisableWith = function () {
56
+ this.disabled = false
57
+
58
+ if (this.matches('button')) {
59
+ this.innerHTML = this.dataset.valueBeforeDisabled
60
+ } else {
61
+ this.value = this.dataset.valueBeforeDisabled
62
+ }
63
+
64
+ delete this.dataset.valueBeforeDisabled
65
+ }
66
+ }
67
+ }
68
+ }
@@ -0,0 +1,9 @@
1
+ export default async () => {
2
+ window.Proscenium = window.Proscenium || {};
3
+
4
+ if (!window.Proscenium.UJS) {
5
+ const classPath = "/@proscenium/ujs/class.js";
6
+ const module = await import(classPath);
7
+ window.Proscenium.UJS = new module.default();
8
+ }
9
+ };
@@ -21,6 +21,7 @@ module Proscenium
21
21
  end
22
22
 
23
23
  def capture_and_replace_proscenium_stylesheets # rubocop:disable Metrics/*
24
+ return if response_body.nil?
24
25
  return if response_body.first.blank? || !Proscenium::Importer.css_imported?
25
26
  return unless response_body.first.include? '<!-- [PROSCENIUM_STYLESHEETS] -->'
26
27
 
@@ -52,6 +53,7 @@ module Proscenium
52
53
  end
53
54
 
54
55
  def capture_and_replace_proscenium_javascripts # rubocop:disable Metrics/*
56
+ return if response_body.nil?
55
57
  return if response_body.first.blank? || !Proscenium::Importer.js_imported?
56
58
 
57
59
  imports = Proscenium::Importer.imported.dup
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Proscenium
4
- VERSION = '0.15.0.beta.2'
4
+ VERSION = '0.15.0.beta.4'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: proscenium
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.0.beta.2
4
+ version: 0.15.0.beta.4
5
5
  platform: x86_64-darwin
6
6
  authors:
7
7
  - Joel Moss
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-02-23 00:00:00.000000000 Z
11
+ date: 2024-03-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -118,6 +118,10 @@ files:
118
118
  - lib/proscenium/libs/react-manager/react.js
119
119
  - lib/proscenium/libs/stimulus-loading.js
120
120
  - lib/proscenium/libs/test.js
121
+ - lib/proscenium/libs/ujs/class.js
122
+ - lib/proscenium/libs/ujs/data_confirm.js
123
+ - lib/proscenium/libs/ujs/data_disable_with.js
124
+ - lib/proscenium/libs/ujs/index.js
121
125
  - lib/proscenium/log_subscriber.rb
122
126
  - lib/proscenium/middleware.rb
123
127
  - lib/proscenium/middleware/base.rb