mirror of
https://github.com/symfony/stimulus-bundle.git
synced 2026-03-24 01:12:07 +01:00
Compare commits
50 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
05af0259f2 | ||
|
|
d610a2e021 | ||
|
|
66b32eaad0 | ||
|
|
581fe67a2a | ||
|
|
90640ce587 | ||
|
|
0401477482 | ||
|
|
7eca9dbf13 | ||
|
|
0c630746cd | ||
|
|
75f6193026 | ||
|
|
7d017977d5 | ||
|
|
f380e2a352 | ||
|
|
40e5dee2da | ||
|
|
591df71416 | ||
|
|
e1d125ac83 | ||
|
|
dfbf6b443b | ||
|
|
03dfa67783 | ||
|
|
c5ea8ee2cc | ||
|
|
328774d5af | ||
|
|
5a7b1f8f9d | ||
|
|
bab42de3cd | ||
|
|
668b9efe9d | ||
|
|
42f89354c7 | ||
|
|
44ac52b92e | ||
|
|
c5245dcbac | ||
|
|
57cf364182 | ||
|
|
9f33146f3d | ||
|
|
7788eaec42 | ||
|
|
b6cda5221b | ||
|
|
f7a29fbff6 | ||
|
|
b9fbd1fce0 | ||
|
|
fedf396824 | ||
|
|
6e15880f3b | ||
|
|
435a3c851b | ||
|
|
4ebef4b41e | ||
|
|
919d8734e9 | ||
|
|
960868a682 | ||
|
|
c20fee01ae | ||
|
|
a031cf8143 | ||
|
|
caef740d94 | ||
|
|
ef937d0a91 | ||
|
|
684aa71734 | ||
|
|
c65cf963cd | ||
|
|
defaeb91bd | ||
|
|
1d74f7034c | ||
|
|
42d84c70f9 | ||
|
|
82c174ebe5 | ||
|
|
750c770f66 | ||
|
|
d5abe891c0 | ||
|
|
a0d87ada42 | ||
|
|
70175cbecb |
1
.gitattributes
vendored
1
.gitattributes
vendored
@@ -2,6 +2,7 @@
|
||||
/.symfony.bundle.yaml export-ignore
|
||||
/assets/src export-ignore
|
||||
/assets/test export-ignore
|
||||
/assets/vitest.config.mjs export-ignore
|
||||
/doc export-ignore
|
||||
/phpunit.xml.dist export-ignore
|
||||
/tests export-ignore
|
||||
|
||||
3
.github/PULL_REQUEST_TEMPLATE.md
vendored
3
.github/PULL_REQUEST_TEMPLATE.md
vendored
@@ -1,5 +1,4 @@
|
||||
Please do not submit any Pull Requests here. They will be closed.
|
||||
---
|
||||
## Please do not submit any Pull Requests here. They will be closed.
|
||||
|
||||
Please submit your PR here instead:
|
||||
https://github.com/symfony/ux
|
||||
|
||||
30
.github/workflows/close-pull-request.yml
vendored
30
.github/workflows/close-pull-request.yml
vendored
@@ -1,20 +1,20 @@
|
||||
name: Close Pull Request
|
||||
|
||||
on:
|
||||
pull_request_target:
|
||||
types: [opened]
|
||||
pull_request_target:
|
||||
types: [opened]
|
||||
|
||||
jobs:
|
||||
run:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: superbrothers/close-pull-request@v3
|
||||
with:
|
||||
comment: |
|
||||
Thanks for your Pull Request! We love contributions.
|
||||
|
||||
However, you should instead open your PR on the main repository:
|
||||
https://github.com/symfony/ux
|
||||
|
||||
This repository is what we call a "subtree split": a read-only subset of that main repository.
|
||||
We're looking forward to your PR there!
|
||||
run:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: superbrothers/close-pull-request@v3
|
||||
with:
|
||||
comment: |
|
||||
Thanks for your Pull Request! We love contributions.
|
||||
|
||||
However, you should instead open your PR on the main repository:
|
||||
https://github.com/symfony/ux
|
||||
|
||||
This repository is what we call a "subtree split": a read-only subset of that main repository.
|
||||
We're looking forward to your PR there!
|
||||
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,4 +1,5 @@
|
||||
/assets/node_modules/
|
||||
/config/reference.php
|
||||
/vendor/
|
||||
/composer.lock
|
||||
/phpunit.xml
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
branches: ["2.x"]
|
||||
maintained_branches: ["2.x"]
|
||||
doc_dir: "doc"
|
||||
branches: ['2.x']
|
||||
maintained_branches: ['2.x']
|
||||
doc_dir: 'doc'
|
||||
|
||||
46
CHANGELOG.md
46
CHANGELOG.md
@@ -1,42 +1,54 @@
|
||||
# CHANGELOG
|
||||
|
||||
## 2.33
|
||||
|
||||
- Change AssetMapper `excluded_patterns` from `**/controllers.json` to `*/controllers.json`
|
||||
|
||||
## 2.30
|
||||
|
||||
- Ensure compatibility with PHP 8.5
|
||||
|
||||
## 2.29.0
|
||||
|
||||
- Add Symfony 8 support
|
||||
|
||||
## 2.20.1
|
||||
|
||||
- Normalize Stimulus controller name in event name
|
||||
- Normalize Stimulus controller name in event name
|
||||
|
||||
## 2.14.2
|
||||
|
||||
- Fix bug with finding UX Packages with non-standard project structure
|
||||
- Fix bug with finding UX Packages with non-standard project structure
|
||||
|
||||
## 2.14.1
|
||||
|
||||
- Fixed bug with Stimulus controllers in subdirectories on Windows
|
||||
- Fixed bug with Stimulus controllers in subdirectories on Windows
|
||||
|
||||
## 2.14.0
|
||||
|
||||
- Added Typescript controllers support
|
||||
- Added Typescript controllers support
|
||||
|
||||
## 2.13.2
|
||||
|
||||
- Revert "Change JavaScript package to `type: module`"
|
||||
- Revert "Change JavaScript package to `type: module`"
|
||||
|
||||
## 2.13.0
|
||||
|
||||
- Normalize parameters names given to twig helper 'stimulus_action()'.
|
||||
**BC Break**: previously, parameters given in camelCase (eg.
|
||||
`bigCrocodile`) were incorrectly registered by the controller as
|
||||
flatcase (`event.params.bigcrocodile`). This was fixed, which means
|
||||
they are now correctly registered as camelCase
|
||||
(`event.params.bigCrocodile`).
|
||||
- Added AssetMapper 6.4 support.
|
||||
- Add Symfony 7 support.
|
||||
- Fix missing double dash in namespaced Stimulus outlets.
|
||||
- Change JavaScript package to `type: module`
|
||||
- Normalize parameters names given to twig helper 'stimulus_action()'.
|
||||
**BC Break**: previously, parameters given in camelCase (eg.
|
||||
`bigCrocodile`) were incorrectly registered by the controller as
|
||||
flatcase (`event.params.bigcrocodile`). This was fixed, which means
|
||||
they are now correctly registered as camelCase
|
||||
(`event.params.bigCrocodile`).
|
||||
- Added AssetMapper 6.4 support.
|
||||
- Add Symfony 7 support.
|
||||
- Fix missing double dash in namespaced Stimulus outlets.
|
||||
- Change JavaScript package to `type: module`
|
||||
|
||||
## 2.10.0
|
||||
|
||||
- Handle Stimulus outlets
|
||||
- Handle Stimulus outlets
|
||||
|
||||
## 2.9.0
|
||||
|
||||
- Introduce the bundle
|
||||
- Introduce the bundle
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
This bundle adds integration between Symfony, Stimulus and Symfony UX:
|
||||
|
||||
- A) Twig `stimulus_*` functions & filters to add Stimulus controllers, actions & targets in your templates;
|
||||
- B) Integration with Symfony UX & AssetMapper;
|
||||
- C) A helper service to build the Stimulus data attributes and use them in your services.
|
||||
- A) Twig `stimulus_*` functions & filters to add Stimulus controllers, actions & targets in your templates;
|
||||
- B) Integration with Symfony UX & AssetMapper;
|
||||
- C) A helper service to build the Stimulus data attributes and use them in your services.
|
||||
|
||||
[Read the documentation][1]
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ Read more at [symfony/ux#2708](https://github.com/symfony/ux/issues/2708).
|
||||
|
||||
## Resources
|
||||
|
||||
- [Documentation](https://symfony.com/bundles/StimulusBundle/current/index.html)
|
||||
- [Report issues](https://github.com/symfony/ux/issues) and
|
||||
[send Pull Requests](https://github.com/symfony/ux/pulls)
|
||||
in the [main Symfony UX repository](https://github.com/symfony/ux)
|
||||
- [Documentation](https://symfony.com/bundles/StimulusBundle/current/index.html)
|
||||
- [Report issues](https://github.com/symfony/ux/issues) and
|
||||
[send Pull Requests](https://github.com/symfony/ux/pulls)
|
||||
in the [main Symfony UX repository](https://github.com/symfony/ux)
|
||||
|
||||
21
assets/dist/controllers.d.ts
vendored
21
assets/dist/controllers.d.ts
vendored
@@ -1,12 +1,13 @@
|
||||
import type { ControllerConstructor } from '@hotwired/stimulus';
|
||||
export interface EagerControllersCollection {
|
||||
[key: string]: ControllerConstructor;
|
||||
import { ControllerConstructor } from "@hotwired/stimulus";
|
||||
interface EagerControllersCollection {
|
||||
[key: string]: ControllerConstructor;
|
||||
}
|
||||
export interface LazyControllersCollection {
|
||||
[key: string]: () => Promise<{
|
||||
default: ControllerConstructor;
|
||||
}>;
|
||||
interface LazyControllersCollection {
|
||||
[key: string]: () => Promise<{
|
||||
default: ControllerConstructor;
|
||||
}>;
|
||||
}
|
||||
export declare const eagerControllers: EagerControllersCollection;
|
||||
export declare const lazyControllers: LazyControllersCollection;
|
||||
export declare const isApplicationDebug = false;
|
||||
declare const eagerControllers: EagerControllersCollection;
|
||||
declare const lazyControllers: LazyControllersCollection;
|
||||
declare const isApplicationDebug = false;
|
||||
export { EagerControllersCollection, LazyControllersCollection, eagerControllers, isApplicationDebug, lazyControllers };
|
||||
1
assets/dist/controllers.js
vendored
1
assets/dist/controllers.js
vendored
@@ -1,5 +1,4 @@
|
||||
const eagerControllers = {};
|
||||
const lazyControllers = {};
|
||||
const isApplicationDebug = false;
|
||||
|
||||
export { eagerControllers, isApplicationDebug, lazyControllers };
|
||||
|
||||
9
assets/dist/loader.d.ts
vendored
9
assets/dist/loader.d.ts
vendored
@@ -1,4 +1,5 @@
|
||||
import { Application } from '@hotwired/stimulus';
|
||||
import { type EagerControllersCollection, type LazyControllersCollection } from './controllers.js';
|
||||
export declare const loadControllers: (application: Application, eagerControllers: EagerControllersCollection, lazyControllers: LazyControllersCollection) => void;
|
||||
export declare const startStimulusApp: () => Application;
|
||||
import { Application } from "@hotwired/stimulus";
|
||||
import { EagerControllersCollection, LazyControllersCollection } from "./controllers.js";
|
||||
declare const loadControllers: (application: Application, eagerControllers: EagerControllersCollection, lazyControllers: LazyControllersCollection) => void;
|
||||
declare const startStimulusApp: () => Application;
|
||||
export { loadControllers, startStimulusApp };
|
||||
141
assets/dist/loader.js
vendored
141
assets/dist/loader.js
vendored
@@ -1,93 +1,70 @@
|
||||
import { Application } from '@hotwired/stimulus';
|
||||
import { isApplicationDebug, eagerControllers, lazyControllers } from './controllers.js';
|
||||
|
||||
const controllerAttribute = 'data-controller';
|
||||
import { Application } from "@hotwired/stimulus";
|
||||
import { eagerControllers, isApplicationDebug, lazyControllers } from "./controllers.js";
|
||||
const controllerAttribute = "data-controller";
|
||||
const loadControllers = (application, eagerControllers, lazyControllers) => {
|
||||
for (const name in eagerControllers) {
|
||||
registerController(name, eagerControllers[name], application);
|
||||
}
|
||||
const lazyControllerHandler = new StimulusLazyControllerHandler(application, lazyControllers);
|
||||
lazyControllerHandler.start();
|
||||
for (const name in eagerControllers) registerController(name, eagerControllers[name], application);
|
||||
new StimulusLazyControllerHandler(application, lazyControllers).start();
|
||||
};
|
||||
const startStimulusApp = () => {
|
||||
const application = Application.start();
|
||||
application.debug = isApplicationDebug;
|
||||
loadControllers(application, eagerControllers, lazyControllers);
|
||||
return application;
|
||||
const application = Application.start();
|
||||
application.debug = isApplicationDebug;
|
||||
loadControllers(application, eagerControllers, lazyControllers);
|
||||
return application;
|
||||
};
|
||||
var StimulusLazyControllerHandler = class {
|
||||
constructor(application, lazyControllers) {
|
||||
this.application = application;
|
||||
this.lazyControllers = lazyControllers;
|
||||
}
|
||||
start() {
|
||||
this.lazyLoadExistingControllers(document.documentElement);
|
||||
this.lazyLoadNewControllers(document.documentElement);
|
||||
}
|
||||
lazyLoadExistingControllers(element) {
|
||||
Array.from(element.querySelectorAll(`[${controllerAttribute}]`)).flatMap(extractControllerNamesFrom).forEach((controllerName) => {
|
||||
this.loadLazyController(controllerName);
|
||||
});
|
||||
}
|
||||
loadLazyController(name) {
|
||||
if (!this.lazyControllers[name]) return;
|
||||
const controllerLoader = this.lazyControllers[name];
|
||||
delete this.lazyControllers[name];
|
||||
if (!canRegisterController(name, this.application)) return;
|
||||
this.application.logDebugActivity(name, "lazy:loading");
|
||||
controllerLoader().then((controllerModule) => {
|
||||
this.application.logDebugActivity(name, "lazy:loaded");
|
||||
registerController(name, controllerModule.default, this.application);
|
||||
}).catch((error) => {
|
||||
console.error(`Error loading controller "${name}":`, error);
|
||||
});
|
||||
}
|
||||
lazyLoadNewControllers(element) {
|
||||
if (Object.keys(this.lazyControllers).length === 0) return;
|
||||
new MutationObserver((mutationsList) => {
|
||||
for (const { attributeName, target, type } of mutationsList) switch (type) {
|
||||
case "attributes":
|
||||
if (attributeName === controllerAttribute && target.getAttribute(controllerAttribute)) extractControllerNamesFrom(target).forEach((controllerName) => {
|
||||
this.loadLazyController(controllerName);
|
||||
});
|
||||
break;
|
||||
case "childList": this.lazyLoadExistingControllers(target);
|
||||
}
|
||||
}).observe(element, {
|
||||
attributeFilter: [controllerAttribute],
|
||||
subtree: true,
|
||||
childList: true
|
||||
});
|
||||
}
|
||||
};
|
||||
class StimulusLazyControllerHandler {
|
||||
constructor(application, lazyControllers) {
|
||||
this.application = application;
|
||||
this.lazyControllers = lazyControllers;
|
||||
}
|
||||
start() {
|
||||
this.lazyLoadExistingControllers(document.documentElement);
|
||||
this.lazyLoadNewControllers(document.documentElement);
|
||||
}
|
||||
lazyLoadExistingControllers(element) {
|
||||
Array.from(element.querySelectorAll(`[${controllerAttribute}]`))
|
||||
.flatMap(extractControllerNamesFrom)
|
||||
.forEach((controllerName) => this.loadLazyController(controllerName));
|
||||
}
|
||||
loadLazyController(name) {
|
||||
if (!this.lazyControllers[name]) {
|
||||
return;
|
||||
}
|
||||
const controllerLoader = this.lazyControllers[name];
|
||||
delete this.lazyControllers[name];
|
||||
if (!canRegisterController(name, this.application)) {
|
||||
return;
|
||||
}
|
||||
this.application.logDebugActivity(name, 'lazy:loading');
|
||||
controllerLoader()
|
||||
.then((controllerModule) => {
|
||||
this.application.logDebugActivity(name, 'lazy:loaded');
|
||||
registerController(name, controllerModule.default, this.application);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(`Error loading controller "${name}":`, error);
|
||||
});
|
||||
}
|
||||
lazyLoadNewControllers(element) {
|
||||
if (Object.keys(this.lazyControllers).length === 0) {
|
||||
return;
|
||||
}
|
||||
new MutationObserver((mutationsList) => {
|
||||
for (const { attributeName, target, type } of mutationsList) {
|
||||
switch (type) {
|
||||
case 'attributes': {
|
||||
if (attributeName === controllerAttribute &&
|
||||
target.getAttribute(controllerAttribute)) {
|
||||
extractControllerNamesFrom(target).forEach((controllerName) => this.loadLazyController(controllerName));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'childList': {
|
||||
this.lazyLoadExistingControllers(target);
|
||||
}
|
||||
}
|
||||
}
|
||||
}).observe(element, {
|
||||
attributeFilter: [controllerAttribute],
|
||||
subtree: true,
|
||||
childList: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
function registerController(name, controller, application) {
|
||||
if (canRegisterController(name, application)) {
|
||||
application.register(name, controller);
|
||||
}
|
||||
if (canRegisterController(name, application)) application.register(name, controller);
|
||||
}
|
||||
function extractControllerNamesFrom(element) {
|
||||
const controllerNameValue = element.getAttribute(controllerAttribute);
|
||||
if (!controllerNameValue) {
|
||||
return [];
|
||||
}
|
||||
return controllerNameValue.split(/\s+/).filter((content) => content.length);
|
||||
const controllerNameValue = element.getAttribute(controllerAttribute);
|
||||
if (!controllerNameValue) return [];
|
||||
return controllerNameValue.split(/\s+/).filter((content) => content.length);
|
||||
}
|
||||
function canRegisterController(name, application) {
|
||||
return !application.router.modulesByIdentifier.has(name);
|
||||
return !application.router.modulesByIdentifier.has(name);
|
||||
}
|
||||
|
||||
export { loadControllers, startStimulusApp };
|
||||
|
||||
@@ -3,23 +3,22 @@
|
||||
"description": "Integration of @hotwired/stimulus into Symfony",
|
||||
"private": true,
|
||||
"license": "MIT",
|
||||
"version": "2.25.1",
|
||||
"version": "2.34.0",
|
||||
"keywords": [
|
||||
"symfony-ux"
|
||||
],
|
||||
"homepage": "https://ux.symfony.com/stimulus",
|
||||
"repository": "https://github.com/symfony/stimulus-bundle",
|
||||
"repository": "https://github.com/symfony/ux",
|
||||
"type": "module",
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"main": "dist/loader.js",
|
||||
"scripts": {
|
||||
"build": "node ../../../bin/build_package.js .",
|
||||
"watch": "node ../../../bin/build_package.js . --watch",
|
||||
"test": "../../../bin/test_package.sh .",
|
||||
"check": "biome check",
|
||||
"ci": "biome ci"
|
||||
"build": "node ../../../bin/build_package.ts .",
|
||||
"watch": "node ../../../bin/build_package.ts . --watch",
|
||||
"test": "pnpm run test:unit && pnpm run test:browser",
|
||||
"test:unit": "../../../bin/unit_test_package.sh ."
|
||||
},
|
||||
"symfony": {
|
||||
"needsPackageAsADependency": false,
|
||||
@@ -31,5 +30,14 @@
|
||||
"peerDependencies": {
|
||||
"@hotwired/stimulus": "^3.0.0",
|
||||
"@symfony/stimulus-bridge": "^3.2.0 || ^4.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@testing-library/dom": "^10.4.0",
|
||||
"@testing-library/jest-dom": "^6.6.3",
|
||||
"@testing-library/user-event": "^14.6.1",
|
||||
"jsdom": "^26.1.0",
|
||||
"tslib": "^2.8.1",
|
||||
"typescript": "^5.8.3",
|
||||
"vitest": "^4.1.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,9 +15,9 @@
|
||||
import { Application, type ControllerConstructor } from '@hotwired/stimulus';
|
||||
import {
|
||||
type EagerControllersCollection,
|
||||
type LazyControllersCollection,
|
||||
eagerControllers,
|
||||
isApplicationDebug,
|
||||
type LazyControllersCollection,
|
||||
lazyControllers,
|
||||
} from './controllers.js';
|
||||
|
||||
@@ -66,10 +66,12 @@ class StimulusLazyControllerHandler {
|
||||
private lazyLoadExistingControllers(element: Element) {
|
||||
Array.from(element.querySelectorAll(`[${controllerAttribute}]`))
|
||||
.flatMap(extractControllerNamesFrom)
|
||||
.forEach((controllerName) => this.loadLazyController(controllerName));
|
||||
.forEach((controllerName) => {
|
||||
this.loadLazyController(controllerName);
|
||||
});
|
||||
}
|
||||
|
||||
private loadLazyController(name: string) {
|
||||
private loadLazyController(name: string): void {
|
||||
if (!this.lazyControllers[name]) {
|
||||
return;
|
||||
}
|
||||
@@ -106,9 +108,9 @@ class StimulusLazyControllerHandler {
|
||||
attributeName === controllerAttribute &&
|
||||
(target as Element).getAttribute(controllerAttribute)
|
||||
) {
|
||||
extractControllerNamesFrom(target as Element).forEach((controllerName) =>
|
||||
this.loadLazyController(controllerName)
|
||||
);
|
||||
extractControllerNamesFrom(target as Element).forEach((controllerName) => {
|
||||
this.loadLazyController(controllerName);
|
||||
});
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -144,6 +146,6 @@ function extractControllerNamesFrom(element: Element): string[] {
|
||||
}
|
||||
|
||||
function canRegisterController(name: string, application: Application) {
|
||||
// @ts-ignore
|
||||
// @ts-expect-error
|
||||
return !application.router.modulesByIdentifier.has(name);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { Application, Controller } from '@hotwired/stimulus';
|
||||
import { waitFor } from '@testing-library/dom';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
// load from dist because the source TypeScript file points directly to controllers.js,
|
||||
// which does not actually exist in the source code
|
||||
import { loadControllers } from '../dist/loader';
|
||||
import type { EagerControllersCollection, LazyControllersCollection } from '../src/controllers';
|
||||
import { loadControllers } from '../../dist/loader';
|
||||
import type { EagerControllersCollection, LazyControllersCollection } from '../../src/controllers';
|
||||
|
||||
let isController1Initialized = false;
|
||||
let isController2Initialized = false;
|
||||
3
assets/tsconfig.json
Normal file
3
assets/tsconfig.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "../../../tsconfig.package.json"
|
||||
}
|
||||
4
assets/vitest.config.mjs
Normal file
4
assets/vitest.config.mjs
Normal file
@@ -0,0 +1,4 @@
|
||||
import { mergeConfig } from 'vitest/config';
|
||||
import configShared from '../../../vitest.config.base.mjs';
|
||||
|
||||
export default mergeConfig(configShared, {});
|
||||
@@ -14,18 +14,18 @@
|
||||
],
|
||||
"require": {
|
||||
"php": ">=8.1",
|
||||
"symfony/config": "^5.4|^6.0|^7.0",
|
||||
"symfony/dependency-injection": "^5.4|^6.0|^7.0",
|
||||
"symfony/finder": "^5.4|^6.0|^7.0",
|
||||
"symfony/http-kernel": "^5.4|^6.0|^7.0",
|
||||
"symfony/config": "^5.4|^6.0|^7.0|^8.0",
|
||||
"symfony/dependency-injection": "^5.4|^6.0|^7.0|^8.0",
|
||||
"symfony/finder": "^5.4|^6.0|^7.0|^8.0",
|
||||
"symfony/http-kernel": "^5.4|^6.0|^7.0|^8.0",
|
||||
"twig/twig": "^2.15.3|^3.8",
|
||||
"symfony/deprecation-contracts": "^2.0|^3.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"symfony/asset-mapper": "^6.3|^7.0",
|
||||
"symfony/framework-bundle": "^5.4|^6.0|^7.0",
|
||||
"symfony/phpunit-bridge": "^5.4|^6.0|^7.0",
|
||||
"symfony/twig-bundle": "^5.4|^6.0|^7.0",
|
||||
"symfony/asset-mapper": "^6.3|^7.0|^8.0",
|
||||
"symfony/framework-bundle": "^5.4|^6.0|^7.0|^8.0",
|
||||
"symfony/phpunit-bridge": "^5.4|^6.0|^7.0|^8.0",
|
||||
"symfony/twig-bundle": "^5.4|^6.0|^7.0|^8.0",
|
||||
"zenstruck/browser": "^1.4"
|
||||
},
|
||||
"minimum-stability": "dev",
|
||||
|
||||
@@ -174,15 +174,15 @@ For example:
|
||||
|
||||
.. code-block:: html+twig
|
||||
|
||||
<div {{ stimulus_controller('chart', { 'name': 'Likes', 'data': [1, 2, 3, 4] }) }}>
|
||||
<div {{ stimulus_controller('hello', { 'name': 'World', 'data': [1, 2, 3, 4] }) }}>
|
||||
Hello
|
||||
</div>
|
||||
|
||||
<!-- would render -->
|
||||
<div
|
||||
data-controller="chart"
|
||||
data-chart-name-value="Likes"
|
||||
data-chart-data-value="[1,2,3,4]"
|
||||
data-controller="hello"
|
||||
data-hello-name-value="World"
|
||||
data-hello-data-value="[1,2,3,4]"
|
||||
>
|
||||
Hello
|
||||
</div>
|
||||
@@ -191,22 +191,22 @@ If you want to set CSS classes:
|
||||
|
||||
.. code-block:: html+twig
|
||||
|
||||
<div {{ stimulus_controller('chart', { 'name': 'Likes', 'data': [1, 2, 3, 4] }, { 'loading': 'spinner' }) }}>
|
||||
<div {{ stimulus_controller('hello', { 'name': 'World', 'data': [1, 2, 3, 4] }, { 'loading': 'spinner' }) }}>
|
||||
Hello
|
||||
</div>
|
||||
|
||||
<!-- would render -->
|
||||
<div
|
||||
data-controller="chart"
|
||||
data-chart-name-value="Likes"
|
||||
data-chart-data-value="[1,2,3,4]"
|
||||
data-chart-loading-class="spinner"
|
||||
data-controller="hello"
|
||||
data-hello-name-value="World"
|
||||
data-hello-data-value="[1,2,3,4]"
|
||||
data-hello-loading-class="spinner"
|
||||
>
|
||||
Hello
|
||||
</div>
|
||||
|
||||
<!-- or without values -->
|
||||
<div {{ stimulus_controller('chart', controllerClasses = { 'loading': 'spinner' }) }}>
|
||||
<div {{ stimulus_controller('hello', controllerClasses: { 'loading': 'spinner' }) }}>
|
||||
Hello
|
||||
</div>
|
||||
|
||||
@@ -214,8 +214,8 @@ And with outlets:
|
||||
|
||||
.. code-block:: html+twig
|
||||
|
||||
<div {{ stimulus_controller('chart',
|
||||
{ 'name': 'Likes', 'data': [1, 2, 3, 4] },
|
||||
<div {{ stimulus_controller('hello',
|
||||
{ 'name': 'World', 'data': [1, 2, 3, 4] },
|
||||
{ 'loading': 'spinner' },
|
||||
{ 'other': '.target' } ) }}>
|
||||
Hello
|
||||
@@ -223,17 +223,17 @@ And with outlets:
|
||||
|
||||
<!-- would render -->
|
||||
<div
|
||||
data-controller="chart"
|
||||
data-chart-name-value="Likes"
|
||||
data-chart-data-value="[1,2,3,4]"
|
||||
data-chart-loading-class="spinner"
|
||||
data-chart-other-outlet=".target"
|
||||
data-controller="hello"
|
||||
data-hello-name-value="World"
|
||||
data-hello-data-value="[1,2,3,4]"
|
||||
data-hello-loading-class="spinner"
|
||||
data-hello-other-outlet=".target"
|
||||
>
|
||||
Hello
|
||||
</div>
|
||||
|
||||
<!-- or without values/classes -->
|
||||
<div {{ stimulus_controller('chart', controllerOutlets = { 'other': '.target' }) }}>
|
||||
<div {{ stimulus_controller('hello', controllerOutlets: { 'other': '.target' }) }}>
|
||||
Hello
|
||||
</div>
|
||||
|
||||
@@ -246,12 +246,12 @@ there's also a ``stimulus_controller`` filter:
|
||||
|
||||
.. code-block:: html+twig
|
||||
|
||||
<div {{ stimulus_controller('chart', { 'name': 'Likes' })|stimulus_controller('other-controller') }}>
|
||||
<div {{ stimulus_controller('hello', { 'name': 'World' })|stimulus_controller('other-controller') }}>
|
||||
Hello
|
||||
</div>
|
||||
|
||||
<!-- would render -->
|
||||
<div data-controller="chart other-controller" data-chart-name-value="Likes">
|
||||
<div data-controller="hello other-controller" data-hello-name-value="World">
|
||||
Hello
|
||||
</div>
|
||||
|
||||
@@ -259,7 +259,7 @@ You can also retrieve the generated attributes as an array, which can be helpful
|
||||
|
||||
.. code-block:: twig
|
||||
|
||||
{{ form_start(form, { attr: stimulus_controller('chart', { 'name': 'Likes' }).toArray() }) }}
|
||||
{{ form_start(form, { attr: stimulus_controller('hello', { 'name': 'World' }).toArray() }) }}
|
||||
|
||||
stimulus_action
|
||||
~~~~~~~~~~~~~~~
|
||||
@@ -418,7 +418,7 @@ is running in debug mode.
|
||||
|
||||
.. tip::
|
||||
|
||||
For AssetMapper 6.3 only, you also need a ``{{ ux_controller_link_tags() }``
|
||||
For AssetMapper 6.3 only, you also need a ``{{ ux_controller_link_tags() }}``
|
||||
in ``base.html.twig``. This is not needed in AssetMapper 6.4+.
|
||||
|
||||
With WebpackEncoreBundle
|
||||
|
||||
@@ -1,38 +1,38 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html -->
|
||||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="vendor/bin/.phpunit/phpunit.xsd"
|
||||
colors="true"
|
||||
bootstrap="vendor/autoload.php"
|
||||
failOnRisky="true"
|
||||
failOnWarning="true"
|
||||
<phpunit
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="vendor/bin/.phpunit/phpunit.xsd"
|
||||
colors="true"
|
||||
bootstrap="vendor/autoload.php"
|
||||
failOnRisky="true"
|
||||
failOnWarning="true"
|
||||
>
|
||||
<php>
|
||||
<ini name="error_reporting" value="-1" />
|
||||
<server name="KERNEL_CLASS" value="Symfony\UX\Autocomplete\Tests\Fixtures\Kernel" />
|
||||
<server name="DATABASE_URL" value="sqlite:///%kernel.project_dir%/var/data.db" />
|
||||
<ini name="error_reporting" value="-1"/>
|
||||
<env name="SHELL_VERBOSITY" value="-1"/>
|
||||
<server name="SYMFONY_DEPRECATIONS_HELPER" value="max[self]=0&max[direct]=0"/>
|
||||
<env name="SYMFONY_DEPRECATIONS_HELPER" value="max[self]=0&max[direct]=0"/>
|
||||
<env name="KERNEL_CLASS" value="Symfony\UX\Autocomplete\Tests\Fixtures\Kernel"/>
|
||||
<env name="DATABASE_URL" value="sqlite:///%kernel.project_dir%/var/data.db"/>
|
||||
</php>
|
||||
|
||||
<testsuites>
|
||||
<testsuite name="symfony/ux-autocomplete Test Suite">
|
||||
<directory>./tests/</directory>
|
||||
<testsuite name="Symfony UX Stimulus Test Suite">
|
||||
<directory>./tests</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
|
||||
<filter>
|
||||
<whitelist processUncoveredFilesFromWhitelist="true">
|
||||
<directory suffix=".php">./src</directory>
|
||||
</whitelist>
|
||||
</filter>
|
||||
<coverage>
|
||||
<include>
|
||||
<directory>./src</directory>
|
||||
</include>
|
||||
</coverage>
|
||||
|
||||
<listeners>
|
||||
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener"/>
|
||||
</listeners>
|
||||
|
||||
<extensions>
|
||||
<extension class="Zenstruck\Browser\Test\BrowserExtension" />
|
||||
<extension class="Zenstruck\Browser\Test\BrowserExtension"/>
|
||||
</extensions>
|
||||
</phpunit>
|
||||
|
||||
@@ -70,6 +70,11 @@ class ControllersMapGenerator
|
||||
|
||||
$controllersMap = [];
|
||||
foreach ($finder as $file) {
|
||||
// Skip .ts controller if .js version is available
|
||||
if ('ts' === $file->getExtension() && file_exists(substr($file->getRealPath(), 0, -2).'js')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$name = $file->getRelativePathname();
|
||||
// use regex to extract 'controller'-postfix including extension
|
||||
preg_match(self::FILENAME_REGEX, $name, $matches);
|
||||
@@ -77,6 +82,10 @@ class ControllersMapGenerator
|
||||
$name = str_replace(['_', '/', '\\'], ['-', '--', '--'], $name);
|
||||
|
||||
$asset = $this->assetMapper->getAssetFromSourcePath($file->getRealPath());
|
||||
if (!$asset) {
|
||||
throw new \RuntimeException(\sprintf('Could not find an asset mapper path that points to the "%s" controller.', $name));
|
||||
}
|
||||
|
||||
$content = file_get_contents($asset->sourcePath);
|
||||
$isLazy = preg_match('/\/\*\s*stimulusFetch:\s*\'lazy\'\s*\*\//i', $content);
|
||||
|
||||
|
||||
@@ -95,7 +95,7 @@ class StimulusLoaderJavaScriptCompiler implements AssetCompilerInterface
|
||||
} else {
|
||||
// import $relativeImportPath and also the auto-imports
|
||||
// and use a Promise.all() to wait for all of them
|
||||
$lazyControllers[] = \sprintf('%s: () => Promise.all([import(%s), %s]).then((ret) => ret[0])', json_encode($name), $relativeImportPath, implode(', ', array_map(fn ($path) => "import($path)", $autoImportPaths)));
|
||||
$lazyControllers[] = \sprintf('%s: () => Promise.all([import(%s), %s]).then((ret) => ret[0])', json_encode($name), $relativeImportPath, implode(', ', array_map(static fn ($path) => "import($path)", $autoImportPaths)));
|
||||
}
|
||||
|
||||
continue;
|
||||
@@ -124,10 +124,10 @@ class StimulusLoaderJavaScriptCompiler implements AssetCompilerInterface
|
||||
$isDebugString = $this->isDebug ? 'true' : 'false';
|
||||
|
||||
return <<<EOF
|
||||
$importCode
|
||||
export const eagerControllers = $eagerControllersJson;
|
||||
export const lazyControllers = $lazyControllersExpression;
|
||||
export const isApplicationDebug = $isDebugString;
|
||||
EOF;
|
||||
$importCode
|
||||
export const eagerControllers = $eagerControllersJson;
|
||||
export const lazyControllers = $lazyControllersExpression;
|
||||
export const isApplicationDebug = $isDebugString;
|
||||
EOF;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
*/
|
||||
class RemoveAssetMapperServicesCompiler implements CompilerPassInterface
|
||||
{
|
||||
public function process(ContainerBuilder $container)
|
||||
public function process(ContainerBuilder $container): void
|
||||
{
|
||||
if (!$container->hasDefinition('asset_mapper')) {
|
||||
$container->removeDefinition('stimulus.ux_controllers_twig_runtime');
|
||||
|
||||
@@ -18,9 +18,9 @@ use Symfony\Component\Config\Definition\Builder\TreeBuilder;
|
||||
use Symfony\Component\Config\Definition\ConfigurationInterface;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Extension\Extension;
|
||||
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
|
||||
use Symfony\Component\DependencyInjection\Loader;
|
||||
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
|
||||
|
||||
/**
|
||||
* @author Ryan Weaver <ryan@symfonycasts.com>
|
||||
@@ -43,7 +43,7 @@ final class StimulusExtension extends Extension implements PrependExtensionInter
|
||||
}
|
||||
}
|
||||
|
||||
public function prepend(ContainerBuilder $container)
|
||||
public function prepend(ContainerBuilder $container): void
|
||||
{
|
||||
if (!$this->isAssetMapperAvailable($container)) {
|
||||
return;
|
||||
@@ -56,7 +56,7 @@ final class StimulusExtension extends Extension implements PrependExtensionInter
|
||||
],
|
||||
'excluded_patterns' => [
|
||||
'*.d.ts',
|
||||
'**/controllers.json',
|
||||
'*/controllers.json',
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
@@ -141,7 +141,7 @@ class StimulusAttributes implements \Stringable, \IteratorAggregate
|
||||
|
||||
public function toArray(): array
|
||||
{
|
||||
$actions = array_map(function (array $actionData): string {
|
||||
$actions = array_map(static function (array $actionData): string {
|
||||
$controllerName = $actionData['controllerName'];
|
||||
$actionName = $actionData['actionName'];
|
||||
$eventName = $actionData['eventName'];
|
||||
|
||||
@@ -25,7 +25,7 @@ final class StimulusBundle extends Bundle
|
||||
return \dirname(__DIR__);
|
||||
}
|
||||
|
||||
public function build(ContainerBuilder $container)
|
||||
public function build(ContainerBuilder $container): void
|
||||
{
|
||||
$container->addCompilerPass(new RemoveAssetMapperServicesCompiler());
|
||||
}
|
||||
|
||||
@@ -151,7 +151,7 @@ final class UxControllersTwigRuntime implements RuntimeExtensionInterface
|
||||
|
||||
private function getJsDelivrUrl(string $package, ?string $version, string $file): string
|
||||
{
|
||||
$version = $version ?? 'latest';
|
||||
$version ??= 'latest';
|
||||
$package = str_replace('@', '', $package);
|
||||
|
||||
return \sprintf('https://cdn.jsdelivr.net/npm/%s@%s/%s', $package, $version, $file);
|
||||
|
||||
@@ -27,13 +27,15 @@ class ControllersMapGeneratorTest extends TestCase
|
||||
$mapper = $this->createMock(AssetMapperInterface::class);
|
||||
$mapper->expects($this->any())
|
||||
->method('getAssetFromSourcePath')
|
||||
->willReturnCallback(function ($path) {
|
||||
->willReturnCallback(static function ($path) {
|
||||
if (str_ends_with($path, 'package-controller-first.js')) {
|
||||
$logicalPath = 'fake-vendor/ux-package1/package-controller-first.js';
|
||||
} elseif (str_ends_with($path, 'package-controller-second.js')) {
|
||||
$logicalPath = 'fake-vendor/ux-package1/package-controller-second.js';
|
||||
} elseif (str_ends_with($path, 'package-hello-controller.js')) {
|
||||
$logicalPath = 'fake-vendor/ux-package2/package-hello-controller.js';
|
||||
} elseif (str_ends_with($path, 'other-controller.ts') || str_ends_with($path, 'excluded-controller.js')) {
|
||||
return null;
|
||||
} else {
|
||||
// replace windows slashes
|
||||
$path = str_replace('\\', '/', $path);
|
||||
@@ -55,7 +57,7 @@ class ControllersMapGeneratorTest extends TestCase
|
||||
if (class_exists(ImportMapConfigReader::class)) {
|
||||
$autoImportLocator->expects($this->any())
|
||||
->method('locateAutoImport')
|
||||
->willReturnCallback(function ($path) {
|
||||
->willReturnCallback(static function ($path) {
|
||||
return new MappedControllerAutoImport('/path/to'.$path, false);
|
||||
});
|
||||
} else {
|
||||
@@ -75,15 +77,18 @@ class ControllersMapGeneratorTest extends TestCase
|
||||
$autoImportLocator,
|
||||
);
|
||||
|
||||
$this->expectException(\RuntimeException::class);
|
||||
$this->expectExceptionMessage('Could not find an asset mapper path that points to the "excluded" controller.');
|
||||
$map = $generator->getControllersMap();
|
||||
// + 3 controller.json UX controllers
|
||||
// - 1 controllers.json UX controller is disabled
|
||||
// + 10 custom controllers (1 file is not a controller & 1 is overridden)
|
||||
$this->assertCount(12, $map);
|
||||
// + 11 custom controllers (1 file is not a controller, 1 is overridden)
|
||||
$this->assertCount(13, $map);
|
||||
$packageNames = array_keys($map);
|
||||
sort($packageNames);
|
||||
$this->assertSame([
|
||||
'bye',
|
||||
'excluded',
|
||||
'fake-vendor--ux-package1--controller-second',
|
||||
'fake-vendor--ux-package2--hello-controller',
|
||||
'hello',
|
||||
|
||||
@@ -42,10 +42,10 @@ class StimulusControllerLoaderFunctionalTest extends WebTestCase
|
||||
|
||||
if (class_exists(ImportMapConfigReader::class)) {
|
||||
// filter out items ending in .css
|
||||
$importMapJsKeys = array_filter($importMapKeys, function ($key) {
|
||||
$importMapJsKeys = array_filter($importMapKeys, static function ($key) {
|
||||
return '.css' !== substr($key, -4);
|
||||
});
|
||||
$importMapCssKeys = array_filter($importMapKeys, function ($key) {
|
||||
$importMapCssKeys = array_filter($importMapKeys, static function ($key) {
|
||||
return '.css' === substr($key, -4);
|
||||
});
|
||||
sort($importMapJsKeys);
|
||||
@@ -63,7 +63,8 @@ class StimulusControllerLoaderFunctionalTest extends WebTestCase
|
||||
// 2x from UX packages, which are enabled in controllers.json
|
||||
'/assets/fake-vendor/ux-package1/package-controller-second.js',
|
||||
'/assets/fake-vendor/ux-package2/package-hello-controller.js',
|
||||
// 3x from more-controllers
|
||||
// 4x from more-controllers
|
||||
'/assets/more-controllers/excluded-controller.js',
|
||||
'/assets/more-controllers/hello-controller.js',
|
||||
'/assets/more-controllers/minified-controller.js',
|
||||
'/assets/more-controllers/other-controller.js',
|
||||
@@ -91,7 +92,7 @@ class StimulusControllerLoaderFunctionalTest extends WebTestCase
|
||||
], array_values($importMapCssKeys));
|
||||
|
||||
// "app" is the entry. So, all non-lazy controllers should be preloaded:
|
||||
$preLoadHrefs = $crawler->filter('link[rel="modulepreload"]')->each(function ($link) {
|
||||
$preLoadHrefs = $crawler->filter('link[rel="modulepreload"]')->each(static function ($link) {
|
||||
return $link->attr('href');
|
||||
});
|
||||
$this->assertCount(12, $preLoadHrefs);
|
||||
@@ -134,7 +135,7 @@ class StimulusControllerLoaderFunctionalTest extends WebTestCase
|
||||
], $importMapKeys);
|
||||
|
||||
// "app" & loader.js are pre-loaded. So, all non-lazy controllers should be preloaded:
|
||||
$preLoadHrefs = $crawler->filter('link[rel="modulepreload"]')->each(function ($link) {
|
||||
$preLoadHrefs = $crawler->filter('link[rel="modulepreload"]')->each(static function ($link) {
|
||||
return $link->attr('href');
|
||||
});
|
||||
$this->assertCount(10, $preLoadHrefs);
|
||||
|
||||
@@ -25,21 +25,21 @@ final class StimulusAttributesTest extends TestCase
|
||||
$this->stimulusAttributes = new StimulusAttributes(new Environment(new ArrayLoader()));
|
||||
}
|
||||
|
||||
public function testAddAction(): void
|
||||
public function testAddAction()
|
||||
{
|
||||
$this->stimulusAttributes->addAction('foo', 'bar', 'baz', ['qux' => '"']);
|
||||
$attributesHtml = (string) $this->stimulusAttributes;
|
||||
self::assertSame('data-action="baz->foo#bar" data-foo-qux-param="""', $attributesHtml);
|
||||
}
|
||||
|
||||
public function testAddActionToArrayNoEscapingAttributeValues(): void
|
||||
public function testAddActionToArrayNoEscapingAttributeValues()
|
||||
{
|
||||
$this->stimulusAttributes->addAction('foo', 'bar', 'baz', ['qux' => '"']);
|
||||
$attributesArray = $this->stimulusAttributes->toArray();
|
||||
self::assertSame(['data-action' => 'baz->foo#bar', 'data-foo-qux-param' => '"'], $attributesArray);
|
||||
}
|
||||
|
||||
public function testAddActionWithMultiple(): void
|
||||
public function testAddActionWithMultiple()
|
||||
{
|
||||
$this->stimulusAttributes->addAction('my-controller', 'onClick');
|
||||
$this->assertSame('data-action="my-controller#onClick"', (string) $this->stimulusAttributes);
|
||||
@@ -52,7 +52,7 @@ final class StimulusAttributesTest extends TestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function testAddControllerToStringEscapingAttributeValues(): void
|
||||
public function testAddControllerToStringEscapingAttributeValues()
|
||||
{
|
||||
$this->stimulusAttributes->addController('foo', ['bar' => '"'], ['baz' => '"']);
|
||||
$attributesHtml = (string) $this->stimulusAttributes;
|
||||
@@ -64,7 +64,7 @@ final class StimulusAttributesTest extends TestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function testAddControllerToArrayNoEscapingAttributeValues(): void
|
||||
public function testAddControllerToArrayNoEscapingAttributeValues()
|
||||
{
|
||||
$this->stimulusAttributes->addController('foo', ['bar' => '"'], ['baz' => '"']);
|
||||
$attributesArray = $this->stimulusAttributes->toArray();
|
||||
@@ -101,21 +101,21 @@ final class StimulusAttributesTest extends TestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function testAddTargetToStringEscapingAttributeValues(): void
|
||||
public function testAddTargetToStringEscapingAttributeValues()
|
||||
{
|
||||
$this->stimulusAttributes->addTarget('foo', '"');
|
||||
$attributesHtml = (string) $this->stimulusAttributes;
|
||||
self::assertSame('data-foo-target="""', $attributesHtml);
|
||||
}
|
||||
|
||||
public function testAddTargetToArrayNoEscapingAttributeValues(): void
|
||||
public function testAddTargetToArrayNoEscapingAttributeValues()
|
||||
{
|
||||
$this->stimulusAttributes->addTarget('foo', '"');
|
||||
$attributesArray = $this->stimulusAttributes->toArray();
|
||||
self::assertSame(['data-foo-target' => '"'], $attributesArray);
|
||||
}
|
||||
|
||||
public function testAddTargetWithMultiple(): void
|
||||
public function testAddTargetWithMultiple()
|
||||
{
|
||||
$this->stimulusAttributes->addTarget('my-controller', 'myTarget');
|
||||
$this->assertSame('data-my-controller-target="myTarget"', (string) $this->stimulusAttributes);
|
||||
@@ -152,7 +152,7 @@ final class StimulusAttributesTest extends TestCase
|
||||
/**
|
||||
* @dataProvider provideAddComplexActionData
|
||||
*/
|
||||
public function testAddComplexAction(string $controllerName, string $actionName, ?string $eventName, string $expectedAction): void
|
||||
public function testAddComplexAction(string $controllerName, string $actionName, ?string $eventName, string $expectedAction)
|
||||
{
|
||||
$this->stimulusAttributes->addAction($controllerName, $actionName, $eventName);
|
||||
$attributesHtml = (string) $this->stimulusAttributes;
|
||||
|
||||
@@ -18,7 +18,7 @@ use Twig\Environment;
|
||||
|
||||
final class StimulusHelperTest extends TestCase
|
||||
{
|
||||
public function testCreateStimulusAttributes(): void
|
||||
public function testCreateStimulusAttributes()
|
||||
{
|
||||
$helper = new StimulusHelper($this->createMock(Environment::class));
|
||||
$attributes = $helper->createStimulusAttributes();
|
||||
|
||||
@@ -32,7 +32,7 @@ final class StimulusTwigExtensionTest extends TestCase
|
||||
/**
|
||||
* @dataProvider provideRenderStimulusController
|
||||
*/
|
||||
public function testRenderStimulusController(string $controllerName, array $controllerValues, array $controllerClasses, array $controllerOutlets, string $expectedString, array $expectedArray): void
|
||||
public function testRenderStimulusController(string $controllerName, array $controllerValues, array $controllerClasses, array $controllerOutlets, string $expectedString, array $expectedArray)
|
||||
{
|
||||
$extension = new StimulusTwigExtension(new StimulusHelper($this->twig));
|
||||
$dto = $extension->renderStimulusController($controllerName, $controllerValues, $controllerClasses, $controllerOutlets);
|
||||
@@ -130,7 +130,7 @@ final class StimulusTwigExtensionTest extends TestCase
|
||||
];
|
||||
}
|
||||
|
||||
public function testAppendStimulusController(): void
|
||||
public function testAppendStimulusController()
|
||||
{
|
||||
$extension = new StimulusTwigExtension(new StimulusHelper($this->twig));
|
||||
$dto = $extension->renderStimulusController('my-controller', ['myValue' => 'scalar-value']);
|
||||
@@ -143,7 +143,7 @@ final class StimulusTwigExtensionTest extends TestCase
|
||||
/**
|
||||
* @dataProvider provideRenderStimulusAction
|
||||
*/
|
||||
public function testRenderStimulusAction(string $controllerName, ?string $actionName, ?string $eventName, array $parameters, string $expectedString, array $expectedArray): void
|
||||
public function testRenderStimulusAction(string $controllerName, ?string $actionName, ?string $eventName, array $parameters, string $expectedString, array $expectedArray)
|
||||
{
|
||||
$extension = new StimulusTwigExtension(new StimulusHelper($this->twig));
|
||||
$dto = $extension->renderStimulusAction($controllerName, $actionName, $eventName, $parameters);
|
||||
@@ -208,7 +208,7 @@ final class StimulusTwigExtensionTest extends TestCase
|
||||
];
|
||||
}
|
||||
|
||||
public function testAppendStimulusAction(): void
|
||||
public function testAppendStimulusAction()
|
||||
{
|
||||
$extension = new StimulusTwigExtension(new StimulusHelper($this->twig));
|
||||
$dto = $extension->renderStimulusAction('my-controller', 'onClick', 'click');
|
||||
@@ -246,7 +246,7 @@ final class StimulusTwigExtensionTest extends TestCase
|
||||
];
|
||||
}
|
||||
|
||||
public function testAppendStimulusTarget(): void
|
||||
public function testAppendStimulusTarget()
|
||||
{
|
||||
$extension = new StimulusTwigExtension(new StimulusHelper($this->twig));
|
||||
$dto = $extension->renderStimulusTarget('my-controller', 'myTarget');
|
||||
|
||||
@@ -39,7 +39,7 @@ class UxControllersTwigRuntimeTest extends TestCase
|
||||
$assetMapper = $this->createMock(AssetMapperInterface::class);
|
||||
$assetMapper->expects($this->any())
|
||||
->method('getAsset')
|
||||
->willReturnCallback(function ($path) {
|
||||
->willReturnCallback(static function ($path) {
|
||||
if (str_starts_with($path, 'in/asset/mapper')) {
|
||||
return new MappedAsset(basename($path), publicPath: '/assets/mapper/'.basename($path));
|
||||
}
|
||||
|
||||
4
tests/fixtures/StimulusTestKernel.php
vendored
4
tests/fixtures/StimulusTestKernel.php
vendored
@@ -63,7 +63,9 @@ class StimulusTestKernel extends Kernel
|
||||
'importmap_path' => '%kernel.project_dir%/'.(class_exists(ImportMapConfigReader::class) ? 'importmap.php' : 'legacy/importmap.php'),
|
||||
],
|
||||
'test' => true,
|
||||
'handle_all_throwables' => true,
|
||||
...(self::VERSION_ID >= 60200 ? [
|
||||
'handle_all_throwables' => true,
|
||||
] : []),
|
||||
'php_errors' => ['log' => true],
|
||||
]);
|
||||
|
||||
|
||||
6
tests/fixtures/assets/more-controllers/excluded-controller.js
vendored
Normal file
6
tests/fixtures/assets/more-controllers/excluded-controller.js
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
// excluded-controller.js
|
||||
import { Controller } from '@hotwired/stimulus';
|
||||
|
||||
/* stimulusFetch: 'lazy' */
|
||||
export default class extends Controller {
|
||||
}
|
||||
7
tests/fixtures/assets/more-controllers/other-controller.ts
vendored
Normal file
7
tests/fixtures/assets/more-controllers/other-controller.ts
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
// other-controller.js
|
||||
// @ts-ignore
|
||||
import { Controller } from '@hotwired/stimulus';
|
||||
|
||||
/* stimulusFetch: 'lazy' */
|
||||
export default class extends Controller {
|
||||
}
|
||||
Reference in New Issue
Block a user