Skip to content

Commit c2221d2

Browse files
committed
compiling and eslint
1 parent a29beee commit c2221d2

File tree

5 files changed

+37
-54
lines changed

5 files changed

+37
-54
lines changed

src/LiveComponent/CHANGELOG.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
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:
32+
Additionally, the `prevent` modifier (e.g. `prevent|save`) was removed. Replace
33+
this with the standard Stimulus `:prevent` action option:
3434

3535
```diff
3636
<button

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

-1
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

+3-3
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,10 @@ export default class LiveControllerDefault extends Controller<HTMLElement> imple
9595
disconnect(): void;
9696
update(event: any): void;
9797
action(event: any): void;
98-
emit(event: Event): void;
99-
emitUp(event: Event): void;
100-
emitSelf(event: Event): void;
10198
$render(): Promise<import("./Backend/BackendResponse").default>;
99+
emit(event: any): void;
100+
emitUp(event: any): void;
101+
emitSelf(event: any): void;
102102
$updateModel(model: string, value: any, shouldRender?: boolean, debounce?: number | boolean): Promise<import("./Backend/BackendResponse").default>;
103103
propsUpdatedFromParentValueChanged(): void;
104104
fingerprintValueChanged(): void;

src/LiveComponent/assets/dist/live_controller.js

+21-45
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':
@@ -325,7 +296,7 @@ function getAllModelDirectiveFromElements(element) {
325296
}
326297
const directives = parseDirectives(element.dataset.model);
327298
directives.forEach((directive) => {
328-
if (directive.args.length > 0 || directive.named.length > 0) {
299+
if (directive.args.length > 0) {
329300
throw new Error(`The data-model="${element.dataset.model}" format is invalid: it does not support passing arguments to the model.`);
330301
}
331302
directive.action = normalizeModelName(directive.action);
@@ -342,7 +313,7 @@ function getModelDirectiveFromElement(element, throwOnMissing = true) {
342313
if (formElement && 'model' in formElement.dataset) {
343314
const directives = parseDirectives(formElement.dataset.model || '*');
344315
const directive = directives[0];
345-
if (directive.args.length > 0 || directive.named.length > 0) {
316+
if (directive.args.length > 0) {
346317
throw new Error(`The data-model="${formElement.dataset.model}" format is invalid: it does not support passing arguments to the model.`);
347318
}
348319
directive.action = normalizeModelName(element.getAttribute('name'));
@@ -2942,15 +2913,18 @@ class LiveControllerDefault extends Controller {
29422913
this.updateModelFromElementEvent(event.currentTarget, null);
29432914
}
29442915
action(event) {
2945-
const rawAction = event.currentTarget.dataset.actionName;
2916+
const params = event.params;
2917+
if (!params.action) {
2918+
throw new Error(`No action name provided on element: ${getElementAsTagText(event.currentTarget)}. Did you forget to add the "data-live-action-param" attribute?`);
2919+
}
2920+
const rawAction = params.action;
2921+
const actionArgs = Object.assign({}, params);
2922+
delete actionArgs.action;
29462923
const directives = parseDirectives(rawAction);
29472924
let debounce = false;
29482925
directives.forEach((directive) => {
29492926
let pendingFiles = {};
29502927
const validModifiers = new Map();
2951-
validModifiers.set('prevent', () => {
2952-
event.preventDefault();
2953-
});
29542928
validModifiers.set('stop', () => {
29552929
event.stopPropagation();
29562930
});
@@ -2985,12 +2959,15 @@ class LiveControllerDefault extends Controller {
29852959
}
29862960
delete this.pendingFiles[key];
29872961
}
2988-
this.component.action(directive.action, directive.named, debounce);
2962+
this.component.action(directive.action, actionArgs, debounce);
29892963
if (getModelDirectiveFromElement(event.currentTarget, false)) {
29902964
this.pendingActionTriggerModelElement = event.currentTarget;
29912965
}
29922966
});
29932967
}
2968+
$render() {
2969+
return this.component.render();
2970+
}
29942971
emit(event) {
29952972
this.getEmitDirectives(event).forEach(({ name, data, nameMatch }) => {
29962973
this.component.emit(name, data, nameMatch);
@@ -3006,9 +2983,6 @@ class LiveControllerDefault extends Controller {
30062983
this.component.emitSelf(name, data);
30072984
});
30082985
}
3009-
$render() {
3010-
return this.component.render();
3011-
}
30122986
$updateModel(model, value, shouldRender = true, debounce = true) {
30132987
return this.component.set(model, value, shouldRender, debounce);
30142988
}
@@ -3019,11 +2993,13 @@ class LiveControllerDefault extends Controller {
30192993
this.component.fingerprint = this.fingerprintValue;
30202994
}
30212995
getEmitDirectives(event) {
3022-
const element = event.currentTarget;
3023-
if (!element.dataset.event) {
3024-
throw new Error(`No data-event attribute found on element: ${getElementAsTagText(element)}`);
2996+
const params = event.params;
2997+
if (!params.event) {
2998+
throw new Error(`No event name provided on element: ${getElementAsTagText(event.currentTarget)}. Did you forget to add the "data-live-event-param" attribute?`);
30252999
}
3026-
const eventInfo = element.dataset.event;
3000+
const eventInfo = params.event;
3001+
const eventArgs = Object.assign({}, params);
3002+
delete eventArgs.event;
30273003
const directives = parseDirectives(eventInfo);
30283004
const emits = [];
30293005
directives.forEach((directive) => {
@@ -3039,7 +3015,7 @@ class LiveControllerDefault extends Controller {
30393015
});
30403016
emits.push({
30413017
name: directive.action,
3042-
data: directive.named,
3018+
data: eventArgs,
30433019
nameMatch,
30443020
});
30453021
});

src/LiveComponent/assets/src/live_controller.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,11 @@ export default class LiveControllerDefault extends Controller<HTMLElement> imple
120120
action(event: any) {
121121
const params = event.params;
122122
if (!params.action) {
123-
throw new Error(`No action name provided on element: ${getElementAsTagText(event.currentTarget)}. Did you forget to add the "data-live-action-param" attribute?`);
123+
throw new Error(
124+
`No action name provided on element: ${getElementAsTagText(
125+
event.currentTarget
126+
)}. Did you forget to add the "data-live-action-param" attribute?`
127+
);
124128
}
125129
const rawAction = params.action;
126130
// all other params are considered action arguments
@@ -231,8 +235,12 @@ export default class LiveControllerDefault extends Controller<HTMLElement> imple
231235

232236
private getEmitDirectives(event: any): Array<{ name: string; data: any; nameMatch: string | null }> {
233237
const params = event.params;
234-
if (!params.action) {
235-
throw new Error(`No event name provided on element: ${getElementAsTagText(event.currentTarget)}. Did you forget to add the "data-live-event-param" attribute?`);
238+
if (!params.event) {
239+
throw new Error(
240+
`No event name provided on element: ${getElementAsTagText(
241+
event.currentTarget
242+
)}. Did you forget to add the "data-live-event-param" attribute?`
243+
);
236244
}
237245
const eventInfo = params.event;
238246
// all other params are considered event arguments

0 commit comments

Comments
 (0)