Skip to content

Commit

Permalink
Merge branch 'b-textinput-prop' - add .prop to <b-textinput/>
Browse files Browse the repository at this point in the history
* b-textinput-prop:
  ui/b/propinput.js: use <b-textinput .prop=${prop} />
  ui/b/objecteditor.js: use <b-textinput .prop=${prop} />
  ui/b/textinput.js: move to directly operating on .prop
  ase/project.cc: add project.default_license preference

Signed-off-by: Tim Janik <[email protected]>
  • Loading branch information
tim-janik committed Feb 12, 2024
2 parents ab3b8da + bdd15b7 commit af7da4a
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 12 deletions.
8 changes: 8 additions & 0 deletions ase/project.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@

namespace Ase {

static Preference synth_latency_pref =
Preference ({
"project.default_license", _("Default License"), "",
"CC-BY-SA-4.0 - https://creativecommons.org/licenses/by-sa/4.0/legalcode",
"",
{}, STANDARD, {
String ("descr=") + _("Default LICENSE to apply in the project properties."), } });

static std::vector<ProjectImplP> &all_projects = *new std::vector<ProjectImplP>();

// == Project ==
Expand Down
3 changes: 1 addition & 2 deletions ui/b/objecteditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ const NUMBER_HTML = (t, prop) => html`
></b-numberinput>`;
const TEXT_HTML = (t, prop) => html`
<b-textinput class=${'b-objecteditor--' + prop.ident_}
value=${prop.value_.val} @valuechange=${e => prop.apply_ (e.target.value)}
></b-textinput>`;
.prop=${prop} ></b-textinput>`;
const SWITCH_HTML = (t, prop) => html`
<b-switchinput class=${'b-objecteditor--' + prop.ident_}
?value=${prop.value_.val} @valuechange=${e => prop.apply_ (e.target.value)}
Expand Down
3 changes: 1 addition & 2 deletions ui/b/propinput.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ const HTML = (t, d) => [
label=${t.prop.label_} title=${t.prop.title_} .choices=${t.prop.value_.choices} ></b-choiceinput>`,
t.istype ('text') &&
html`
<b-textinput class=${t.classes + " b-propinput-text"} ?disabled=${t.readonly}
value=${t.prop.value_.val} @valuechange=${e => t.prop.apply_ (e.target.value)}
<b-textinput class=${t.classes + " b-propinput-text"} ?disabled=${t.readonly} .prop=${t.prop}
label=${t.prop.label_} title=${t.prop.title_} ></b-textinput>`,
!t.labeled || !t.prop.nick_ ? '' :
html`
Expand Down
32 changes: 24 additions & 8 deletions ui/b/textinput.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,27 +45,43 @@ class BTextInput extends LitComponent {
render() { return HTML (this); }
input_element = null;
static properties = {
value: { type: String, },
prop: { type: Object, reflect: true },
placeholder: { type: String, },
readonly: { type: Boolean, },
};
constructor() {
constructor()
{
super();
this.value = '';
this.placeholder = '';
this.readonly = false;
}
updated() {
// debug ("textinput.js: value:", this.value, "live:", this.input_element.value);
updated (changed_props)
{
if (changed_props.has ('prop')) {
changed_props['prop'] && changed_props['prop'].delnotify_ (this.request_update_);
this.prop && this.prop.addnotify_ (this.request_update_);
}
const value = this.prop ? this.prop.value_.val : "";
if (value !== this.value) {
this.value = value;
this.request_update_ ('value');
}
}
disconnectedCallback()
{
this.prop && this.prop.delnotify_ (this.request_update_);
}
handle_input (event) { // emit 'input' with constrained value
handle_input (event) // emit 'input' with constrained value
{
const constrainedvalue = this.constrain (this.input_element.value);
if (constrainedvalue !== this.value) {
this.value = constrainedvalue; // becomes Event.target.value
this.dispatchEvent (new Event ('valuechange', { composed: true }));
this.value = constrainedvalue;
this.prop?.apply_ (this.value);
}
}
constrain (txt) {
constrain (txt)
{
return '' + txt;
}
}
Expand Down

0 comments on commit af7da4a

Please sign in to comment.