Skip to content

Commit 4a1ec50

Browse files
committed
remove UrlUtils
1 parent 19666f8 commit 4a1ec50

File tree

5 files changed

+6
-424
lines changed

5 files changed

+6
-424
lines changed

src/LiveComponent/assets/dist/live_controller.js

Lines changed: 1 addition & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -1797,110 +1797,6 @@ function executeMorphdom(rootFromElement, rootToElement, modifiedFieldElements,
17971797
});
17981798
}
17991799

1800-
function isValueEmpty(value) {
1801-
if (null === value || value === '' || undefined === value || (Array.isArray(value) && value.length === 0)) {
1802-
return true;
1803-
}
1804-
if (typeof value !== 'object') {
1805-
return false;
1806-
}
1807-
for (const key of Object.keys(value)) {
1808-
if (!isValueEmpty(value[key])) {
1809-
return false;
1810-
}
1811-
}
1812-
return true;
1813-
}
1814-
function toQueryString(data) {
1815-
const buildQueryStringEntries = (data, entries = {}, baseKey = '') => {
1816-
Object.entries(data).forEach(([iKey, iValue]) => {
1817-
const key = baseKey === '' ? iKey : `${baseKey}[${iKey}]`;
1818-
if ('' === baseKey && isValueEmpty(iValue)) {
1819-
entries[key] = '';
1820-
}
1821-
else if (null !== iValue) {
1822-
if (typeof iValue === 'object') {
1823-
entries = { ...entries, ...buildQueryStringEntries(iValue, entries, key) };
1824-
}
1825-
else {
1826-
entries[key] = encodeURIComponent(iValue)
1827-
.replace(/%20/g, '+')
1828-
.replace(/%2C/g, ',');
1829-
}
1830-
}
1831-
});
1832-
return entries;
1833-
};
1834-
const entries = buildQueryStringEntries(data);
1835-
return Object.entries(entries)
1836-
.map(([key, value]) => `${key}=${value}`)
1837-
.join('&');
1838-
}
1839-
function fromQueryString(search) {
1840-
search = search.replace('?', '');
1841-
if (search === '')
1842-
return {};
1843-
const insertDotNotatedValueIntoData = (key, value, data) => {
1844-
const [first, second, ...rest] = key.split('.');
1845-
if (!second) {
1846-
data[key] = value;
1847-
return value;
1848-
}
1849-
if (data[first] === undefined) {
1850-
data[first] = Number.isNaN(Number.parseInt(second)) ? {} : [];
1851-
}
1852-
insertDotNotatedValueIntoData([second, ...rest].join('.'), value, data[first]);
1853-
};
1854-
const entries = search.split('&').map((i) => i.split('='));
1855-
const data = {};
1856-
entries.forEach(([key, value]) => {
1857-
value = decodeURIComponent(value.replace(/\+/g, '%20'));
1858-
if (!key.includes('[')) {
1859-
data[key] = value;
1860-
}
1861-
else {
1862-
if ('' === value)
1863-
return;
1864-
const dotNotatedKey = key.replace(/\[/g, '.').replace(/]/g, '');
1865-
insertDotNotatedValueIntoData(dotNotatedKey, value, data);
1866-
}
1867-
});
1868-
return data;
1869-
}
1870-
class UrlUtils extends URL {
1871-
has(key) {
1872-
const data = this.getData();
1873-
return Object.keys(data).includes(key);
1874-
}
1875-
set(key, value) {
1876-
const data = this.getData();
1877-
data[key] = value;
1878-
this.setData(data);
1879-
}
1880-
get(key) {
1881-
return this.getData()[key];
1882-
}
1883-
remove(key) {
1884-
const data = this.getData();
1885-
delete data[key];
1886-
this.setData(data);
1887-
}
1888-
getData() {
1889-
if (!this.search) {
1890-
return {};
1891-
}
1892-
return fromQueryString(this.search);
1893-
}
1894-
setData(data) {
1895-
this.search = toQueryString(data);
1896-
}
1897-
}
1898-
class HistoryStrategy {
1899-
static replace(url) {
1900-
history.replaceState(history.state, '', url);
1901-
}
1902-
}
1903-
19041800
class UnsyncedInputsTracker {
19051801
constructor(component, modelElementResolver) {
19061802
this.elementEventListeners = [
@@ -2250,7 +2146,7 @@ class Component {
22502146
this.processRerender(html, backendResponse);
22512147
const liveUrl = await backendResponse.getLiveUrl();
22522148
if (liveUrl) {
2253-
HistoryStrategy.replace(new UrlUtils(liveUrl + window.location.hash, window.location.origin));
2149+
history.replaceState(history.state, '', new URL(liveUrl + window.location.hash, window.location.origin));
22542150
}
22552151
this.backendRequest = null;
22562152
thisPromiseResolve(backendResponse);

src/LiveComponent/assets/dist/url_utils.d.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/LiveComponent/assets/src/Component/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import ExternalMutationTracker from '../Rendering/ExternalMutationTracker';
77
import { elementBelongsToThisComponent, getValueFromElement, htmlToElement } from '../dom_utils';
88
import { executeMorphdom } from '../morphdom';
99
import { normalizeModelName } from '../string_utils';
10-
import { HistoryStrategy, UrlUtils } from "../url_utils";
1110
import type { ElementDriver } from './ElementDriver';
1211
import UnsyncedInputsTracker from './UnsyncedInputsTracker';
1312
import ValueStore from './ValueStore';
@@ -331,7 +330,11 @@ export default class Component {
331330
this.processRerender(html, backendResponse);
332331
const liveUrl = await backendResponse.getLiveUrl();
333332
if (liveUrl) {
334-
HistoryStrategy.replace(new UrlUtils(liveUrl + window.location.hash, window.location.origin));
333+
history.replaceState(
334+
history.state,
335+
'',
336+
new URL(liveUrl + window.location.hash, window.location.origin)
337+
);
335338
}
336339

337340
// finally resolve this promise

src/LiveComponent/assets/src/url_utils.ts

Lines changed: 0 additions & 172 deletions
This file was deleted.

0 commit comments

Comments
 (0)