-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moving from ES6 to TypeScript and Snowpack to Vite
- Loading branch information
1 parent
292d240
commit 663bd95
Showing
16 changed files
with
1,729 additions
and
2,321 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
{ | ||
"presets": [ | ||
"@babel/env", | ||
"@babel/preset-typescript" | ||
], | ||
"plugins": [ | ||
"@babel/plugin-transform-typescript", | ||
"@babel/plugin-proposal-class-properties" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
pkg | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
node_modules | ||
pkg | ||
dist | ||
build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,2 @@ | ||
const { setup: setupDevServer } = require('jest-dev-server') | ||
const { setup: setupPuppeteer } = require('jest-environment-puppeteer') | ||
|
||
module.exports = async function globalSetup (globalConfig) { | ||
await setupPuppeteer(globalConfig) | ||
await setupDevServer({ | ||
command: `yarn dev --open none --port 3000`, | ||
launchTimeout: 50000, | ||
port: 3000 | ||
}) | ||
} | ||
import '@babel/polyfill' | ||
import 'mutationobserver-shim' |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { Application } from 'stimulus' | ||
import NestedForm from '../src/index' | ||
|
||
const startStimulus = (): void => { | ||
const application = Application.start() | ||
application.register('nested-form', NestedForm) | ||
} | ||
|
||
describe('#nestedForm', (): void => { | ||
beforeEach((): void => { | ||
startStimulus() | ||
|
||
document.body.innerHTML = ` | ||
<form data-controller="nested-form"> | ||
<template data-nested-form-target="template"> | ||
<div class="nested-form-wrapper" data-new-record="true"> | ||
<label for="NEW_RECORD">New todo</label> | ||
</div> | ||
</template> | ||
<div> | ||
<label>Your todo</label> | ||
</div> | ||
<div data-nested-form-target="target"></div> | ||
<button type="button" data-action="nested-form#add">Add todo</button> | ||
</form> | ||
` | ||
}) | ||
|
||
it('should create new todo', (): void => { | ||
const target: HTMLElement = document.querySelector("[data-nested-form-target='target']") | ||
const addButton: HTMLButtonElement = document.querySelector("[data-action='nested-form#add']") | ||
|
||
expect(target.previousElementSibling.innerHTML).toContain('Your todo') | ||
|
||
addButton.click() | ||
|
||
expect(target.previousElementSibling.innerHTML).toContain('New todo') | ||
}) | ||
}) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,40 @@ | ||
import { Controller } from 'stimulus' | ||
|
||
export default class extends Controller { | ||
targetTarget: HTMLElement | ||
templateTarget: HTMLElement | ||
wrapperSelectorValue: string | ||
wrapperSelector: string | ||
|
||
static targets = ['target', 'template'] | ||
static values = { | ||
wrapperSelector: String | ||
} | ||
|
||
initialize () { | ||
initialize (): void { | ||
this.wrapperSelector = this.wrapperSelectorValue || '.nested-form-wrapper' | ||
} | ||
|
||
add (e) { | ||
add (e: Event) { | ||
e.preventDefault() | ||
|
||
const content = this.templateTarget.innerHTML.replace(/NEW_RECORD/g, new Date().getTime()) | ||
const content: string = this.templateTarget.innerHTML.replace(/NEW_RECORD/g, new Date().getTime().toString()) | ||
this.targetTarget.insertAdjacentHTML('beforebegin', content) | ||
} | ||
|
||
remove (e) { | ||
remove (e: Event): void { | ||
e.preventDefault() | ||
|
||
const wrapper = e.target.closest(this.wrapperSelector) | ||
// @ts-ignore | ||
const wrapper: HTMLElement = e.target.closest(this.wrapperSelector) | ||
|
||
if (wrapper.dataset.newRecord === 'true') { | ||
wrapper.remove() | ||
} else { | ||
wrapper.style.display = 'none' | ||
wrapper.querySelector("input[name*='_destroy']").value = 1 | ||
|
||
const input: HTMLInputElement = wrapper.querySelector("input[name*='_destroy']") | ||
input.value = '1' | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"compilerOptions": { | ||
"lib": ["dom", "es6"], | ||
"types": ["vite/client", "jest"], | ||
"skipLibCheck": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const path = require('path') | ||
|
||
module.exports = { | ||
build: { | ||
lib: { | ||
entry: path.resolve(__dirname, 'src/index.ts'), | ||
name: 'stimulus-rails-nested-form' | ||
}, | ||
rollupOptions: { | ||
external: ['stimulus'], | ||
output: { | ||
globals: { | ||
stimulus: 'Stimulus' | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.