ariadne_view_components 0.0.79.2 → 0.0.79.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +2 -0
- data/app/assets/javascripts/ariadne_view_components.js.gz +0 -0
- data/app/assets/stylesheets/ariadne_view_components.css.gz +0 -0
- data/app/components/ariadne/ariadne-form.js +83 -0
- data/app/components/ariadne/ariadne.js +40 -0
- data/app/components/ariadne/behaviors/captionable.rb +1 -1
- data/app/components/ariadne/behaviors/tooltipable.rb +1 -1
- data/app/components/ariadne/tmp/components/ariadne/ariadne-form.d.ts +22 -0
- data/lib/ariadne/view_components/version.rb +1 -1
- metadata +10 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 191ebf85e699edb8806ba64a8979be20bfc962db6b2f36fcf37fb244ae7bd753
|
4
|
+
data.tar.gz: 802332bdae038a697836a0f09b8c06cdee7b98fc6bc1947ab35f8918aa3249ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7bd1b82ed39aef69f710450c25f0c7bc4e96ba9629100f7cbd980d8877ec8e158a87fa9058819efb83c07de57cd89760aa34fefe9c10c02bfb9c53cee453cd51
|
7
|
+
data.tar.gz: 2b6a746a0c4f6711d00fd5209b941eba4a4a002f3cd16ee443d1c699fb257d03995552d6408d5279f5d0979318eb5d230ea2498ef5ef6b42db57efdb4dfed7d6
|
data/CHANGELOG.md
CHANGED
Binary file
|
Binary file
|
@@ -0,0 +1,83 @@
|
|
1
|
+
import { Controller } from '@hotwired/stimulus';
|
2
|
+
import { html } from 'lit-html';
|
3
|
+
class AriadneFormWith extends Controller {
|
4
|
+
constructor() {
|
5
|
+
super(...arguments);
|
6
|
+
this.onBlur = (event) => {
|
7
|
+
this.validateField(event.target);
|
8
|
+
};
|
9
|
+
this.onSubmit = (event) => {
|
10
|
+
if (!this.validateForm()) {
|
11
|
+
event.preventDefault();
|
12
|
+
this.firstInvalidField?.focus();
|
13
|
+
}
|
14
|
+
};
|
15
|
+
this.getRenderString = (data) => {
|
16
|
+
const { strings, values } = data;
|
17
|
+
const v = [...values, ''].map(e => (typeof e === 'object' ? this.getRenderString(e) : e));
|
18
|
+
return strings.reduce((acc, s, i) => acc + s + v[i], '');
|
19
|
+
};
|
20
|
+
}
|
21
|
+
connect() {
|
22
|
+
this.element.setAttribute('novalidate', 'true');
|
23
|
+
this.element.addEventListener('blur', this.onBlur, true);
|
24
|
+
this.element.addEventListener('submit', this.onSubmit);
|
25
|
+
this.element.addEventListener('ajax:beforeSend', this.onSubmit);
|
26
|
+
}
|
27
|
+
disconnect() {
|
28
|
+
this.element.removeEventListener('blur', this.onBlur);
|
29
|
+
this.element.removeEventListener('submit', this.onSubmit);
|
30
|
+
this.element.removeEventListener('ajax:beforeSend', this.onSubmit);
|
31
|
+
}
|
32
|
+
validateForm() {
|
33
|
+
let isValid = true;
|
34
|
+
// Not using `find` because we want to validate all the fields
|
35
|
+
for (const field of this.formFields) {
|
36
|
+
if (this.shouldValidateField(field) && !this.validateField(field))
|
37
|
+
isValid = false;
|
38
|
+
}
|
39
|
+
return isValid;
|
40
|
+
}
|
41
|
+
validateField(field) {
|
42
|
+
if (!this.shouldValidateField(field))
|
43
|
+
return true;
|
44
|
+
const isValid = field.checkValidity();
|
45
|
+
field.classList.toggle('invalid', !isValid);
|
46
|
+
this.refreshErrorForInvalidField(field, isValid);
|
47
|
+
return isValid;
|
48
|
+
}
|
49
|
+
shouldValidateField(field) {
|
50
|
+
return (!field.disabled &&
|
51
|
+
!field.classList.contains('ProseMirror') &&
|
52
|
+
!['file', 'reset', 'submit', 'button'].includes(field.type));
|
53
|
+
}
|
54
|
+
refreshErrorForInvalidField(field, isValid) {
|
55
|
+
this.removeExistingErrorMessage(field);
|
56
|
+
if (!isValid)
|
57
|
+
this.showErrorForInvalidField(field);
|
58
|
+
}
|
59
|
+
removeExistingErrorMessage(field) {
|
60
|
+
const fieldContainer = field.closest('.field');
|
61
|
+
if (!fieldContainer)
|
62
|
+
return;
|
63
|
+
const existingErrorMessageElement = fieldContainer.querySelector('.error');
|
64
|
+
if (existingErrorMessageElement) {
|
65
|
+
existingErrorMessageElement?.parentNode?.removeChild(existingErrorMessageElement);
|
66
|
+
}
|
67
|
+
}
|
68
|
+
showErrorForInvalidField(field) {
|
69
|
+
field.insertAdjacentHTML('afterend', this.buildFieldErrorHtml(field));
|
70
|
+
}
|
71
|
+
buildFieldErrorHtml(field) {
|
72
|
+
const data = html `<p class="error">${field.validationMessage}</p>`;
|
73
|
+
return this.getRenderString(data);
|
74
|
+
}
|
75
|
+
get formFields() {
|
76
|
+
return Array.from(this.formFieldTargets);
|
77
|
+
}
|
78
|
+
get firstInvalidField() {
|
79
|
+
return this.formFields.find(field => !field.checkValidity());
|
80
|
+
}
|
81
|
+
}
|
82
|
+
AriadneFormWith.targets = ['formField'];
|
83
|
+
export default AriadneFormWith;
|
@@ -0,0 +1,40 @@
|
|
1
|
+
import { Application } from '@hotwired/stimulus';
|
2
|
+
const application = Application.start();
|
3
|
+
application.debug = import.meta.env.DEV;
|
4
|
+
window.Stimulus = application;
|
5
|
+
const componentModules = import.meta.glob(['../../components/**/component.ts'], { eager: true });
|
6
|
+
for (const [path, module] of Object.entries(componentModules)) {
|
7
|
+
const dirs = path.split('/');
|
8
|
+
// Dropping ../../components and component.ts parts
|
9
|
+
const name = dirs
|
10
|
+
.slice(3, dirs.length - 1)
|
11
|
+
.join('-')
|
12
|
+
.replaceAll('_', '-')
|
13
|
+
.toLocaleLowerCase();
|
14
|
+
application.register(
|
15
|
+
// @tag stimulus-id
|
16
|
+
`ui-cmp-${name}`, module.default);
|
17
|
+
}
|
18
|
+
// import AriadneForm from './ariadne-form'
|
19
|
+
// import StringMatchController from './string_match_controller/string_match_controller'
|
20
|
+
// import EventsController from './events_controller/events_controller'
|
21
|
+
// import OptionsController from './options_controller/options_controller'
|
22
|
+
// import AccumulatorController from './accumulator_controller/accumulator_controller'
|
23
|
+
// import ToggleableController from './toggleable_controller/toggleable_controller'
|
24
|
+
// import ClipboardCopyComponent from './clipboard_copy_component/clipboard-copy-component'
|
25
|
+
// import SlideoverComponent from './slideover_component/slideover-component'
|
26
|
+
// import TabNavComponent from './tab_nav_component/tab-nav-component'
|
27
|
+
// import TooltipComponent from './tooltip_component/tooltip-component'
|
28
|
+
// import './tab_container_component/tab-container-component'
|
29
|
+
// import './time_ago_component/time-ago-component'
|
30
|
+
// const application = Application.start()
|
31
|
+
// application.register('clipboard-copy-component', ClipboardCopyComponent)
|
32
|
+
// application.register('ariadne-form', AriadneForm)
|
33
|
+
// application.register('slideover-component', SlideoverComponent)
|
34
|
+
// application.register('tab-nav-component', TabNavComponent)
|
35
|
+
// application.register('tooltip-component', TooltipComponent)
|
36
|
+
// application.register('toggleable', ToggleableController)
|
37
|
+
// application.register('accumulator', AccumulatorController)
|
38
|
+
// application.register('options', OptionsController)
|
39
|
+
// application.register('string-match', StringMatchController)
|
40
|
+
// application.register('events', EventsController)
|
@@ -0,0 +1,22 @@
|
|
1
|
+
import { Controller } from '@hotwired/stimulus';
|
2
|
+
import type { TemplateResult } from 'lit-html';
|
3
|
+
type HTMLFormField = HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement;
|
4
|
+
export default class AriadneFormWith extends Controller {
|
5
|
+
static targets: string[];
|
6
|
+
readonly formFieldTargets: [HTMLFormField];
|
7
|
+
connect(): void;
|
8
|
+
disconnect(): void;
|
9
|
+
onBlur: (event: Event) => void;
|
10
|
+
onSubmit: (event: Event) => void;
|
11
|
+
validateForm(): boolean;
|
12
|
+
validateField(field: HTMLFormField): boolean;
|
13
|
+
shouldValidateField(field: HTMLFormField): boolean;
|
14
|
+
refreshErrorForInvalidField(field: HTMLFormField, isValid: boolean): void;
|
15
|
+
removeExistingErrorMessage(field: HTMLFormField): void;
|
16
|
+
showErrorForInvalidField(field: HTMLFormField): void;
|
17
|
+
buildFieldErrorHtml(field: HTMLFormField): string;
|
18
|
+
get formFields(): HTMLFormField[];
|
19
|
+
get firstInvalidField(): HTMLFormField | undefined;
|
20
|
+
getRenderString: (data: TemplateResult) => string;
|
21
|
+
}
|
22
|
+
export {};
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ariadne_view_components
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.79.
|
4
|
+
version: 0.0.79.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Garen J. Torikian
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-05-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tailwind_merge
|
@@ -111,7 +111,7 @@ dependencies:
|
|
111
111
|
- - "~>"
|
112
112
|
- !ruby/object:Gem::Version
|
113
113
|
version: '0.2'
|
114
|
-
description:
|
114
|
+
description:
|
115
115
|
email:
|
116
116
|
- gjtorikian@yetto.app
|
117
117
|
executables: []
|
@@ -128,7 +128,9 @@ files:
|
|
128
128
|
- app/assets/stylesheets/ariadne_view_components.css
|
129
129
|
- app/assets/stylesheets/ariadne_view_components.css.br
|
130
130
|
- app/assets/stylesheets/ariadne_view_components.css.gz
|
131
|
+
- app/components/ariadne/ariadne-form.js
|
131
132
|
- app/components/ariadne/ariadne-form.ts
|
133
|
+
- app/components/ariadne/ariadne.js
|
132
134
|
- app/components/ariadne/base_component.rb
|
133
135
|
- app/components/ariadne/behaviors/captionable.rb
|
134
136
|
- app/components/ariadne/behaviors/tooltipable.rb
|
@@ -170,6 +172,7 @@ files:
|
|
170
172
|
- app/components/ariadne/layout/two_panel/component.rb
|
171
173
|
- app/components/ariadne/layout/wide/component.html.erb
|
172
174
|
- app/components/ariadne/layout/wide/component.rb
|
175
|
+
- app/components/ariadne/tmp/components/ariadne/ariadne-form.d.ts
|
173
176
|
- app/components/ariadne/turbo/frame/component.html.erb
|
174
177
|
- app/components/ariadne/turbo/frame/component.rb
|
175
178
|
- app/components/ariadne/turbo/stream_action/component.html.erb
|
@@ -309,7 +312,7 @@ licenses:
|
|
309
312
|
- AGPL-3.0-or-later
|
310
313
|
metadata:
|
311
314
|
allowed_push_host: https://rubygems.org
|
312
|
-
post_install_message:
|
315
|
+
post_install_message:
|
313
316
|
rdoc_options: []
|
314
317
|
require_paths:
|
315
318
|
- lib
|
@@ -324,8 +327,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
324
327
|
- !ruby/object:Gem::Version
|
325
328
|
version: '0'
|
326
329
|
requirements: []
|
327
|
-
rubygems_version: 3.4.
|
328
|
-
signing_key:
|
330
|
+
rubygems_version: 3.4.21
|
331
|
+
signing_key:
|
329
332
|
specification_version: 4
|
330
333
|
summary: ViewComponents + TailwindCSS + Stimulus
|
331
334
|
test_files: []
|