-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Copy over everything from symfony/ux#2288
- Loading branch information
Flo
committed
Jan 13, 2025
0 parents
commit 92a770e
Showing
38 changed files
with
1,368 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/.gitattributes export-ignore | ||
/.gitignore export-ignore | ||
/.symfony.bundle.yaml export-ignore | ||
/assets/src export-ignore | ||
/assets/test export-ignore | ||
/assets/vitest.config.js export-ignore | ||
/doc export-ignore | ||
/phpunit.xml.dist export-ignore | ||
/tests export-ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/assets/node_modules/ | ||
/vendor/ | ||
/composer.lock | ||
/phpunit.xml | ||
/.phpunit.result.cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
branches: ["2.x"] | ||
maintained_branches: ["2.x"] | ||
doc_dir: "doc" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# CHANGELOG | ||
|
||
## 2.13.2 | ||
|
||
- Revert "Change JavaScript package to `type: module`" | ||
|
||
## 2.13.0 | ||
|
||
- Add support for Svelte 4. | ||
- Add Symfony 7 support. | ||
- Change JavaScript package to `type: module` | ||
|
||
## 2.9.0 | ||
|
||
- Add support for symfony/asset-mapper | ||
|
||
- Replace `symfony/webpack-encore-bundle` by `symfony/stimulus-bundle` in dependencies | ||
|
||
- Minimum PHP version is now 8.1 | ||
|
||
## 2.8.0 | ||
|
||
- Introduce the package |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Copyright (c) 2021-present Fabien Potencier | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is furnished | ||
to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Fork by ChqThomas | ||
|
||
https://github.com/symfony/ux/pull/2288 | ||
|
||
# Symfony UX Svelte | ||
|
||
Symfony UX Svelte integrates [Svelte](https://svelte.dev/) into Symfony applications. | ||
It provides tools to render Svelte 3 components from Twig. | ||
|
||
**This repository is a READ-ONLY sub-tree split**. See | ||
https://github.com/symfony/ux to create issues or submit pull requests. | ||
|
||
## Resources | ||
|
||
- [Documentation](https://symfony.com/bundles/ux-svelte/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) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import type { SvelteComponent } from 'svelte'; | ||
export interface ComponentCollection { | ||
[key: string]: SvelteComponent; | ||
} | ||
export declare const components: ComponentCollection; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const components = {}; | ||
|
||
export { components }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import type { SvelteComponent } from 'svelte'; | ||
import { type ComponentCollection } from './components.js'; | ||
declare global { | ||
function resolveSvelteComponent(name: string): typeof SvelteComponent<any>; | ||
interface Window { | ||
resolveSvelteComponent(name: string): typeof SvelteComponent<any>; | ||
} | ||
} | ||
export declare function registerSvelteControllerComponents(svelteComponents?: ComponentCollection): void; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { components } from './components.js'; | ||
|
||
function registerSvelteControllerComponents(svelteComponents = components) { | ||
window.resolveSvelteComponent = (name) => { | ||
const component = svelteComponents[name]; | ||
if (typeof component === 'undefined') { | ||
const possibleValues = Object.keys(svelteComponents).length > 0 ? Object.keys(svelteComponents).join(', ') : 'none'; | ||
throw new Error(`Svelte controller "${name}" does not exist. Possible values: ${possibleValues}`); | ||
} | ||
return component; | ||
}; | ||
} | ||
|
||
export { registerSvelteControllerComponents }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import type { SvelteComponent } from 'svelte'; | ||
declare global { | ||
function resolveSvelteComponent(name: string): typeof SvelteComponent<any>; | ||
interface Window { | ||
resolveSvelteComponent(name: string): typeof SvelteComponent<any>; | ||
} | ||
} | ||
export declare function registerSvelteControllerComponents(context: __WebpackModuleApi.RequireContext): void; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
function registerSvelteControllerComponents(context) { | ||
const svelteControllers = {}; | ||
const importAllSvelteComponents = (r) => { | ||
r.keys().forEach((key) => { | ||
svelteControllers[key] = r(key).default; | ||
}); | ||
}; | ||
importAllSvelteComponents(context); | ||
window.resolveSvelteComponent = (name) => { | ||
const component = svelteControllers[`./${name}.svelte`]; | ||
if (typeof component === 'undefined') { | ||
throw new Error(`Svelte controller "${name}" does not exist`); | ||
} | ||
return component; | ||
}; | ||
} | ||
|
||
export { registerSvelteControllerComponents }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Controller } from '@hotwired/stimulus'; | ||
import type { SvelteComponent } from 'svelte'; | ||
export default class extends Controller<Element & { | ||
root?: SvelteComponent; | ||
}> { | ||
private app; | ||
readonly componentValue: string; | ||
private props; | ||
private intro; | ||
readonly propsValue: Record<string, unknown> | null | undefined; | ||
readonly introValue: boolean | undefined; | ||
static values: { | ||
component: StringConstructor; | ||
props: ObjectConstructor; | ||
intro: BooleanConstructor; | ||
}; | ||
connect(): void; | ||
disconnect(): void; | ||
_destroyIfExists(): void; | ||
private dispatchEvent; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { Controller } from '@hotwired/stimulus'; | ||
|
||
class default_1 extends Controller { | ||
connect() { | ||
this.element.innerHTML = ''; | ||
this.props = this.propsValue ?? undefined; | ||
this.intro = this.introValue ?? undefined; | ||
this.dispatchEvent('connect'); | ||
const Component = window.resolveSvelteComponent(this.componentValue); | ||
this._destroyIfExists(); | ||
this.app = new Component({ | ||
target: this.element, | ||
props: this.props, | ||
intro: this.intro, | ||
}); | ||
this.element.root = this.app; | ||
this.dispatchEvent('mount', { | ||
component: Component, | ||
}); | ||
} | ||
disconnect() { | ||
this._destroyIfExists(); | ||
this.dispatchEvent('unmount'); | ||
} | ||
_destroyIfExists() { | ||
if (this.element.root !== undefined) { | ||
this.element.root.$destroy(); | ||
delete this.element.root; | ||
} | ||
} | ||
dispatchEvent(name, payload = {}) { | ||
const detail = { | ||
componentName: this.componentValue, | ||
props: this.props, | ||
intro: this.intro, | ||
...payload, | ||
}; | ||
this.dispatch(name, { detail, prefix: 'svelte' }); | ||
} | ||
} | ||
default_1.values = { | ||
component: String, | ||
props: Object, | ||
intro: Boolean, | ||
}; | ||
|
||
export { default_1 as default }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"name": "@symfony/ux-svelte", | ||
"description": "Integration of Svelte in Symfony", | ||
"main": "dist/register_controller.js", | ||
"version": "1.0.0", | ||
"license": "MIT", | ||
"symfony": { | ||
"controllers": { | ||
"svelte": { | ||
"main": "dist/render_controller.js", | ||
"fetch": "eager", | ||
"enabled": true | ||
} | ||
}, | ||
"importmap": { | ||
"@hotwired/stimulus": "^3.0.0", | ||
"svelte/internal": "^3.0", | ||
"@symfony/ux-svelte": "path:%PACKAGE%/dist/loader.js" | ||
} | ||
}, | ||
"peerDependencies": { | ||
"@hotwired/stimulus": "^3.0.0", | ||
"svelte": "^3.0 || ^4.0" | ||
}, | ||
"devDependencies": { | ||
"@hotwired/stimulus": "^3.0.0", | ||
"@sveltejs/vite-plugin-svelte": "^2.4.6", | ||
"@types/webpack-env": "^1.16", | ||
"svelte": "^3.0 || ^4.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
// This file is dynamically rewritten by ux-svelte + AssetMapper. | ||
import type { SvelteComponent } from 'svelte'; | ||
|
||
export interface ComponentCollection { | ||
[key: string]: SvelteComponent; | ||
} | ||
|
||
export const components: ComponentCollection = {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
import type { SvelteComponent } from 'svelte'; | ||
import { type ComponentCollection, components } from './components.js'; | ||
|
||
declare global { | ||
function resolveSvelteComponent(name: string): typeof SvelteComponent<any>; | ||
|
||
interface Window { | ||
resolveSvelteComponent(name: string): typeof SvelteComponent<any>; | ||
} | ||
} | ||
|
||
export function registerSvelteControllerComponents(svelteComponents: ComponentCollection = components): void { | ||
// Expose a global Svelte loader to allow rendering from the Stimulus controller | ||
(window as any).resolveSvelteComponent = (name: string): SvelteComponent => { | ||
const component = svelteComponents[name]; | ||
if (typeof component === 'undefined') { | ||
const possibleValues: string = | ||
Object.keys(svelteComponents).length > 0 ? Object.keys(svelteComponents).join(', ') : 'none'; | ||
|
||
throw new Error(`Svelte controller "${name}" does not exist. Possible values: ${possibleValues}`); | ||
} | ||
|
||
return component; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
import type { SvelteComponent } from 'svelte'; | ||
|
||
declare global { | ||
function resolveSvelteComponent(name: string): typeof SvelteComponent<any>; | ||
|
||
interface Window { | ||
resolveSvelteComponent(name: string): typeof SvelteComponent<any>; | ||
} | ||
} | ||
|
||
export function registerSvelteControllerComponents(context: __WebpackModuleApi.RequireContext) { | ||
const svelteControllers: { [key: string]: object } = {}; | ||
|
||
const importAllSvelteComponents = (r: __WebpackModuleApi.RequireContext) => { | ||
r.keys().forEach((key) => { | ||
svelteControllers[key] = r(key).default; | ||
}); | ||
}; | ||
|
||
importAllSvelteComponents(context); | ||
|
||
// Expose a global Svelte loader to allow rendering from the Stimulus controller | ||
(window as any).resolveSvelteComponent = (name: string): object => { | ||
const component = svelteControllers[`./${name}.svelte`]; | ||
if (typeof component === 'undefined') { | ||
throw new Error(`Svelte controller "${name}" does not exist`); | ||
} | ||
|
||
return component; | ||
}; | ||
} |
Oops, something went wrong.