improve ui
This commit is contained in:
Vendored
+62
-29
@@ -49,21 +49,17 @@
|
|||||||
var v4_default = v4;
|
var v4_default = v4;
|
||||||
|
|
||||||
// node_modules/bloatless-react/index.ts
|
// node_modules/bloatless-react/index.ts
|
||||||
var UUID = class {
|
function UUID() {
|
||||||
value;
|
return v4_default();
|
||||||
constructor() {
|
}
|
||||||
this.value = v4_default();
|
|
||||||
}
|
|
||||||
toString() {
|
|
||||||
return this.value;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
var State = class {
|
var State = class {
|
||||||
_value;
|
_value;
|
||||||
_bindings = /* @__PURE__ */ new Set();
|
_bindings = /* @__PURE__ */ new Set();
|
||||||
|
// init
|
||||||
constructor(initialValue) {
|
constructor(initialValue) {
|
||||||
this._value = initialValue;
|
this._value = initialValue;
|
||||||
}
|
}
|
||||||
|
// value
|
||||||
get value() {
|
get value() {
|
||||||
return this._value;
|
return this._value;
|
||||||
}
|
}
|
||||||
@@ -72,6 +68,7 @@
|
|||||||
this._value = newValue;
|
this._value = newValue;
|
||||||
this.callSubscriptions();
|
this.callSubscriptions();
|
||||||
}
|
}
|
||||||
|
// subscriptions
|
||||||
callSubscriptions() {
|
callSubscriptions() {
|
||||||
this._bindings.forEach((fn) => fn(this._value));
|
this._bindings.forEach((fn) => fn(this._value));
|
||||||
}
|
}
|
||||||
@@ -79,33 +76,52 @@
|
|||||||
this._bindings.add(fn);
|
this._bindings.add(fn);
|
||||||
fn(this._value);
|
fn(this._value);
|
||||||
}
|
}
|
||||||
|
// stringify
|
||||||
|
toString() {
|
||||||
|
return JSON.stringify(this._value);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
var ListState = class extends State {
|
var ListState = class extends State {
|
||||||
additionHandlers = /* @__PURE__ */ new Set();
|
additionHandlers = /* @__PURE__ */ new Set();
|
||||||
removalHandlers = /* @__PURE__ */ new Map();
|
removalHandlers = /* @__PURE__ */ new Map();
|
||||||
constructor() {
|
// init
|
||||||
super(/* @__PURE__ */ new Set());
|
constructor(initialItems) {
|
||||||
|
super(new Set(initialItems));
|
||||||
}
|
}
|
||||||
|
// list
|
||||||
add(...items) {
|
add(...items) {
|
||||||
items.forEach((item) => {
|
items.forEach((item) => {
|
||||||
this.value.add(item);
|
this.value.add(item);
|
||||||
this.additionHandlers.forEach((handler) => handler(item));
|
this.additionHandlers.forEach((handler) => handler(item));
|
||||||
});
|
});
|
||||||
|
this.callSubscriptions();
|
||||||
}
|
}
|
||||||
remove(...items) {
|
remove(...items) {
|
||||||
items.forEach((item) => {
|
items.forEach((item) => {
|
||||||
this.value.delete(item);
|
this.value.delete(item);
|
||||||
const uuid = item.uuid;
|
const id = item.id;
|
||||||
if (!this.removalHandlers.has(uuid)) return;
|
if (!this.removalHandlers.has(id)) return;
|
||||||
this.removalHandlers.get(uuid)(item);
|
this.removalHandlers.get(id)(item);
|
||||||
this.removalHandlers.delete(uuid);
|
this.removalHandlers.delete(id);
|
||||||
});
|
});
|
||||||
|
this.callSubscriptions();
|
||||||
}
|
}
|
||||||
|
clear() {
|
||||||
|
this.remove(...this.value.values());
|
||||||
|
}
|
||||||
|
// handlers
|
||||||
handleAddition(handler) {
|
handleAddition(handler) {
|
||||||
this.additionHandlers.add(handler);
|
this.additionHandlers.add(handler);
|
||||||
|
[...this.value.values()].forEach(handler);
|
||||||
}
|
}
|
||||||
handleRemoval(item, handler) {
|
handleRemoval(item, handler) {
|
||||||
this.removalHandlers.set(item.uuid, handler);
|
this.removalHandlers.set(item.id, handler);
|
||||||
|
}
|
||||||
|
// stringification
|
||||||
|
toString() {
|
||||||
|
const array = [...this.value];
|
||||||
|
const json = JSON.stringify(array);
|
||||||
|
return json;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
function createProxyState(statesToSubscibe, fn) {
|
function createProxyState(statesToSubscibe, fn) {
|
||||||
@@ -139,15 +155,21 @@
|
|||||||
}
|
}
|
||||||
case "subscribe": {
|
case "subscribe": {
|
||||||
if (directiveValue == "children") {
|
if (directiveValue == "children") {
|
||||||
const [listState, toElement] = value;
|
element.style.scrollBehavior = "smooth";
|
||||||
listState.handleAddition((newItem) => {
|
try {
|
||||||
const child = toElement(newItem, listState);
|
const [listState, toElement] = value;
|
||||||
listState.handleRemoval(
|
listState.handleAddition((newItem) => {
|
||||||
newItem,
|
const child = toElement(newItem, listState);
|
||||||
() => child.remove()
|
listState.handleRemoval(
|
||||||
);
|
newItem,
|
||||||
element.append(child);
|
() => child.remove()
|
||||||
});
|
);
|
||||||
|
element.append(child);
|
||||||
|
child.scrollIntoView();
|
||||||
|
});
|
||||||
|
} catch {
|
||||||
|
throw `error: cannot process subscribe:children directive because ListItemConverter is not defined. Usage: "subscribe:children={[list, converter]}"; you can find a more detailed example in the documentation`;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
const state = value;
|
const state = value;
|
||||||
state.subscribe(
|
state.subscribe(
|
||||||
@@ -168,9 +190,20 @@
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "toggle": {
|
case "toggle": {
|
||||||
|
if (value.subscribe) {
|
||||||
|
const state = value;
|
||||||
|
state.subscribe(
|
||||||
|
(newValue) => element.toggleAttribute(directiveValue, newValue)
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
element.toggleAttribute(directiveValue, value);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "set": {
|
||||||
const state = value;
|
const state = value;
|
||||||
state.subscribe(
|
state.subscribe(
|
||||||
(newValue) => element.toggleAttribute(directiveValue, newValue)
|
(newValue) => element.setAttribute(directiveValue, newValue)
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -182,7 +215,7 @@
|
|||||||
return element;
|
return element;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ../node_modules/udn-frontend/index.ts
|
// node_modules/udn-frontend/index.ts
|
||||||
var UDNFrontend = class {
|
var UDNFrontend = class {
|
||||||
ws;
|
ws;
|
||||||
// handlers
|
// handlers
|
||||||
@@ -267,7 +300,7 @@
|
|||||||
es: {
|
es: {
|
||||||
channel: "Canal",
|
channel: "Canal",
|
||||||
channel_placeholder: "mi-canal",
|
channel_placeholder: "mi-canal",
|
||||||
disconnected: "Sin conneci\xF3n",
|
disconnected: "Sin coneci\xF3n",
|
||||||
reconnecting: "Conectando...",
|
reconnecting: "Conectando...",
|
||||||
info: "Info",
|
info: "Info",
|
||||||
message: "Mensaje",
|
message: "Mensaje",
|
||||||
@@ -415,7 +448,7 @@
|
|||||||
"toggle:disabled": isMessageEmpty
|
"toggle:disabled": isMessageEmpty
|
||||||
},
|
},
|
||||||
getText("send"),
|
getText("send"),
|
||||||
/* @__PURE__ */ createElement("span", { class: "icon" }, "arrow_forward")
|
/* @__PURE__ */ createElement("span", { class: "icon" }, "send")
|
||||||
))));
|
))));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ export function MainScreen() {
|
|||||||
</button>
|
</button>
|
||||||
<button class="primary width-50" on:click={subscribe}>
|
<button class="primary width-50" on:click={subscribe}>
|
||||||
{getText("subscribe")}
|
{getText("subscribe")}
|
||||||
<span class="icon">check</span>
|
<span class="icon">arrow_forward</span>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user