Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add functionality to remove element from dom #2192

Draft
wants to merge 3 commits into
base: 2.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 1 addition & 8 deletions src/Autocomplete/assets/dist/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,12 @@ 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.
***************************************************************************** */
/* global Reflect, Promise, SuppressedError, Symbol */


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);
}

typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
var e = new Error(message);
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
};
}

var _default_1_instances, _default_1_getCommonConfig, _default_1_createAutocomplete, _default_1_createAutocompleteWithHtmlContents, _default_1_createAutocompleteWithRemoteData, _default_1_stripTags, _default_1_mergeObjects, _default_1_createTomSelect;
class default_1 extends Controller {
Expand Down
11 changes: 8 additions & 3 deletions src/LiveComponent/assets/dist/live_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -1667,7 +1667,7 @@ class ElementChanges {
element.classList.remove(...this.removedClasses);
this.styleChanges.getChangedItems().forEach((change) => {
element.style.setProperty(change.name, change.value);
return;

});
this.styleChanges.getRemovedItems().forEach((styleName) => {
element.style.removeProperty(styleName);
Expand Down Expand Up @@ -2040,7 +2040,8 @@ class Component {
}
const headers = backendResponse.response.headers;
if (!headers.get('Content-Type')?.includes('application/vnd.live-component+html') &&
!headers.get('X-Live-Redirect')) {
!headers.get('X-Live-Redirect') &&
!headers.get('X-Live-Delete')) {
const controls = { displayError: true };
this.valueStore.pushPendingPropsBackToDirty();
this.hooks.triggerHook('response:error', backendResponse, controls);
Expand Down Expand Up @@ -2079,6 +2080,10 @@ class Component {
}
return;
}
if (backendResponse.response.headers.get('X-Live-Delete')) {
this.element.remove();
return;
}
this.hooks.triggerHook('loading.state:finished', this.element);
const modifiedModelValues = {};
Object.keys(this.valueStore.getDirtyProps()).forEach((modelName) => {
Expand Down Expand Up @@ -2994,7 +2999,7 @@ class LiveControllerDefault extends Controller {
});
validModifiers.set('self', () => {
if (event.target !== event.currentTarget) {
return;

}
});
validModifiers.set('debounce', (modifier) => {
Expand Down
9 changes: 8 additions & 1 deletion src/LiveComponent/assets/src/Component/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,8 @@ export default class Component {
const headers = backendResponse.response.headers;
if (
!headers.get('Content-Type')?.includes('application/vnd.live-component+html') &&
!headers.get('X-Live-Redirect')
!headers.get('X-Live-Redirect') &&
!headers.get('X-Live-Delete')
) {
const controls = { displayError: true };
this.valueStore.pushPendingPropsBackToDirty();
Expand Down Expand Up @@ -366,6 +367,12 @@ export default class Component {

return;
}
if (backendResponse.response.headers.get('X-Live-Delete')) {
// action returned a delete element from the DOM
this.element.remove();

return;
}

// remove the loading behavior now so that when we morphdom
// "diffs" the elements, any loading differences will not cause
Expand Down
Loading