Skip to content

Commit d31f7af

Browse files
committed
dist
1 parent 788c7d0 commit d31f7af

File tree

2 files changed

+24
-18
lines changed

2 files changed

+24
-18
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export interface DirectiveModifier {
55
export interface Directive {
66
action: string;
77
args: string[];
8+
named: any;
89
modifiers: DirectiveModifier[];
910
getString: {
1011
(): string;

src/LiveComponent/assets/dist/live_controller.js

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ function parseDirectives(content) {
66
return directives;
77
}
88
let currentActionName = '';
9-
let currentArgumentValue = '';
9+
let currentArgumentsString = '';
1010
let currentArguments = [];
11+
let currentNamedArguments = {};
1112
let currentModifiers = [];
1213
let state = 'action';
1314
const getLastActionName = function () {
@@ -19,29 +20,39 @@ function parseDirectives(content) {
1920
}
2021
return directives[directives.length - 1].action;
2122
};
22-
const pushInstruction = function () {
23+
const pushDirective = function () {
2324
directives.push({
2425
action: currentActionName,
2526
args: currentArguments,
27+
named: currentNamedArguments,
2628
modifiers: currentModifiers,
2729
getString: () => {
2830
return content;
2931
}
3032
});
3133
currentActionName = '';
32-
currentArgumentValue = '';
3334
currentArguments = [];
35+
currentNamedArguments = {};
3436
currentModifiers = [];
3537
state = 'action';
3638
};
3739
const pushArgument = function () {
38-
currentArguments.push(currentArgumentValue.trim());
39-
currentArgumentValue = '';
40+
const urlParams = new URLSearchParams('?' + currentArgumentsString);
41+
if (currentArgumentsString.indexOf('=') === -1) {
42+
currentArguments = currentArgumentsString.split(',').map((arg) => arg.trim());
43+
}
44+
else {
45+
currentNamedArguments = Object.fromEntries(urlParams);
46+
}
47+
currentArgumentsString = '';
4048
};
4149
const pushModifier = function () {
4250
if (currentArguments.length > 1) {
4351
throw new Error(`The modifier "${currentActionName}()" does not support multiple arguments.`);
4452
}
53+
if (Object.keys(currentNamedArguments).length > 0) {
54+
throw new Error(`The modifier "${currentActionName}()" does not support named arguments.`);
55+
}
4556
currentModifiers.push({
4657
name: currentActionName,
4758
value: currentArguments.length > 0 ? currentArguments[0] : null,
@@ -60,7 +71,7 @@ function parseDirectives(content) {
6071
}
6172
if (char === ' ') {
6273
if (currentActionName) {
63-
pushInstruction();
74+
pushDirective();
6475
}
6576
break;
6677
}
@@ -76,11 +87,7 @@ function parseDirectives(content) {
7687
state = 'after_arguments';
7788
break;
7889
}
79-
if (char === ',') {
80-
pushArgument();
81-
break;
82-
}
83-
currentArgumentValue += char;
90+
currentArgumentsString += char;
8491
break;
8592
case 'after_arguments':
8693
if (char === '|') {
@@ -90,15 +97,15 @@ function parseDirectives(content) {
9097
if (char !== ' ') {
9198
throw new Error(`Missing space after ${getLastActionName()}()`);
9299
}
93-
pushInstruction();
100+
pushDirective();
94101
break;
95102
}
96103
}
97104
switch (state) {
98105
case 'action':
99106
case 'after_arguments':
100107
if (currentActionName) {
101-
pushInstruction();
108+
pushDirective();
102109
}
103110
break;
104111
default:
@@ -212,7 +219,7 @@ function getAllModelDirectiveFromElements(element) {
212219
}
213220
const directives = parseDirectives(element.dataset.model);
214221
directives.forEach((directive) => {
215-
if (directive.args.length > 0) {
222+
if (directive.args.length > 0 || directive.named.length > 0) {
216223
throw new Error(`The data-model="${element.dataset.model}" format is invalid: it does not support passing arguments to the model.`);
217224
}
218225
directive.action = normalizeModelName(directive.action);
@@ -229,7 +236,7 @@ function getModelDirectiveFromElement(element, throwOnMissing = true) {
229236
if (formElement && 'model' in formElement.dataset) {
230237
const directives = parseDirectives(formElement.dataset.model || '*');
231238
const directive = directives[0];
232-
if (directive.args.length > 0) {
239+
if (directive.args.length > 0 || directive.named.length > 0) {
233240
throw new Error(`The data-model="${formElement.dataset.model}" format is invalid: it does not support passing arguments to the model.`);
234241
}
235242
directive.action = normalizeModelName(element.getAttribute('name'));
@@ -2867,8 +2874,6 @@ class LiveControllerDefault extends Controller {
28672874
throw new Error(`No action name provided on element: ${getElementAsTagText(event.currentTarget)}. Did you forget to add the "data-live-action-param" attribute?`);
28682875
}
28692876
const rawAction = params.action;
2870-
const actionArgs = Object.assign({}, params);
2871-
delete actionArgs.action;
28722877
const directives = parseDirectives(rawAction);
28732878
let debounce = false;
28742879
directives.forEach((directive) => {
@@ -2908,7 +2913,7 @@ class LiveControllerDefault extends Controller {
29082913
}
29092914
delete this.pendingFiles[key];
29102915
}
2911-
this.component.action(directive.action, actionArgs, debounce);
2916+
this.component.action(directive.action, directive.named, debounce);
29122917
if (getModelDirectiveFromElement(event.currentTarget, false)) {
29132918
this.pendingActionTriggerModelElement = event.currentTarget;
29142919
}

0 commit comments

Comments
 (0)