Skip to content

Commit 02f3547

Browse files
committed
compiling and eslint
1 parent 3291055 commit 02f3547

File tree

5 files changed

+44
-60
lines changed

5 files changed

+44
-60
lines changed

src/LiveComponent/CHANGELOG.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,18 @@
2929
>Add Item</button>
3030
```
3131

32-
Additionally, the `prevent` modifier (e.g. `prevent|save`) was removed. Replace
33-
this with the standard Stimulus `:prevent` action option:
34-
35-
```diff
36-
<button
37-
- data-action="live#action
38-
+ data-action="live#action:prevent"
39-
- data-action-name="prevent|save"
40-
+ data-live-action-param="save"
41-
>Save</button>
42-
```
32+
Additionally, the `prevent` modifier (e.g. `prevent|save`) was removed. Replace
33+
this with the standard Stimulus `:prevent` action option:
34+
35+
```diff
36+
<button
37+
- data-action="live#action
38+
+ data-action="live#action:prevent"
39+
- data-action-name="prevent|save"
40+
+ data-live-action-param="save"
41+
>Save</button>
42+
```
43+
4344
- [BC BREAK] The `data-event` attribute was removed in favor of using Stimulus
4445
"action parameters": rename `data-event` to `data-live-event-param`. Additionally,
4546
if you were passing arguments to the event name, use action parameter attributes

src/LiveComponent/assets/dist/Directive/directives_parser.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ export interface DirectiveModifier {
55
export interface Directive {
66
action: string;
77
args: string[];
8-
named: any;
98
modifiers: DirectiveModifier[];
109
getString: {
1110
(): string;

src/LiveComponent/assets/dist/live_controller.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ export default class LiveControllerDefault extends Controller<HTMLElement> imple
7070
update(event: any): void;
7171
action(event: any): void;
7272
$render(): Promise<import("./Backend/BackendResponse").default>;
73-
emit(event: Event): void;
74-
emitUp(event: Event): void;
75-
emitSelf(event: Event): void;
73+
emit(event: any): void;
74+
emitUp(event: any): void;
75+
emitSelf(event: any): void;
7676
private getEmitDirectives;
7777
$updateModel(model: string, value: any, shouldRender?: boolean, debounce?: number | boolean): Promise<import("./Backend/BackendResponse").default>;
7878
private handleInputEvent;

src/LiveComponent/assets/dist/live_controller.js

Lines changed: 18 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@ function parseDirectives(content) {
66
return directives;
77
}
88
let currentActionName = '';
9-
let currentArgumentName = '';
109
let currentArgumentValue = '';
1110
let currentArguments = [];
12-
let currentNamedArguments = {};
1311
let currentModifiers = [];
1412
let state = 'action';
1513
const getLastActionName = function () {
@@ -25,52 +23,30 @@ function parseDirectives(content) {
2523
directives.push({
2624
action: currentActionName,
2725
args: currentArguments,
28-
named: currentNamedArguments,
2926
modifiers: currentModifiers,
3027
getString: () => {
3128
return content;
3229
}
3330
});
3431
currentActionName = '';
35-
currentArgumentName = '';
3632
currentArgumentValue = '';
3733
currentArguments = [];
38-
currentNamedArguments = {};
3934
currentModifiers = [];
4035
state = 'action';
4136
};
4237
const pushArgument = function () {
43-
const mixedArgTypesError = () => {
44-
throw new Error(`Normal and named arguments cannot be mixed inside "${currentActionName}()"`);
45-
};
46-
if (currentArgumentName) {
47-
if (currentArguments.length > 0) {
48-
mixedArgTypesError();
49-
}
50-
currentNamedArguments[currentArgumentName.trim()] = currentArgumentValue;
51-
}
52-
else {
53-
if (Object.keys(currentNamedArguments).length > 0) {
54-
mixedArgTypesError();
55-
}
56-
currentArguments.push(currentArgumentValue.trim());
57-
}
58-
currentArgumentName = '';
38+
currentArguments.push(currentArgumentValue.trim());
5939
currentArgumentValue = '';
6040
};
6141
const pushModifier = function () {
6242
if (currentArguments.length > 1) {
6343
throw new Error(`The modifier "${currentActionName}()" does not support multiple arguments.`);
6444
}
65-
if (Object.keys(currentNamedArguments).length > 0) {
66-
throw new Error(`The modifier "${currentActionName}()" does not support named arguments.`);
67-
}
6845
currentModifiers.push({
6946
name: currentActionName,
7047
value: currentArguments.length > 0 ? currentArguments[0] : null,
7148
});
7249
currentActionName = '';
73-
currentArgumentName = '';
7450
currentArguments = [];
7551
state = 'action';
7652
};
@@ -104,11 +80,6 @@ function parseDirectives(content) {
10480
pushArgument();
10581
break;
10682
}
107-
if (char === '=') {
108-
currentArgumentName = currentArgumentValue;
109-
currentArgumentValue = '';
110-
break;
111-
}
11283
currentArgumentValue += char;
11384
break;
11485
case 'after_arguments':
@@ -241,7 +212,7 @@ function getAllModelDirectiveFromElements(element) {
241212
}
242213
const directives = parseDirectives(element.dataset.model);
243214
directives.forEach((directive) => {
244-
if (directive.args.length > 0 || directive.named.length > 0) {
215+
if (directive.args.length > 0) {
245216
throw new Error(`The data-model="${element.dataset.model}" format is invalid: it does not support passing arguments to the model.`);
246217
}
247218
directive.action = normalizeModelName(directive.action);
@@ -258,7 +229,7 @@ function getModelDirectiveFromElement(element, throwOnMissing = true) {
258229
if (formElement && 'model' in formElement.dataset) {
259230
const directives = parseDirectives(formElement.dataset.model || '*');
260231
const directive = directives[0];
261-
if (directive.args.length > 0 || directive.named.length > 0) {
232+
if (directive.args.length > 0) {
262233
throw new Error(`The data-model="${formElement.dataset.model}" format is invalid: it does not support passing arguments to the model.`);
263234
}
264235
directive.action = normalizeModelName(element.getAttribute('name'));
@@ -2891,15 +2862,18 @@ class LiveControllerDefault extends Controller {
28912862
this.updateModelFromElementEvent(event.currentTarget, null);
28922863
}
28932864
action(event) {
2894-
const rawAction = event.currentTarget.dataset.actionName;
2865+
const params = event.params;
2866+
if (!params.action) {
2867+
throw new Error(`No action name provided on element: ${getElementAsTagText(event.currentTarget)}. Did you forget to add the "data-live-action-param" attribute?`);
2868+
}
2869+
const rawAction = params.action;
2870+
const actionArgs = Object.assign({}, params);
2871+
delete actionArgs.action;
28952872
const directives = parseDirectives(rawAction);
28962873
let debounce = false;
28972874
directives.forEach((directive) => {
28982875
let pendingFiles = {};
28992876
const validModifiers = new Map();
2900-
validModifiers.set('prevent', () => {
2901-
event.preventDefault();
2902-
});
29032877
validModifiers.set('stop', () => {
29042878
event.stopPropagation();
29052879
});
@@ -2934,7 +2908,7 @@ class LiveControllerDefault extends Controller {
29342908
}
29352909
delete this.pendingFiles[key];
29362910
}
2937-
this.component.action(directive.action, directive.named, debounce);
2911+
this.component.action(directive.action, actionArgs, debounce);
29382912
if (getModelDirectiveFromElement(event.currentTarget, false)) {
29392913
this.pendingActionTriggerModelElement = event.currentTarget;
29402914
}
@@ -2959,11 +2933,13 @@ class LiveControllerDefault extends Controller {
29592933
});
29602934
}
29612935
getEmitDirectives(event) {
2962-
const element = event.currentTarget;
2963-
if (!element.dataset.event) {
2964-
throw new Error(`No data-event attribute found on element: ${getElementAsTagText(element)}`);
2936+
const params = event.params;
2937+
if (!params.event) {
2938+
throw new Error(`No event name provided on element: ${getElementAsTagText(event.currentTarget)}. Did you forget to add the "data-live-event-param" attribute?`);
29652939
}
2966-
const eventInfo = element.dataset.event;
2940+
const eventInfo = params.event;
2941+
const eventArgs = Object.assign({}, params);
2942+
delete eventArgs.event;
29672943
const directives = parseDirectives(eventInfo);
29682944
const emits = [];
29692945
directives.forEach((directive) => {
@@ -2979,7 +2955,7 @@ class LiveControllerDefault extends Controller {
29792955
});
29802956
emits.push({
29812957
name: directive.action,
2982-
data: directive.named,
2958+
data: eventArgs,
29832959
nameMatch,
29842960
});
29852961
});

src/LiveComponent/assets/src/live_controller.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,11 @@ export default class LiveControllerDefault extends Controller<HTMLElement> imple
156156
action(event: any) {
157157
const params = event.params;
158158
if (!params.action) {
159-
throw new Error(`No action name provided on element: ${getElementAsTagText(event.currentTarget)}. Did you forget to add the "data-live-action-param" attribute?`);
159+
throw new Error(
160+
`No action name provided on element: ${getElementAsTagText(
161+
event.currentTarget
162+
)}. Did you forget to add the "data-live-action-param" attribute?`
163+
);
160164
}
161165
const rawAction = params.action;
162166
// all other params are considered action arguments
@@ -247,8 +251,12 @@ export default class LiveControllerDefault extends Controller<HTMLElement> imple
247251

248252
private getEmitDirectives(event: any): Array<{ name: string; data: any; nameMatch: string | null }> {
249253
const params = event.params;
250-
if (!params.action) {
251-
throw new Error(`No event name provided on element: ${getElementAsTagText(event.currentTarget)}. Did you forget to add the "data-live-event-param" attribute?`);
254+
if (!params.event) {
255+
throw new Error(
256+
`No event name provided on element: ${getElementAsTagText(
257+
event.currentTarget
258+
)}. Did you forget to add the "data-live-event-param" attribute?`
259+
);
252260
}
253261
const eventInfo = params.event;
254262
// all other params are considered event arguments

0 commit comments

Comments
 (0)