Skip to content

Commit

Permalink
Update components/traits
Browse files Browse the repository at this point in the history
  • Loading branch information
artf committed Jun 9, 2023
1 parent 103e57b commit f9378b9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
25 changes: 10 additions & 15 deletions src/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,16 @@ export default (editor: Editor, opts: RequiredPluginOptions) => {
traits,
'script-props': [...typedPropsKeys, 'typedsrc'],
script(props: typeof typedProps & { typedsrc: string }) {
console.log({props});
const strings = typeof props.strings === 'string' ? JSON.parse(props.strings) : props.strings;
const getStrings = (value: string | string[]) => {
if (Array.isArray(value)) {
return value;
} else if (value.indexOf('\n') >= 0) {
return value.split('\n');
} else {
return []
}
}
const strings = getStrings(props.strings);
const int = (num: any) => parseInt(num, 10) || 0;
const bool = (val: any) => !!val;
const init = () => {
Expand Down Expand Up @@ -110,19 +118,6 @@ export default (editor: Editor, opts: RequiredPluginOptions) => {
}
},
}) as any,

init() {
const events = traits.filter(i => ['strings'].indexOf(i.name) < 0)
.map(i => `change:${i.name}`).join(' ');
this.on(events, () => this.trigger('change:script'));
this.on('change:strings', this.onStringsChange);
},

onStringsChange(_: any, value: any) {
if (Array.isArray(value)) return;
this.set({ strings: value.split('\n') });
this.trigger('change:script');
}
},
});
};
7 changes: 6 additions & 1 deletion src/traits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ export default (editor: Editor) => {

onUpdate({ component, elInput }) {
elInput.value = component.get('strings').join('\n');
}
},

onEvent({ component, elInput }) {
const value = (elInput.value || '').split('\n');
component.set('strings', value);
},
});
}

0 comments on commit f9378b9

Please sign in to comment.