Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
more examples
  • Loading branch information
dunglas committed Jul 20, 2022
commit 47aca25aa4007d7ec5a13e73c4f723ead4cddfea
38 changes: 19 additions & 19 deletions src/Autocomplete/assets/dist/controller.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import { Controller } from '@hotwired/stimulus';
import TomSelect from 'tom-select';

/******************************************************************************
Copyright (c) Microsoft Corporation.

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */

function __classPrivateFieldGet(receiver, state, kind, f) {
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
/******************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
function __classPrivateFieldGet(receiver, state, kind, f) {
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
}

var _instances, _getCommonConfig, _createAutocomplete, _createAutocompleteWithHtmlContents, _createAutocompleteWithRemoteData, _stripTags, _mergeObjects, _createTomSelect, _dispatchEvent;
Expand Down
2 changes: 1 addition & 1 deletion src/Collection/Tests/app/Form/TeamType.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class TeamType extends AbstractType
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('name')
->add('name', null, ['attr' => ['data-controller' => 'test']])
->add('players', CollectionType::class, [
'entry_type' => PlayerType::class,
'allow_add' => true,
Expand Down
9 changes: 6 additions & 3 deletions src/Collection/Tests/app/assets/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@
* file that was distributed with this source code.
*/

import { Application } from "@hotwired/stimulus";
import { Application, Controller as BaseController } from "@hotwired/stimulus";
import Controller from "@symfony/ux-collection/dist/controller.js";

const application = Application.start();
application.register("symfony--ux-collection--collection", Controller);
application.register("collection", Controller);

application.register("test", class test extends BaseController {
connect() {
console.log('Yolo', this.element);
}
});
console.log('test app initialized');
8 changes: 5 additions & 3 deletions src/Collection/Tests/app/templates/basic_form.html.twig
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{% extends 'base.html.twig' %}

{% block body %}
<div data-controller="symfony--ux-collection--collection" >
{{ form(form) }}
</div>
{{ form_start(form, {'attr': {
'data-controller': 'symfony--ux-collection--collection'
}}) }}
{{ form(form) }}
{{ form_end(form) }}
{% endblock %}
22 changes: 13 additions & 9 deletions src/Collection/Tests/app/templates/template_form.html.twig
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
{% extends 'base.html.twig' %}

{% block body %}
<template id="addButton">
<button type="button">My add button</button>
</template>
<template id="addButton">
<button type="button">My add button</button>
</template>

<template id="deleteButton">
<button type="button">My delete button</button>
</template>
<template id="deleteButton">
<button type="button">My delete button</button>
</template>

<div data-controller="symfony--ux-collection--collection" data-symfony--ux-collection--collection-add-button-template-id-value="addButton" data-symfony--ux-collection--collection-delete-button-template-id-value="deleteButton">
{{ form(form) }}
</div>
{{ form_start(form, {'attr': {
'data-controller': 'symfony--ux-collection--collection',
'data-symfony--ux-collection--collection-add-button-template-id-value': 'addButton',
'data-symfony--ux-collection--collection-delete-button-template-id-value': 'deleteButton',
}}) }}
{{ form(form) }}
{{ form_end(form) }}
{% endblock %}
85 changes: 47 additions & 38 deletions src/LiveComponent/assets/dist/live_controller.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
import { Controller } from '@hotwired/stimulus';

/******************************************************************************
Copyright (c) Microsoft Corporation.

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */

function __classPrivateFieldGet(receiver, state, kind, f) {
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
}

function __classPrivateFieldSet(receiver, state, value, kind, f) {
if (kind === "m") throw new TypeError("Private method is not writable");
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
/******************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
function __classPrivateFieldGet(receiver, state, kind, f) {
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
}
function __classPrivateFieldSet(receiver, state, value, kind, f) {
if (kind === "m") throw new TypeError("Private method is not writable");
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
}

var DOCUMENT_FRAGMENT_NODE = 11;
Expand Down Expand Up @@ -1084,8 +1084,8 @@ function getModelDirectiveFromInput(element, throwOnMissing = true) {
}
if (element.getAttribute('name')) {
const formElement = element.closest('form');
if (formElement && formElement.dataset.model) {
const directives = parseDirectives(formElement.dataset.model);
if (formElement && ('model' in formElement.dataset)) {
const directives = parseDirectives(formElement.dataset.model || '*');
const directive = directives[0];
if (directive.args.length > 0 || directive.named.length > 0) {
throw new Error(`The data-model="${formElement.dataset.model}" format is invalid: it does not support passing arguments to the model.`);
Expand Down Expand Up @@ -1222,9 +1222,7 @@ class default_1 extends Controller {
if (!(this.element instanceof HTMLElement)) {
throw new Error('Invalid Element Type');
}
if (this.element.dataset.poll !== undefined) {
this._initiatePolling(this.element.dataset.poll);
}
this._initiatePolling();
window.addEventListener('beforeunload', this.markAsWindowUnloaded);
this._startAttributesMutationObserver();
this.element.addEventListener('live:update-model', this.handleUpdateModelEvent);
Expand All @@ -1234,9 +1232,7 @@ class default_1 extends Controller {
this._dispatchEvent('live:connect', { controller: this });
}
disconnect() {
this.pollingIntervals.forEach((interval) => {
clearInterval(interval);
});
this._stopAllPolling();
window.removeEventListener('beforeunload', this.markAsWindowUnloaded);
this.element.removeEventListener('live:update-model', this.handleUpdateModelEvent);
this.element.removeEventListener('input', this.handleInputEvent);
Expand Down Expand Up @@ -1665,7 +1661,12 @@ class default_1 extends Controller {
}
this._updateModelFromElement(target, 'change');
}
_initiatePolling(rawPollConfig) {
_initiatePolling() {
this._stopAllPolling();
if (this.element.dataset.poll === undefined) {
return;
}
const rawPollConfig = this.element.dataset.poll;
const directives = parseDirectives(rawPollConfig || '$render');
directives.forEach((directive) => {
let duration = 2000;
Expand Down Expand Up @@ -1790,9 +1791,12 @@ class default_1 extends Controller {
const element = this.element;
this.mutationObserver = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
if (mutation.type === 'attributes' && !element.dataset.originalData) {
this.originalDataJSON = this.valueStore.asJson();
this._exposeOriginalData();
if (mutation.type === 'attributes') {
if (!element.dataset.originalData) {
this.originalDataJSON = this.valueStore.asJson();
this._exposeOriginalData();
}
this._initiatePolling();
}
});
});
Expand All @@ -1803,6 +1807,11 @@ class default_1 extends Controller {
getDefaultDebounce() {
return this.hasDebounceValue ? this.debounceValue : DEFAULT_DEBOUNCE;
}
_stopAllPolling() {
this.pollingIntervals.forEach((interval) => {
clearInterval(interval);
});
}
}
default_1.values = {
url: String,
Expand Down