Skip to content

Commit

Permalink
Copy over everything from symfony/ux#2288
Browse files Browse the repository at this point in the history
  • Loading branch information
Flo committed Jan 13, 2025
0 parents commit 92a770e
Show file tree
Hide file tree
Showing 38 changed files with 1,368 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .gitattributes
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
5 changes: 5 additions & 0 deletions .gitignore
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
3 changes: 3 additions & 0 deletions .symfony.bundle.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
branches: ["2.x"]
maintained_branches: ["2.x"]
doc_dir: "doc"
23 changes: 23 additions & 0 deletions CHANGELOG.md
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
19 changes: 19 additions & 0 deletions LICENSE
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.
19 changes: 19 additions & 0 deletions README.md
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)

5 changes: 5 additions & 0 deletions assets/dist/components.d.ts
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;
3 changes: 3 additions & 0 deletions assets/dist/components.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const components = {};

export { components };
9 changes: 9 additions & 0 deletions assets/dist/loader.d.ts
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;
14 changes: 14 additions & 0 deletions assets/dist/loader.js
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 };
8 changes: 8 additions & 0 deletions assets/dist/register_controller.d.ts
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;
18 changes: 18 additions & 0 deletions assets/dist/register_controller.js
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 };
21 changes: 21 additions & 0 deletions assets/dist/render_controller.d.ts
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;
}
47 changes: 47 additions & 0 deletions assets/dist/render_controller.js
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 };
31 changes: 31 additions & 0 deletions assets/package.json
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"
}
}
17 changes: 17 additions & 0 deletions assets/src/components.ts
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 = {};
34 changes: 34 additions & 0 deletions assets/src/loader.ts
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;
};
}
40 changes: 40 additions & 0 deletions assets/src/register_controller.ts
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;
};
}
Loading

0 comments on commit 92a770e

Please sign in to comment.