shoelace-rails 0.4.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/main.yml +11 -61
  3. data/.gitignore +1 -6
  4. data/Appraisals +6 -0
  5. data/CHANGELOG.md +22 -5
  6. data/Gemfile +0 -3
  7. data/Rakefile +2 -17
  8. data/app/helpers/shoelace/form_helper.rb +63 -14
  9. data/gemfiles/rails_60.gemfile +0 -1
  10. data/gemfiles/rails_61.gemfile +0 -1
  11. data/gemfiles/rails_70.gemfile +0 -1
  12. data/gemfiles/rails_71.gemfile +10 -0
  13. data/gemfiles/rails_edge.gemfile +0 -1
  14. data/lib/shoelace/rails/version.rb +1 -1
  15. data/shoelace-rails.gemspec +1 -1
  16. data/test/helpers/form_helper_test.rb +40 -11
  17. data/test/helpers/translation_test.rb +160 -0
  18. metadata +7 -58
  19. data/dist/.keep +0 -0
  20. data/dist/types/.keep +0 -0
  21. data/package.json +0 -50
  22. data/rollup.config.js +0 -49
  23. data/src/index.ts +0 -2
  24. data/src/turbo/index.ts +0 -6
  25. data/src/turbo/polyfills/formdata-event.js +0 -27
  26. data/src/turbo/sl-turbo-form.ts +0 -110
  27. data/src/turbolinks/features/confirm.ts +0 -42
  28. data/src/turbolinks/features/disable.ts +0 -94
  29. data/src/turbolinks/features/remote.ts +0 -107
  30. data/src/turbolinks/index.ts +0 -6
  31. data/src/turbolinks/selectors.ts +0 -38
  32. data/src/turbolinks/start.ts +0 -38
  33. data/src/turbolinks/turbolinks.ts +0 -78
  34. data/src/turbolinks/utils/ajax.ts +0 -146
  35. data/src/turbolinks/utils/csp.ts +0 -20
  36. data/src/turbolinks/utils/csrf.ts +0 -33
  37. data/src/turbolinks/utils/dom.ts +0 -40
  38. data/src/turbolinks/utils/event.ts +0 -57
  39. data/src/turbolinks/utils/form.ts +0 -58
  40. data/test/dummy_app/Gemfile +0 -19
  41. data/test/dummy_app/Rakefile +0 -6
  42. data/test/dummy_app/app/controllers/hotwire_forms_controller.rb +0 -46
  43. data/test/dummy_app/app/controllers/turbolinks_forms_controller.rb +0 -37
  44. data/test/dummy_app/app/models/user.rb +0 -16
  45. data/test/dummy_app/app/packs/entrypoints/hotwire.js +0 -1
  46. data/test/dummy_app/app/packs/entrypoints/turbolinks.js +0 -5
  47. data/test/dummy_app/app/views/hotwire_forms/form.html.erb +0 -45
  48. data/test/dummy_app/app/views/hotwire_forms/show.html.erb +0 -5
  49. data/test/dummy_app/app/views/layouts/application.html.erb +0 -39
  50. data/test/dummy_app/app/views/turbolinks_forms/form.html.erb +0 -44
  51. data/test/dummy_app/app/views/turbolinks_forms/show.html.erb +0 -5
  52. data/test/dummy_app/bin/rails +0 -5
  53. data/test/dummy_app/bin/webpack +0 -18
  54. data/test/dummy_app/bin/yarn +0 -18
  55. data/test/dummy_app/config/application.rb +0 -16
  56. data/test/dummy_app/config/boot.rb +0 -4
  57. data/test/dummy_app/config/environment.rb +0 -2
  58. data/test/dummy_app/config/environments/development.rb +0 -10
  59. data/test/dummy_app/config/environments/test.rb +0 -18
  60. data/test/dummy_app/config/routes.rb +0 -4
  61. data/test/dummy_app/config/webpack/development.js +0 -5
  62. data/test/dummy_app/config/webpack/production.js +0 -1
  63. data/test/dummy_app/config/webpack/test.js +0 -5
  64. data/test/dummy_app/config/webpacker.yml +0 -33
  65. data/test/dummy_app/config.ru +0 -6
  66. data/test/dummy_app/package.json +0 -24
  67. data/test/dummy_app/test/system/hotwire_form_test.rb +0 -63
  68. data/test/dummy_app/test/system/turbolinks_form_test.rb +0 -38
  69. data/test/dummy_app/test/test_helper.rb +0 -68
  70. data/tsconfig.json +0 -19
  71. data/yarn.lock +0 -249
@@ -0,0 +1,160 @@
1
+ # frozen_string_literal: true
2
+ require 'test_helper'
3
+
4
+ require_relative '../../app/helpers/shoelace/form_helper'
5
+
6
+ class TranslationTest < ActionView::TestCase
7
+ include ActionView::Helpers::TranslationHelper
8
+ include Shoelace::FormHelper
9
+
10
+ AUTOCOMPLETE_ATTRIBUTE = ActionView::VERSION::STRING >= '6.1.0' ? 'autocomplete="off"' : ''
11
+
12
+ setup do
13
+ I18n.backend.store_translations :en,
14
+ helpers: {
15
+ label: {
16
+ user: { name: "Full Name" }
17
+ }
18
+ }
19
+
20
+ view_paths = ActionController::Base.view_paths
21
+ view_paths.each(&:clear_cache)
22
+ @view = ::ActionView::Base.with_empty_template_cache.with_view_paths(view_paths, {})
23
+ end
24
+
25
+ teardown do
26
+ I18n.backend.reload!
27
+ end
28
+
29
+ test "Form helpers should respect label translations" do
30
+ sl_form_for(User.new, url: "/") do |form|
31
+ assert_dom_equal <<~HTML, form.text_field(:name)
32
+ <sl-input label="Full Name" type="text" name="user[name]" id="user_name"></sl-input>
33
+ HTML
34
+ end
35
+ end
36
+
37
+ test "#color_field should respect label translations" do
38
+ sl_form_for(User.new, url: "/") do |form|
39
+ assert_dom_equal <<~HTML, form.color_field(:name)
40
+ <sl-color-picker name="user[name]" id="user_name" label="Full Name"></sl-color-picker>
41
+ HTML
42
+ end
43
+ end
44
+
45
+ test "#range_field should respect label translations" do
46
+ sl_form_for(User.new, url: "/") do |form|
47
+ assert_dom_equal <<~HTML, form.range_field(:name)
48
+ <sl-range label="Full Name" name="user[name]" id="user_name"></sl-range>
49
+ HTML
50
+ end
51
+ end
52
+
53
+ test "#switch_field should respect label translations" do
54
+ sl_form_for(User.new, url: "/") do |form|
55
+ assert_dom_equal <<~HTML, form.switch_field(:name)
56
+ <sl-switch name="user[name]" id="user_name">Full Name</sl-switch>
57
+ HTML
58
+ end
59
+ end
60
+
61
+ test "#text_area should respect label translations" do
62
+ sl_form_for(User.new, url: "/") do |form|
63
+ assert_dom_equal <<~HTML, form.text_area(:name)
64
+ <sl-textarea label="Full Name" resize="auto" name="user[name]" id="user_name"></sl-textarea>
65
+ HTML
66
+ end
67
+ end
68
+
69
+ test "#check_box should respect label translations" do
70
+ sl_form_for(User.new, url: "/") do |form|
71
+ assert_dom_equal <<~HTML, form.check_box(:name)
72
+ <input name="user[name]" type="hidden" value="0" #{AUTOCOMPLETE_ATTRIBUTE} />
73
+ <sl-checkbox value="1" name="user[name]" id="user_name">Full Name</sl-checkbox>
74
+ HTML
75
+ end
76
+ end
77
+
78
+ test "#selec should respect label translationst" do
79
+ users = {
80
+ "Yuki Nishijima" => 1,
81
+ "Matz" => 2,
82
+ "Koichi Sasada" => 3
83
+ }
84
+
85
+ sl_form_for(User.new, url: "/") do |form|
86
+ assert_dom_equal <<~HTML, form.select(:name, users)
87
+ <sl-select label="Full Name" name="user[name]" id="user_name">
88
+ <sl-option value="1">Yuki Nishijima</sl-option>
89
+ <sl-option value="2">Matz</sl-option>
90
+ <sl-option value="3">Koichi Sasada</sl-option>
91
+ </sl-select>
92
+ HTML
93
+ end
94
+ end
95
+
96
+ test "#collection_select should respect label translations" do
97
+ users = {
98
+ 1 => "Yuki Nishijima",
99
+ 2 => "Matz",
100
+ 3 => "Koichi Sasada",
101
+ }
102
+
103
+ sl_form_for(User.new, url: "/") do |form|
104
+ assert_dom_equal <<~HTML, form.collection_select(:name, users, :first, :last)
105
+ <sl-select label="Full Name" name="user[name]" id="user_name">
106
+ <sl-option value="1">Yuki Nishijima</sl-option>
107
+ <sl-option value="2">Matz</sl-option>
108
+ <sl-option value="3">Koichi Sasada</sl-option>
109
+ </sl-select>
110
+ HTML
111
+ end
112
+ end
113
+
114
+ test "#grouped_collection_select should respect label translations" do
115
+ users = [
116
+ OpenStruct.new(
117
+ group_name: "Main maintainers",
118
+ members: [
119
+ OpenStruct.new(id: 1, name: "Matz"),
120
+ OpenStruct.new(id: 2, name: "Koichi Sasada"),
121
+ ]
122
+ ),
123
+ OpenStruct.new(
124
+ group_name: "Default gem maintainers",
125
+ members: [OpenStruct.new(id: 3, name: "Yuki Nishijima")]
126
+ ),
127
+ ]
128
+
129
+ sl_form_for(User.new(name: "2"), url: "/") do |form|
130
+ assert_dom_equal <<~HTML, form.grouped_collection_select(:name, users, :members, :group_name, :id, :name)
131
+ <sl-select label="Full Name" name="user[name]" id="user_name" value="2">
132
+ <small>Main maintainers</small>
133
+ <sl-option value="1">Matz</sl-option>
134
+ <sl-option value="2" checked="checked">Koichi Sasada</sl-option>
135
+ <sl-divider></sl-divider>
136
+ <small>Default gem maintainers</small>
137
+ <sl-option value="3">Yuki Nishijima</sl-option>
138
+ </sl-select>
139
+ HTML
140
+ end
141
+ end
142
+
143
+ test "#collection_radio_buttons should respect label translations" do
144
+ users = {
145
+ 1 => "Yuki Nishijima",
146
+ 2 => "Matz",
147
+ 3 => "Koichi Sasada",
148
+ }
149
+
150
+ sl_form_for(User.new, url: "/") do |form|
151
+ assert_dom_equal <<~HTML, form.collection_radio_buttons(:name, users, :first, :last)
152
+ <sl-radio-group label="Full Name" name="user[name]" id="user_name">
153
+ <sl-radio value="1" id="user_name_1">Yuki Nishijima</sl-radio>
154
+ <sl-radio value="2" id="user_name_2">Matz</sl-radio>
155
+ <sl-radio value="3" id="user_name_3">Koichi Sasada</sl-radio>
156
+ </sl-radio-group>
157
+ HTML
158
+ end
159
+ end
160
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shoelace-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuki Nishijima
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-03-21 00:00:00.000000000 Z
11
+ date: 2024-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionview
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: 2.0.3
75
+ version: 2.2.0
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
- version: 2.0.3
82
+ version: 2.2.0
83
83
  description: The shoelace-rails gem adds useful view helper methods for using Shoalace
84
84
  Web Components.
85
85
  email:
@@ -101,14 +101,13 @@ files:
101
101
  - app/helpers/shoelace/tag_helper.rb
102
102
  - bin/console
103
103
  - bin/setup
104
- - dist/.keep
105
- - dist/types/.keep
106
104
  - gemfiles/rails_50.gemfile
107
105
  - gemfiles/rails_51.gemfile
108
106
  - gemfiles/rails_52.gemfile
109
107
  - gemfiles/rails_60.gemfile
110
108
  - gemfiles/rails_61.gemfile
111
109
  - gemfiles/rails_70.gemfile
110
+ - gemfiles/rails_71.gemfile
112
111
  - gemfiles/rails_edge.gemfile
113
112
  - lib/shoelace/engine.rb
114
113
  - lib/shoelace/rails.rb
@@ -116,61 +115,11 @@ files:
116
115
  - lib/shoelace/railtie.rb
117
116
  - lib/shoelace/testing.rb
118
117
  - lib/tasks/shoelace.rake
119
- - package.json
120
- - rollup.config.js
121
118
  - shoelace-rails.gemspec
122
- - src/index.ts
123
- - src/turbo/index.ts
124
- - src/turbo/polyfills/formdata-event.js
125
- - src/turbo/sl-turbo-form.ts
126
- - src/turbolinks/features/confirm.ts
127
- - src/turbolinks/features/disable.ts
128
- - src/turbolinks/features/remote.ts
129
- - src/turbolinks/index.ts
130
- - src/turbolinks/selectors.ts
131
- - src/turbolinks/start.ts
132
- - src/turbolinks/turbolinks.ts
133
- - src/turbolinks/utils/ajax.ts
134
- - src/turbolinks/utils/csp.ts
135
- - src/turbolinks/utils/csrf.ts
136
- - src/turbolinks/utils/dom.ts
137
- - src/turbolinks/utils/event.ts
138
- - src/turbolinks/utils/form.ts
139
- - test/dummy_app/Gemfile
140
- - test/dummy_app/Rakefile
141
- - test/dummy_app/app/controllers/hotwire_forms_controller.rb
142
- - test/dummy_app/app/controllers/turbolinks_forms_controller.rb
143
- - test/dummy_app/app/models/user.rb
144
- - test/dummy_app/app/packs/entrypoints/hotwire.js
145
- - test/dummy_app/app/packs/entrypoints/turbolinks.js
146
- - test/dummy_app/app/views/hotwire_forms/form.html.erb
147
- - test/dummy_app/app/views/hotwire_forms/show.html.erb
148
- - test/dummy_app/app/views/layouts/application.html.erb
149
- - test/dummy_app/app/views/turbolinks_forms/form.html.erb
150
- - test/dummy_app/app/views/turbolinks_forms/show.html.erb
151
- - test/dummy_app/bin/rails
152
- - test/dummy_app/bin/webpack
153
- - test/dummy_app/bin/yarn
154
- - test/dummy_app/config.ru
155
- - test/dummy_app/config/application.rb
156
- - test/dummy_app/config/boot.rb
157
- - test/dummy_app/config/environment.rb
158
- - test/dummy_app/config/environments/development.rb
159
- - test/dummy_app/config/environments/test.rb
160
- - test/dummy_app/config/routes.rb
161
- - test/dummy_app/config/webpack/development.js
162
- - test/dummy_app/config/webpack/production.js
163
- - test/dummy_app/config/webpack/test.js
164
- - test/dummy_app/config/webpacker.yml
165
- - test/dummy_app/package.json
166
- - test/dummy_app/test/system/hotwire_form_test.rb
167
- - test/dummy_app/test/system/turbolinks_form_test.rb
168
- - test/dummy_app/test/test_helper.rb
169
119
  - test/helpers/form_helper_test.rb
170
120
  - test/helpers/tag_helper_test.rb
121
+ - test/helpers/translation_test.rb
171
122
  - test/test_helper.rb
172
- - tsconfig.json
173
- - yarn.lock
174
123
  homepage: https://github.com/yuki24/shoelace-rails
175
124
  licenses:
176
125
  - MIT
@@ -193,7 +142,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
193
142
  - !ruby/object:Gem::Version
194
143
  version: '0'
195
144
  requirements: []
196
- rubygems_version: 3.4.6
145
+ rubygems_version: 3.5.3
197
146
  signing_key:
198
147
  specification_version: 4
199
148
  summary: Rails view helpers Shoelace.style, the design system.
data/dist/.keep DELETED
File without changes
data/dist/types/.keep DELETED
File without changes
data/package.json DELETED
@@ -1,50 +0,0 @@
1
- {
2
- "name": "@yuki24/shoelace-rails",
3
- "version": "0.1.0-beta.5",
4
- "author": "Yuki Nishijima <yuki24@hey.com>",
5
- "license": "MIT",
6
- "description": "Unobtrusive Javascript and Turbolinks support for shoelace.style",
7
- "homepage": "https://github.com/yuki24/shoelace-rails",
8
- "module": "dist/shoelace-rails.es2017-esm.js",
9
- "main": "dist/shoelace-rails.es2017-umd.js",
10
- "types": "dist/types/index.d.ts",
11
- "files": [
12
- "dist/*.js",
13
- "dist/*.js.map",
14
- "dist/types/**/*"
15
- ],
16
- "repository": {
17
- "type": "git",
18
- "url": "git+https://github.com/yuki24/shoelace-rails.git"
19
- },
20
- "bugs": {
21
- "url": "https://github.com/yuki24/shoelace-rails"
22
- },
23
- "scripts": {
24
- "build": "yarn types && rollup -c",
25
- "clean": "rm -fr dist",
26
- "prettier-project": "yarn run prettier-write 'src/**/*.{ts,tsx,js,jsx}'",
27
- "prettier-write": "yarn run prettier --write",
28
- "release": "yarn clean && yarn build && npm publish --access public",
29
- "types": "tsc --noEmit false --emitDeclarationOnly true --outDir dist/types"
30
- },
31
- "devDependencies": {
32
- "@hotwired/turbo": "^7.0.1",
33
- "@rollup/plugin-node-resolve": "^13.0.4",
34
- "@rollup/plugin-typescript": "^8.2.5",
35
- "@shoelace-style/shoelace": "^2.0.0-beta.52",
36
- "prettier": "^2.3.2",
37
- "rollup": "^2.56.2",
38
- "tslib": "^2.3.1",
39
- "turbolinks": "5.x",
40
- "typescript": "^4.3.5"
41
- },
42
- "peerDependencies": {
43
- "@hotwired/turbo": "7.x",
44
- "turbolinks": "5.x"
45
- },
46
- "prettier": {
47
- "printWidth": 120,
48
- "semi": false
49
- }
50
- }
data/rollup.config.js DELETED
@@ -1,49 +0,0 @@
1
- import resolve from "@rollup/plugin-node-resolve"
2
- import typescript from "@rollup/plugin-typescript"
3
-
4
- export default [
5
- {
6
- external: ['turbolinks'],
7
- input: "src/index.ts",
8
- output: [
9
- {
10
- name: "Shoelace Rails",
11
- file: "dist/shoelace-rails.es5-umd.js",
12
- format: "umd",
13
- sourcemap: true,
14
- }
15
- ],
16
- plugins: [
17
- resolve(),
18
- typescript({ target: "es5", downlevelIteration: true })
19
- ],
20
- watch: {
21
- include: "src/**"
22
- }
23
- },
24
-
25
- {
26
- external: ['turbolinks'],
27
- input: "src/index.ts",
28
- output: [
29
- {
30
- name: "Shoelace Rails",
31
- file: "dist/shoelace-rails.es2017-umd.js",
32
- format: "umd",
33
- sourcemap: true,
34
- },
35
- {
36
- file: "dist/shoelace-rails.es2017-esm.js",
37
- format: "es",
38
- sourcemap: true,
39
- }
40
- ],
41
- plugins: [
42
- resolve(),
43
- typescript()
44
- ],
45
- watch: {
46
- include: "src/**"
47
- }
48
- }
49
- ]
data/src/index.ts DELETED
@@ -1,2 +0,0 @@
1
- export * from "./turbo"
2
- export * from "./turbolinks"
data/src/turbo/index.ts DELETED
@@ -1,6 +0,0 @@
1
- import "./polyfills/formdata-event"
2
- import { SlTurboFormElement } from "./sl-turbo-form"
3
-
4
- export const startTurbo = () => {
5
- customElements.define("sl-turbo-form", SlTurboFormElement)
6
- }
@@ -1,27 +0,0 @@
1
- (function(){
2
- /*
3
-
4
- Copyright (c) 2020 The Polymer Project Authors. All rights reserved. This
5
- code may only be used under the BSD style license found at
6
- http://polymer.github.io/LICENSE.txt The complete set of authors may be
7
- found at http://polymer.github.io/AUTHORS.txt The complete set of
8
- contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt Code
9
- distributed by Google as part of the polymer project is also subject to an
10
- additional IP rights grant found at http://polymer.github.io/PATENTS.txt
11
- */
12
- 'use strict';function aa(a){var b=0;return function(){return b<a.length?{done:!1,value:a[b++]}:{done:!0}}}function n(a){var b="undefined"!=typeof Symbol&&Symbol.iterator&&a[Symbol.iterator];return b?b.call(a):{next:aa(a)}}function ba(a){for(var b,c=[];!(b=a.next()).done;)c.push(b.value);return c}var ca="function"==typeof Object.create?Object.create:function(a){function b(){}b.prototype=a;return new b};
13
- function da(a){a=["object"==typeof globalThis&&globalThis,a,"object"==typeof window&&window,"object"==typeof self&&self,"object"==typeof global&&global];for(var b=0;b<a.length;++b){var c=a[b];if(c&&c.Math==Math)return c}throw Error("Cannot find global object");}var ea=da(this),q;
14
- if("function"==typeof Object.setPrototypeOf)q=Object.setPrototypeOf;else{var r;a:{var ha={a:!0},ia={};try{ia.__proto__=ha;r=ia.a;break a}catch(a){}r=!1}q=r?function(a,b){a.__proto__=b;if(a.__proto__!==b)throw new TypeError(a+" is not extensible");return a}:null}var ja=q,ka=window.Document.prototype,la=ka.createElement,ma=ka.createEvent;var t=window.Event,u=t.prototype,na=u.initEvent,oa=null===u||void 0===u?void 0:u.stopImmediatePropagation,pa=null===u||void 0===u?void 0:u.stopPropagation,w=Object.getOwnPropertyDescriptor(u,"defaultPrevented"),x=Object.getOwnPropertyDescriptor(u,"target");Object.getOwnPropertyDescriptor(u,"type");var qa=window.document;var ra=null===x||void 0===x?void 0:x.get,y=void 0!==ra?function(a){return ra.call(a)}:function(a){return a.target},sa=null===w||void 0===w?void 0:w.get,ta=void 0!==sa?function(a){return sa.call(a)}:function(a){return a.defaultPrevented};function ua(a,b,c){Object.setPrototypeOf(a,Object.getPrototypeOf(b));for(var d=n(Object.keys(b)),e=d.next();!e.done;e=d.next())e=e.value,"prototype"!==e&&Object.defineProperty(a,e,Object.getOwnPropertyDescriptor(b,e));a.prototype=c;Object.defineProperty(c,"constructor",{writable:!0,configurable:!0,enumerable:!1,value:c.constructor})};var va=new WeakMap,wa=new WeakMap;function z(a,b){b=void 0===b?{}:b;try{var c=new t(a,b)}catch(e){c=ma.call(qa,"Event");var d=b.bubbles;b=b.cancelable;na.call(c,a,void 0===d?!1:d,void 0===b?!1:b)}Object.setPrototypeOf(c,Object.getPrototypeOf(this));return c}ua(z,t,u);
15
- function xa(){z.prototype.constructor=z;Object.setPrototypeOf(z,Function.prototype);z.prototype.stopImmediatePropagation=function(){wa.set(this,!0);return oa.call(this)};z.prototype.stopPropagation=function(){va.set(this,!0);return pa.call(this)};window.Event=z};var A=window.EventTarget,B=null===A||void 0===A?void 0:A.prototype,ya=null===B||void 0===B?void 0:B.addEventListener,za=null===B||void 0===B?void 0:B.removeEventListener,Aa=null===B||void 0===B?void 0:B.dispatchEvent;var C=window.Node.prototype,E=C.addEventListener,Ba=C.appendChild,Ca=C.dispatchEvent,Da=C.getRootNode,Ea=C.insertBefore,Fa=C.removeChild,Ga=C.removeEventListener,F=Object.getOwnPropertyDescriptor(C,"parentNode");var G=window.Window.prototype,H=G.addEventListener,Ha=G.removeEventListener,Ia=G.dispatchEvent;var Ja=A?ya:function(a,b,c){if(this instanceof Node)return E.call(this,a,b,c);if(this instanceof Window)return H.call(this,a,b,c);throw new TypeError("Unsupported.");},Ka=A?za:function(a,b,c){if(this instanceof Node)return Ga.call(this,a,b,c);if(this instanceof Window)return Ha.call(this,a,b,c);throw new TypeError("Unsupported.");},Ma=A?Aa:function(a){if(this instanceof Node)return Ca.call(this,a);if(this instanceof Window)return Ia.call(this,a);throw new TypeError("Unsupported.");};var Na=null===F||void 0===F?void 0:F.get,I=void 0!==Na?function(a){return Na.call(a)}:function(a){return a.parentNode};function Oa(a){if(void 0!==Da)return Da.call(a,void 0);for(var b=I(a);null!==b;)a=b,b=I(b);return a};var J=window.HTMLInputElement.prototype,K=Object.getOwnPropertyDescriptor(J,"name"),L=Object.getOwnPropertyDescriptor(J,"type"),M=Object.getOwnPropertyDescriptor(J,"value");var N,Pa,Qa,Ra=null!==(N=(null!==L&&void 0!==L?L:{}).set)&&void 0!==N?N:function(a){this.type=a},Sa=null!==(Pa=(null!==K&&void 0!==K?K:{}).set)&&void 0!==Pa?Pa:function(a){this.name=a},Ta=null!==(Qa=(null!==M&&void 0!==M?M:{}).set)&&void 0!==Qa?Qa:function(a){this.value=a};var O=window.Element.prototype,P=O.getAttribute,Ua=O.hasAttribute,Va=O.removeAttribute,Wa=O.setAttribute;var Xa=Object.getOwnPropertyDescriptor(window.HTMLCollection.prototype,"length");var Ya,Za=null!==(Ya=(null!==Xa&&void 0!==Xa?Xa:{}).get)&&void 0!==Ya?Ya:function(){return this.length};var Q=window.HTMLFormElement.prototype,$a=Q.submit,ab=Object.getOwnPropertyDescriptor(Q,"elements");var bb=window.FormData,R=bb.prototype,cb=R.append,db=R.delete,eb=R.set;var fb=new WeakMap;function S(a,b){b=void 0===b?{}:b;a=z.call(this,a,b)||this;b=b.formData;if(!(b instanceof FormData))throw new TypeError("Failed to construct 'FormDataEvent': member formData is not of type FormData.");fb.set(a,b);return a}S.prototype=ca(z.prototype);S.prototype.constructor=S;if(ja)ja(S,z);else for(var T in z)if("prototype"!=T)if(Object.defineProperties){var gb=Object.getOwnPropertyDescriptor(z,T);gb&&Object.defineProperty(S,T,gb)}else S[T]=z[T];
16
- ea.Object.defineProperties(S.prototype,{formData:{configurable:!0,enumerable:!0,get:function(){return fb.get(this)}}});var U=new WeakMap;function V(a){var b=new bb(a);Object.setPrototypeOf(b,Object.getPrototypeOf(this));U.set(b,[]);a instanceof HTMLFormElement&&Ma.call(a,new S("formdata",{bubbles:!0,formData:b}));return b}ua(V,bb,R);
17
- function hb(){V.prototype.constructor=V;V.prototype.append=function(a,b){var c=U.get(this);if("string"!==typeof b)throw Error("Unsupported.");c.push({i:"append",name:a,value:b});return cb.call(this,a,b)};void 0!==db&&(V.prototype["delete"]=function(a){U.get(this).push({i:"delete",name:a});return db.call(this,a)});void 0!==eb&&(V.prototype.set=function(a,b){var c=U.get(this);if("string"!==typeof b)throw Error("Unsupported.");c.push({i:"set",name:a,value:b});return eb.call(this,a,b)});window.FormData=
18
- V};function ib(a){function b(p){for(var h=ab.get.call(a),k=Za.call(h),m=0;m<k;m++){var v=h[m],fa;if(fa=P.call(v,"name")===p)fa=!Ua.call(v,"disabled");if(fa)return v}}function c(p){for(var h=ab.get.call(a),k=Za.call(h),m=0;m<k;m++){var v=h[m];P.call(v,"name")===p&&(f.has(v)||f.set(v,P.call(v,"disabled")),Wa.call(v,"disabled",""))}}function d(p,h,k){var m=la.call(qa,"input",void 0);Ra.call(m,"hidden");Sa.call(m,p);Ta.call(m,h);void 0!==k?(p=I(k),Ea.call(p,m,k)):Ba.call(a,m);g.push(m)}var e=new V(a),g=
19
- [],f=new Map;e=n(U.get(e));for(var l=e.next();!l.done;l=e.next())switch(l=l.value,l.i){case "append":d(l.name,l.value);break;case "delete":c(l.name);break;case "set":var D=l;l=D.name;D=D.value;var La=b(l);void 0===La?d(l,D):(c(l),d(l,D,La));break;default:throw Error("UNREACHABLE");}setTimeout(function(){for(var p=n(g),h=p.next();!h.done;h=p.next()){h=h.value;var k=I(h);k&&Fa.call(k,h)}p=n(f);for(h=p.next();!h.done;h=p.next())k=n(h.value),h=k.next().value,k=k.next().value,P.call(h,"disabled")!==k&&
20
- (null===k?Va.call(h,"disabled"):Wa.call(h,"disabled",k))})};function W(){this.h=[]}W.prototype.push=function(a){for(var b=a.g,c=a.capture,d=n(this.h),e=d.next();!e.done;e=d.next())if(e=e.value,b===e.g&&c===e.capture)return;this.h.push(a)};W.prototype.delete=function(a){var b=a.g;a=a.capture;for(var c=0;c<this.h.length;c++){var d=this.h[c];if(b===d.g&&a===d.capture){this.h.splice(c,1);break}}};
21
- ea.Object.defineProperties(W.prototype,{length:{configurable:!0,enumerable:!0,get:function(){return this.h.length}},l:{configurable:!0,enumerable:!0,get:function(){for(var a=this.h,b=a.length-1;0<=b;b--){var c=a[b];if(c.capture)return c.g}}},j:{configurable:!0,enumerable:!0,get:function(){for(var a=this.h,b=a.length-1;0<=b;b--){var c=a[b];if(!c.capture)return c.g}}}});var X=new WeakMap;function jb(a,b,c){var d;b&&(X.has(a)||X.set(a,new W),c="boolean"===typeof c?c:null!==(d=null===c||void 0===c?void 0:c.capture)&&void 0!==d?d:!1,X.get(a).push({g:b,capture:c}))}function kb(a,b,c){var d;b&&(a=X.get(a),void 0!==a&&(c="boolean"===typeof c?c:null!==(d=null===c||void 0===c?void 0:c.capture)&&void 0!==d?d:!1,a.delete({g:b,capture:c})))};var Y=new WeakMap,lb=new WeakMap,Z=new WeakMap;function mb(a){if(!lb.has(a)){lb.set(a,!0);var b=y(a);if(b instanceof HTMLFormElement){b=Oa(b);var c=nb(function(){});Z.set(a,{target:b,g:c});Ja.call(b,"submit",c);jb(b,c)}}}
22
- function nb(a){return function e(c,d){for(var g=[],f=1;f<arguments.length;++f)g[f-1]=arguments[f];g="function"===typeof a?a.call.apply(a,[this,c].concat(g instanceof Array?g:ba(n(g)))):a.handleEvent.apply(a,[c].concat(g instanceof Array?g:ba(n(g))));f=y(c)instanceof HTMLFormElement;if(wa.has(c)&&f)ob(c);else if(va.has(c)&&f){f=X.get(this);var l=f.j;e!==f.l&&e!==l||ob(c)}else Z.has(c)&&(f=Z.get(c),void 0!==f&&this===f.target&&(f=X.get(this).j,e===f&&ob(c)));return g}}
23
- function ob(a){var b=Z.get(a);if(b){var c=b.target;b=b.g;Ka.call(c,"submit",b);kb(c,b);Z.delete(a)}ta(a)||ib(y(a))};var pb=new WeakMap;function qb(a,b){a.addEventListener=function(c,d,e){if("submit"===c&&null!==d){var g=nb(d);pb.set(d,g);d=g}g=b.call(this,c,d,e);if("formdata"===c){c=d;var f;c&&(e="boolean"===typeof e?e:null!==(f=null===e||void 0===e?void 0:e.capture)&&void 0!==f?f:!1,f=Y.get(this),void 0===f?(f=new W,f.push({g:c,capture:e}),Y.set(this,f),Ja.call(this,"submit",mb,!0)):f.push({g:c,capture:e}))}else"submit"===c&&null!==d&&jb(this,d,e);return g}}
24
- function rb(a,b){a.removeEventListener=function(c,d,e){var g;"submit"===c&&null!==d&&(d=null!==(g=pb.get(d))&&void 0!==g?g:d);g=b.call(this,c,d,e);if("formdata"===c){c=d;var f;c&&(d=Y.get(this),void 0!==d&&(e="boolean"===typeof e?e:null!==(f=null===e||void 0===e?void 0:e.capture)&&void 0!==f?f:!1,d.delete({g:c,capture:e}),0===d.length&&(Y.delete(this),Ka.call(this,"submit",mb,!0))))}else"submit"===c&&null!==d&&kb(this,d,e);return g}};function sb(){Q.submit=function(){ib(this);return $a.call(this)}};void 0===window.FormDataEvent&&(xa(),B&&(qb(B,ya),rb(B,za)),E&&(qb(C,E),rb(C,Ga)),H&&(qb(G,H),rb(G,Ha)),hb(),Object.defineProperty(window,"FormDataEvent",{writable:!0,enumerable:!1,configurable:!0,value:S}),Q&&sb());
25
- }).call(self);
26
-
27
- //# sourceMappingURL=formdata-event.min.js.map
@@ -1,110 +0,0 @@
1
- interface SlForm extends HTMLElement {
2
- getFormData: () => FormData
3
- }
4
-
5
- interface SlButton extends HTMLElement {
6
- submit: boolean
7
- }
8
-
9
- interface FormDataEvent extends Event {
10
- formData: FormData
11
- }
12
-
13
- interface SubmitEvent extends CustomEvent {
14
- submitter: Element
15
- }
16
-
17
- const submittersByForm: WeakMap<HTMLFormElement, HTMLElement> = new WeakMap()
18
-
19
- const cloneAttributes = (target, source) =>
20
- [...source.attributes]
21
- .filter(({ nodeName }) => !["id", "class"].includes(nodeName))
22
- .forEach(({ nodeName, nodeValue }) => target.setAttribute(nodeName, nodeValue))
23
-
24
- const findSubmitterFromClickTarget = (target: EventTarget | null): HTMLElement => {
25
- const element = target instanceof Element ? target : target instanceof Node ? target.parentElement : null
26
-
27
- if (element?.tagName === "SL-BUTTON") {
28
- const slButton = element as SlButton
29
- return slButton.submit ? slButton : null
30
- } else {
31
- const candidate = element?.closest("input, button") as HTMLInputElement | HTMLFormElement
32
- return candidate?.type === "submit" ? candidate : null
33
- }
34
- }
35
-
36
- export class SlTurboFormElement extends HTMLElement {
37
- private readonly form: HTMLFormElement
38
- private called: boolean
39
-
40
- static template = `
41
- <sl-form>
42
- <slot></slot>
43
- </sl-form>
44
- `
45
-
46
- static get observedAttributes() {
47
- return ["action", "method", "enctype", "accept-charset", "data"]
48
- }
49
-
50
- constructor() {
51
- super()
52
-
53
- // The <sl-form> component needs to be rendered within the shadow DOM so we can safely use the <slot>, which
54
- // should contain shoelace form controls.
55
- const shadowRoot = this.attachShadow({ mode: "open" })
56
- shadowRoot.innerHTML = SlTurboFormElement.template
57
-
58
- // The normal <form> element needs to be rendered within the light DOM so we can emit a custom 'submit' event
59
- // with appropriate formdata, target, etc.
60
- this.form = document.createElement("form")
61
- this.form.style.display = "none"
62
- cloneAttributes(this.form, this)
63
- this.appendChild(this.form)
64
- }
65
-
66
- connectedCallback() {
67
- this.addEventListener("click", this.clickCaptured, true)
68
- this.addEventListener("sl-submit", this.handleSubmit)
69
- this.addEventListener("formdata", this.handleFormData)
70
- }
71
-
72
- disconnectedCallback() {
73
- this.removeEventListener("click", this.clickCaptured, true)
74
- this.removeEventListener("sl-submit", this.handleSubmit)
75
- this.removeEventListener("formdata", this.handleFormData)
76
- }
77
-
78
- handleFormData = (event: FormDataEvent) => {
79
- const { formData, target } = event
80
-
81
- if (this.form === target && !this.called) {
82
- this.called = true
83
- const slForm = this.shadowRoot.querySelector("sl-form") as SlForm
84
-
85
- for (const [key, value] of slForm.getFormData().entries()) {
86
- formData.append(key, value)
87
- }
88
- }
89
- }
90
-
91
- handleSubmit = (event: CustomEvent) => {
92
- event.stopImmediatePropagation()
93
- const submitter = submittersByForm.get(this.form)
94
- const submitEvent = new CustomEvent("submit", { bubbles: true, cancelable: true }) as SubmitEvent
95
- Object.defineProperty(submitEvent, "submitter", { get: () => submitter })
96
-
97
- const cancelled = this.form.dispatchEvent(submitEvent)
98
- if (cancelled) {
99
- this.form.submit()
100
- }
101
- }
102
-
103
- clickCaptured = (event: Event) => {
104
- const submitter = findSubmitterFromClickTarget(event.target)
105
-
106
- if (submitter) {
107
- submittersByForm.set(this.form, submitter)
108
- }
109
- }
110
- }
@@ -1,42 +0,0 @@
1
- // This code was heavily inspired by the rails-ujs project.
2
- // Copyright (c) 2007-2021 Rails Core team.
3
- import { fire, stopEverything } from "../utils/event"
4
-
5
- export const handleConfirm = (event) => {
6
- const { target } = event
7
-
8
- if (!allowAction(target)) {
9
- return stopEverything(event)
10
- }
11
- }
12
-
13
- // For 'data-confirm' attribute:
14
- // - Fires `confirm` event
15
- // - Shows the confirmation dialog
16
- // - Fires the `confirm:complete` event
17
- //
18
- // Returns `true` if no function stops the chain and user chose yes `false` otherwise.
19
- // Attaching a handler to the element's `confirm` event that returns a `falsy` value cancels the confirmation dialog.
20
- // Attaching a handler to the element's `confirm:complete` event that returns a `falsy` value makes this function
21
- // return false. The `confirm:complete` event is fired whether or not the user answered true or false to the dialog.
22
- const allowAction = (element) => {
23
- const message = element.getAttribute("data-confirm")
24
-
25
- if (!message) {
26
- return true
27
- }
28
-
29
- let callback = null,
30
- answer = false
31
- if (fire(element, "confirm")) {
32
- try {
33
- answer = confirm(message)
34
- } catch (error) {
35
- // no-op...
36
- }
37
-
38
- callback = fire(element, "confirm:complete", [answer])
39
- }
40
-
41
- return answer && callback
42
- }