Skip to content

Commit dc769c9

Browse files
committedMar 23, 2024·
Updating config and move package to organization
1 parent 59f77a9 commit dc769c9

21 files changed

+4468
-3603
lines changed
 

‎.babelrc

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
11
{
2-
"presets": [
3-
"@babel/env",
4-
"@babel/preset-typescript"
5-
],
6-
"plugins": [
7-
"@babel/plugin-transform-typescript",
8-
"@babel/plugin-proposal-class-properties"
9-
]
2+
"presets": ["@babel/env", "@babel/preset-typescript"],
3+
"plugins": ["@babel/plugin-transform-typescript"]
104
}

‎.eslintrc.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
// https://eslint.org/docs/user-guide/configuring
22

33
module.exports = {
4+
root: true,
5+
parser: "@typescript-eslint/parser",
46
env: {
57
browser: true,
68
node: true,
7-
es6: true
9+
es6: true,
10+
jest: true,
811
},
9-
10-
globals: {
11-
page: 'readonly'
12-
}
12+
// https://github.com/standard/standard/blob/master/docs/RULES-en.md
13+
extends: ["standard", "prettier"],
14+
plugins: ["@typescript-eslint"],
1315
}

‎.github/workflows/lint.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ jobs:
99
- uses: actions/checkout@v2
1010
- uses: actions/setup-node@v2
1111
with:
12-
node-version-file: '.node-version'
13-
cache: 'yarn'
12+
node-version-file: ".node-version"
13+
cache: "yarn"
1414
- run: |
1515
yarn install --silent --non-interactive
1616
yarn lint

‎.github/workflows/test.yml

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
name: Test
32

43
on: [push]
@@ -10,8 +9,8 @@ jobs:
109
- uses: actions/checkout@v2
1110
- uses: actions/setup-node@v2
1211
with:
13-
node-version-file: '.node-version'
14-
cache: 'yarn'
12+
node-version-file: ".node-version"
13+
cache: "yarn"
1514
- name: test
1615
run: |
1716
yarn install --silent --non-interactive

‎.node-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
18
1+
20

‎.npmignore

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ index.html
66
netlify.toml
77
.node-version
88
.eslintrc.js
9-
src
109
spec
1110
tsconfig.json
12-
vite.config.js
11+
vite.config.mjs
1312
.prettierignore
1413
postcss.config.js
1514
tailwind.config.js

‎.prettierignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
dist
2+
node_modules

‎.prettierrc

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"printWidth": 120
2+
"printWidth": 120,
3+
"semi": false
34
}

‎CHANGELOG.md

+11
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
11
# Changelog
2+
23
All notable changes to this project will be documented in this file.
34

45
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
56
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
67

78
## [Unreleased]
89

10+
## [5.0.0] - 2024-03-23
11+
912
### Added
1013

1114
- Dispatch `rails-nested-form:add` and `rails-nested-form:remove` events.
1215

16+
### Chore
17+
18+
- Renaming the component from `stimulus-rails-nested-form` to `@stimulus-components/rails-nested-form`
19+
- Upgrading dependencies
20+
- Exporting Typescript Types
21+
- Updating demo UI
22+
- Add [Stimulus LSP](https://github.com/marcoroth/stimulus-lsp) compatibility
23+
1324
## [4.1.0] - 2022-12-23
1425

1526
### Added

‎LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2024 Guillaume Briday
3+
Copyright (c) Guillaume Briday
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

‎index.html

+47-60
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!DOCTYPE html>
1+
<!doctype html>
22
<html lang="en">
33
<head>
44
<meta charset="UTF-8" />
@@ -11,62 +11,45 @@
1111
<title>Stimulus Rails Nested Form</title>
1212

1313
<script type="module" defer>
14-
import './src/app.css'
15-
import { Application } from '@hotwired/stimulus'
16-
import NestedForm from './src/index'
14+
import "./src/app.css"
15+
import { Application } from "@hotwired/stimulus"
16+
import RailsNestedForm from "./src/index"
1717

1818
const application = Application.start()
19-
application.register('nested-form', NestedForm)
19+
application.register("nested-form", RailsNestedForm)
2020
</script>
2121
</head>
2222

2323
<body>
24-
<!-- This example requires Tailwind CSS v2.0+ -->
25-
<div class="relative bg-gray-50 overflow-hidden">
26-
<div class="hidden sm:block sm:absolute sm:inset-y-0 sm:h-full sm:w-full" aria-hidden="true">
27-
<div class="relative h-full max-w-7xl mx-auto">
28-
<svg
29-
class="absolute right-full transform translate-y-1/4 translate-x-1/4 lg:translate-x-1/2"
30-
width="404"
31-
height="784"
32-
fill="none"
33-
viewBox="0 0 404 784"
34-
>
35-
<defs>
36-
<pattern
37-
id="f210dbf6-a58d-4871-961e-36d5016a0f49"
38-
x="0"
39-
y="0"
40-
width="20"
41-
height="20"
42-
patternUnits="userSpaceOnUse"
43-
>
44-
<rect x="0" y="0" width="4" height="4" class="text-gray-200" fill="currentColor" />
45-
</pattern>
46-
</defs>
47-
<rect width="404" height="784" fill="url(#f210dbf6-a58d-4871-961e-36d5016a0f49)" />
48-
</svg>
49-
<svg
50-
class="absolute left-full transform -translate-y-3/4 -translate-x-1/4 md:-translate-y-1/2 lg:-translate-x-1/2"
51-
width="404"
52-
height="784"
53-
fill="none"
54-
viewBox="0 0 404 784"
55-
>
56-
<defs>
57-
<pattern
58-
id="5d0dd344-b041-4d26-bec4-8d33ea57ec9b"
59-
x="0"
60-
y="0"
61-
width="20"
62-
height="20"
63-
patternUnits="userSpaceOnUse"
64-
>
65-
<rect x="0" y="0" width="4" height="4" class="text-gray-200" fill="currentColor" />
66-
</pattern>
67-
</defs>
68-
<rect width="404" height="784" fill="url(#5d0dd344-b041-4d26-bec4-8d33ea57ec9b)" />
69-
</svg>
24+
<div class="relative bg-white overflow-hidden">
25+
<div class="relative isolate pt-14">
26+
<div
27+
class="absolute inset-x-0 top-[calc(100%-13rem)] -z-10 transform-gpu overflow-hidden blur-3xl sm:top-[calc(100%-30rem)]"
28+
aria-hidden="true"
29+
>
30+
<div
31+
class="relative left-[calc(50%+3rem)] aspect-[1155/678] w-[36.125rem] -translate-x-1/2 bg-gradient-to-tr from-yellow-500 to-orange-500 opacity-30 sm:left-[calc(50%+36rem)] sm:w-[72.1875rem]"
32+
style="
33+
clip-path: polygon(
34+
74.1% 44.1%,
35+
100% 61.6%,
36+
97.5% 26.9%,
37+
85.5% 0.1%,
38+
80.7% 2%,
39+
72.5% 32.5%,
40+
60.2% 62.4%,
41+
52.4% 68.1%,
42+
47.5% 58.3%,
43+
45.2% 34.5%,
44+
27.5% 76.7%,
45+
0.1% 64.9%,
46+
17.9% 100%,
47+
27.6% 76.8%,
48+
76.1% 97.7%,
49+
74.1% 44.1%
50+
);
51+
"
52+
></div>
7053
</div>
7154
</div>
7255

@@ -85,8 +68,11 @@ <h1 class="text-4xl tracking-tight font-extrabold text-gray-900 sm:text-5xl md:t
8568
</p>
8669

8770
<p class="text-center mt-3">
88-
<img class="inline-block" src="https://img.shields.io/npm/dt/stimulus-rails-nested-form.svg" />
89-
<img class="inline-block" src="https://img.shields.io/npm/v/stimulus-rails-nested-form.svg" />
71+
<img
72+
class="inline-block"
73+
src="https://img.shields.io/npm/dt/@stimulus-components/rails-nested-form.svg"
74+
/>
75+
<img class="inline-block" src="https://img.shields.io/npm/v/@stimulus-components/rails-nested-form.svg" />
9076

9177
<img
9278
class="inline-block"
@@ -107,7 +93,7 @@ <h1 class="text-4xl tracking-tight font-extrabold text-gray-900 sm:text-5xl md:t
10793
<div class="mt-5 max-w-md mx-auto sm:flex sm:justify-center md:mt-8">
10894
<div class="rounded-md shadow">
10995
<a
110-
href="https://www.stimulus-components.com/docs/stimulus-rails-nested-form"
96+
href="https://www.stimulus-components.com/docs/stimulus-rails-nested-form/"
11197
class="w-full flex items-center justify-center px-8 py-3 border border-transparent text-base font-medium rounded-md text-white bg-gradient-to-r from-yellow-500 to-orange-500 md:py-4 md:text-lg md:px-10"
11298
>
11399
Documentation &rarr;
@@ -118,7 +104,7 @@ <h1 class="text-4xl tracking-tight font-extrabold text-gray-900 sm:text-5xl md:t
118104
href="https://github.com/stimulus-components/stimulus-rails-nested-form"
119105
class="w-full flex items-center justify-center gap-1 px-8 py-3 border border-transparent text-base font-medium rounded-md bg-white hover:bg-gray-50 md:py-4 md:text-lg md:px-10"
120106
>
121-
<svg fill="currentColor" viewBox="0 0 24 24" aria-hidden="true" class="h-6 w-6">
107+
<svg fill="currentColor" viewBox="0 0 24 24" aria-hidden="true" class="size-6">
122108
<path
123109
fill-rule="evenodd"
124110
d="M12 2C6.477 2 2 6.484 2 12.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-1.988 1.029-2.688-.103-.253-.446-1.272.098-2.65 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0112 6.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.379.202 2.398.1 2.651.64.7 1.028 1.595 1.028 2.688 0 3.848-2.339 4.695-4.566 4.943.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0022 12.017C22 6.484 17.522 2 12 2z"
@@ -198,15 +184,14 @@ <h1 class="text-4xl tracking-tight font-extrabold text-gray-900 sm:text-5xl md:t
198184

199185
<button
200186
type="submit"
201-
class="mt-4 bg-indigo-600 hover:bg-indigo-400 text-white font-semibold py-2 px-4 border rounded shadow"
187+
class="mt-4 bg-blue-600 hover:bg-blue-500 text-white font-semibold py-2 px-4 border rounded shadow"
202188
>
203189
Save todos
204190
</button>
205191
</form>
206192
</section>
207193
</div>
208194

209-
<!-- This example requires Tailwind CSS v2.0+ -->
210195
<footer class="bg-white">
211196
<div class="max-w-7xl mx-auto py-12 px-4 overflow-hidden sm:px-6 lg:px-8">
212197
<div class="-mx-5 -my-2 flex flex-wrap justify-center" aria-label="Footer">
@@ -229,9 +214,11 @@ <h1 class="text-4xl tracking-tight font-extrabold text-gray-900 sm:text-5xl md:t
229214
class="text-gray-400 hover:text-gray-500"
230215
>
231216
<span class="sr-only">Twitter</span>
232-
<svg class="h-6 w-6" fill="currentColor" viewBox="0 0 24 24" aria-hidden="true">
217+
<svg class="size-6" fill="currentColor" viewBox="0 0 512 512">
233218
<path
234-
d="M8.29 20.251c7.547 0 11.675-6.253 11.675-11.675 0-.178 0-.355-.012-.53A8.348 8.348 0 0022 5.92a8.19 8.19 0 01-2.357.646 4.118 4.118 0 001.804-2.27 8.224 8.224 0 01-2.605.996 4.107 4.107 0 00-6.993 3.743 11.65 11.65 0 01-8.457-4.287 4.106 4.106 0 001.27 5.477A4.072 4.072 0 012.8 9.713v.052a4.105 4.105 0 003.292 4.022 4.095 4.095 0 01-1.853.07 4.108 4.108 0 003.834 2.85A8.233 8.233 0 012 18.407a11.616 11.616 0 006.29 1.84"
219+
fill-rule="evenodd"
220+
d="M389.2 48h70.6L305.6 224.2 487 464H345L233.7 318.6 106.5 464H35.8L200.7 275.5 26.8 48H172.4L272.9 180.9 389.2 48zM364.4 421.8h39.1L151.1 88h-42L364.4 421.8z"
221+
clip-rule="evenodd"
235222
/>
236223
</svg>
237224
</a>
@@ -243,7 +230,7 @@ <h1 class="text-4xl tracking-tight font-extrabold text-gray-900 sm:text-5xl md:t
243230
class="text-gray-400 hover:text-gray-500"
244231
>
245232
<span class="sr-only">GitHub</span>
246-
<svg class="h-6 w-6" fill="currentColor" viewBox="0 0 24 24" aria-hidden="true">
233+
<svg class="size-6" fill="currentColor" viewBox="0 0 24 24" aria-hidden="true">
247234
<path
248235
fill-rule="evenodd"
249236
d="M12 2C6.477 2 2 6.484 2 12.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-1.988 1.029-2.688-.103-.253-.446-1.272.098-2.65 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0112 6.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.379.202 2.398.1 2.651.64.7 1.028 1.595 1.028 2.688 0 3.848-2.339 4.695-4.566 4.943.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0022 12.017C22 6.484 17.522 2 12 2z"

‎jest/jest-setup.js

-2
This file was deleted.

‎jest/jest-setup.ts

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import "@babel/polyfill"
2+
import "mutationobserver-shim"

‎package.json

+48-26
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,73 @@
11
{
2-
"name": "stimulus-rails-nested-form",
2+
"name": "@stimulus-components/rails-nested-form",
33
"version": "4.1.0",
44
"description": "A Stimulus controller to create new fields on the fly to populate your Rails relationship.",
5+
"keywords": [
6+
"stimulus",
7+
"stimulusjs",
8+
"stimulus controller",
9+
"rails",
10+
"nested form"
11+
],
512
"repository": "git@github.com:stimulus-components/stimulus-rails-nested-form.git",
13+
"bugs": {
14+
"url": "https://github.com/stimulus-components/stimulus-rails-nested-form/issues"
15+
},
616
"author": "Guillaume Briday <guillaumebriday@gmail.com>",
717
"license": "MIT",
818
"homepage": "https://github.com/stimulus-components/stimulus-rails-nested-form",
919
"private": false,
20+
"publishConfig": {
21+
"access": "public"
22+
},
1023
"main": "dist/stimulus-rails-nested-form.umd.js",
1124
"module": "dist/stimulus-rails-nested-form.mjs",
25+
"types": "dist/types/index.d.ts",
1226
"scripts": {
13-
"format": "prettier-standard '**/*.{ts,css,html}' --format",
14-
"lint": "prettier-standard '**/*.{ts,css,html}' --lint",
27+
"lint": "tsc --noEmit && eslint --ext .js,.mjs,.ts . && prettier . --check",
28+
"lintfix": "eslint --ext .js,.mjs,.ts . --fix && prettier . --write",
29+
"types": "tsc --noEmit false --declaration true --emitDeclarationOnly true --outDir dist/types",
1530
"dev": "vite",
1631
"prod": "vite build --mode netlify",
17-
"build": "tsc --noEmit && vite build",
32+
"build": "vite build && yarn types",
1833
"version": "yarn build",
1934
"test": "BABEL_ENV=test jest",
2035
"np": "np --no-2fa"
2136
},
2237
"devDependencies": {
23-
"@babel/core": "7.20.7",
24-
"@babel/plugin-syntax-class-properties": "7.12.13",
25-
"@babel/polyfill": "^7.12.1",
26-
"@babel/preset-env": "^7.20.2",
27-
"@babel/preset-typescript": "^7.18.6",
28-
"@hotwired/stimulus": "^3.2.1",
29-
"@testing-library/dom": "^8.19.1",
30-
"@types/jest": "^29.2.4",
31-
"autoprefixer": "^10.4.13",
32-
"babel-jest": "^29.3.1",
33-
"jest": "^29.3.1",
34-
"jest-environment-jsdom": "^29.3.1",
38+
"@babel/core": "7.24.3",
39+
"@babel/polyfill": "7.12.1",
40+
"@babel/preset-env": "7.24.3",
41+
"@babel/preset-typescript": "7.24.1",
42+
"@hotwired/stimulus": "^3",
43+
"@types/jest": "^29.5.12",
44+
"@typescript-eslint/eslint-plugin": "^7.3.1",
45+
"@typescript-eslint/parser": "^7.3.1",
46+
"autoprefixer": "10.4.19",
47+
"eslint": "^8.57.0",
48+
"eslint-config-prettier": "^9.1.0",
49+
"eslint-config-standard": "17.1.0",
50+
"eslint-plugin-import": "2.29.1",
51+
"eslint-plugin-n": "16.6.2",
52+
"eslint-plugin-node": "11.1.0",
53+
"eslint-plugin-promise": "6.1.1",
54+
"eslint-plugin-standard": "5.0.0",
55+
"jest": "^29.7.0",
56+
"jest-environment-jsdom": "^29.7.0",
3557
"mutationobserver-shim": "^0.3.7",
36-
"np": "^7.6.2",
37-
"postcss": "^8.4.20",
38-
"prettier-standard": "16.4.1",
39-
"tailwindcss": "^3.2.4",
40-
"typescript": "^4.9.4",
41-
"vite": "^4.0.3"
58+
"np": "9.2.0",
59+
"postcss": "8.4.38",
60+
"prettier": "3.2.5",
61+
"tailwindcss": "3.4.1",
62+
"typescript": "^5.4.3",
63+
"vite": "5.2.4"
64+
},
65+
"peerDependencies": {
66+
"@hotwired/stimulus": "^3.0.0"
4267
},
4368
"jest": {
4469
"setupFiles": [
45-
"<rootDir>/jest/jest-setup.js"
70+
"<rootDir>/jest/jest-setup.ts"
4671
]
47-
},
48-
"peerDependencies": {
49-
"@hotwired/stimulus": "^3.2.1"
5072
}
5173
}

‎spec/index.test.ts

+13-13
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
* @jest-environment jsdom
33
*/
44

5-
import { Application } from '@hotwired/stimulus'
6-
import NestedForm from '../src/index'
5+
import { Application } from "@hotwired/stimulus"
6+
import RailsNestedForm from "../src/index"
77

88
const startStimulus = (): void => {
99
const application = Application.start()
10-
application.register('nested-form', NestedForm)
10+
application.register("nested-form", RailsNestedForm)
1111
}
1212

13-
describe('#nestedForm', (): void => {
13+
describe("#nestedForm", (): void => {
1414
beforeEach((): void => {
1515
startStimulus()
1616

@@ -33,32 +33,32 @@ describe('#nestedForm', (): void => {
3333
`
3434
})
3535

36-
it('should create new todo', (): void => {
36+
it("should create new todo", (): void => {
3737
const target: HTMLElement = document.querySelector("[data-nested-form-target='target']")
3838
const addButton: HTMLButtonElement = document.querySelector("[data-action='nested-form#add']")
3939

40-
expect(target.previousElementSibling.innerHTML).toContain('Your todo')
40+
expect(target.previousElementSibling.innerHTML).toContain("Your todo")
4141

4242
addButton.click()
4343

44-
expect(target.previousElementSibling.innerHTML).toContain('New todo')
44+
expect(target.previousElementSibling.innerHTML).toContain("New todo")
4545
})
4646

47-
it('should dispatch events', (): void => {
47+
it("should dispatch events", (): void => {
4848
const controllerElement: HTMLButtonElement = document.querySelector("[data-controller='nested-form']")
4949
const addButton: HTMLButtonElement = document.querySelector("[data-action='nested-form#add']")
5050

5151
// @ts-ignore
52-
jest.spyOn(global, 'CustomEvent').mockImplementation((type: string, eventInit?: any) => ({ type, eventInit }))
53-
const mockDispatchEvent = jest.spyOn(controllerElement, 'dispatchEvent').mockImplementation(() => true)
52+
jest.spyOn(global, "CustomEvent").mockImplementation((type: string, eventInit?: any) => ({ type, eventInit }))
53+
const mockDispatchEvent = jest.spyOn(controllerElement, "dispatchEvent").mockImplementation(() => true)
5454

5555
addButton.click()
5656

5757
expect(mockDispatchEvent).toHaveBeenCalledWith({
58-
type: 'rails-nested-form:add',
58+
type: "rails-nested-form:add",
5959
eventInit: {
60-
bubbles: true
61-
}
60+
bubbles: true,
61+
},
6262
})
6363
})
6464
})

‎src/index.ts

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,44 @@
1-
import { Controller } from '@hotwired/stimulus'
1+
import { Controller } from "@hotwired/stimulus"
22

3-
export default class extends Controller {
3+
export default class RailsNestedForm extends Controller {
44
targetTarget: HTMLElement
55
templateTarget: HTMLElement
66
wrapperSelectorValue: string
77

8-
static targets = ['target', 'template']
8+
static targets = ["target", "template"]
99
static values = {
1010
wrapperSelector: {
1111
type: String,
12-
default: '.nested-form-wrapper'
13-
}
12+
default: ".nested-form-wrapper",
13+
},
1414
}
1515

16-
add (e: Event) {
16+
add(e: Event): void {
1717
e.preventDefault()
1818

1919
const content: string = this.templateTarget.innerHTML.replace(/NEW_RECORD/g, new Date().getTime().toString())
20-
this.targetTarget.insertAdjacentHTML('beforebegin', content)
20+
this.targetTarget.insertAdjacentHTML("beforebegin", content)
2121

22-
const event = new CustomEvent('rails-nested-form:add', { bubbles: true })
22+
const event = new CustomEvent("rails-nested-form:add", { bubbles: true })
2323
this.element.dispatchEvent(event)
2424
}
2525

26-
remove (e: Event): void {
26+
remove(e: Event): void {
2727
e.preventDefault()
2828

2929
// @ts-ignore
3030
const wrapper: HTMLElement = e.target.closest(this.wrapperSelectorValue)
3131

32-
if (wrapper.dataset.newRecord === 'true') {
32+
if (wrapper.dataset.newRecord === "true") {
3333
wrapper.remove()
3434
} else {
35-
wrapper.style.display = 'none'
35+
wrapper.style.display = "none"
3636

3737
const input: HTMLInputElement = wrapper.querySelector("input[name*='_destroy']")
38-
input.value = '1'
38+
input.value = "1"
3939
}
4040

41-
const event = new CustomEvent('rails-nested-form:remove', { bubbles: true })
41+
const event = new CustomEvent("rails-nested-form:remove", { bubbles: true })
4242
this.element.dispatchEvent(event)
4343
}
4444
}

‎tailwind.config.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
module.exports = {
2-
content: [
3-
"./index.html",
4-
"./src/**/*.{js,ts,jsx,tsx}",
5-
]
1+
export default {
2+
content: ["./index.html", "./src/**/*.{js,ts,jsx,tsx}"],
63
}

‎tsconfig.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"compilerOptions": {
33
"lib": ["dom", "es6"],
4-
"types": ["vite/client", "jest"],
4+
"types": ["vite/client"],
55
"skipLibCheck": true
6-
}
6+
},
7+
"exclude": ["node_modules", "spec", "jest"]
78
}

‎vite.config.js

-26
This file was deleted.

‎vite.config.mjs

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { resolve } from "path"
2+
import { defineConfig } from "vite"
3+
4+
export default defineConfig(({ mode }) => {
5+
if (mode === "netlify") {
6+
return {}
7+
}
8+
9+
return {
10+
esbuild: {
11+
minifyIdentifiers: false,
12+
},
13+
build: {
14+
lib: {
15+
entry: resolve(__dirname, "src/index.ts"),
16+
name: "StimulusRailsNestedForm",
17+
fileName: "stimulus-rails-nested-form",
18+
},
19+
rollupOptions: {
20+
external: ["@hotwired/stimulus"],
21+
output: {
22+
globals: {
23+
"@hotwired/stimulus": "Stimulus",
24+
},
25+
},
26+
},
27+
},
28+
}
29+
})

‎yarn.lock

+4,280-3,433
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.