@impro.social/impro-plugin 0.0.12 → 0.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/main.js +44 -7
- package/package.json +1 -1
package/main.js
CHANGED
|
@@ -739,15 +739,30 @@ class PostsFeedComponent {
|
|
|
739
739
|
}
|
|
740
740
|
}
|
|
741
741
|
|
|
742
|
+
export class VirtualText {
|
|
743
|
+
constructor(value) {
|
|
744
|
+
this.value = value == null ? "" : String(value);
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
_serialize() {
|
|
748
|
+
return { type: "text", value: this.value };
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
|
|
742
752
|
export class VirtualEl {
|
|
743
753
|
constructor(tag) {
|
|
744
754
|
this.tag = tag;
|
|
745
755
|
this.attrs = {};
|
|
746
|
-
this.
|
|
756
|
+
this.styles = {};
|
|
747
757
|
this.children = [];
|
|
748
758
|
this.events = {};
|
|
749
759
|
}
|
|
750
760
|
|
|
761
|
+
setStyle(name, value) {
|
|
762
|
+
this.styles[String(name)] = value == null ? "" : String(value);
|
|
763
|
+
return this;
|
|
764
|
+
}
|
|
765
|
+
|
|
751
766
|
onClick(fn) {
|
|
752
767
|
const handlerId = uuid.create();
|
|
753
768
|
callHandlers.set(handlerId, fn);
|
|
@@ -770,17 +785,37 @@ export class VirtualEl {
|
|
|
770
785
|
}
|
|
771
786
|
|
|
772
787
|
setText(text) {
|
|
773
|
-
this.text = text;
|
|
774
788
|
this.children = [];
|
|
789
|
+
if (text != null && text !== "") this.children.push(new VirtualText(text));
|
|
775
790
|
return this;
|
|
776
791
|
}
|
|
777
792
|
|
|
778
793
|
empty() {
|
|
779
|
-
this.text = null;
|
|
780
794
|
this.children = [];
|
|
781
795
|
return this;
|
|
782
796
|
}
|
|
783
797
|
|
|
798
|
+
appendChild(child) {
|
|
799
|
+
if (!(child instanceof VirtualEl) && !(child instanceof VirtualText)) {
|
|
800
|
+
throw new TypeError(
|
|
801
|
+
"appendChild expects a VirtualEl or VirtualText instance",
|
|
802
|
+
);
|
|
803
|
+
}
|
|
804
|
+
this.children.push(child);
|
|
805
|
+
return this;
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
appendText(value) {
|
|
809
|
+
this.children.push(new VirtualText(value));
|
|
810
|
+
return this;
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
createText(value) {
|
|
814
|
+
const node = new VirtualText(value);
|
|
815
|
+
this.children.push(node);
|
|
816
|
+
return node;
|
|
817
|
+
}
|
|
818
|
+
|
|
784
819
|
addClass(cls) {
|
|
785
820
|
this.attrs.class = this.attrs.class ? `${this.attrs.class} ${cls}` : cls;
|
|
786
821
|
return this;
|
|
@@ -793,7 +828,7 @@ export class VirtualEl {
|
|
|
793
828
|
|
|
794
829
|
createEl(tag, options = {}, callback) {
|
|
795
830
|
const child = new VirtualEl(tag);
|
|
796
|
-
if (options.text != null) child.
|
|
831
|
+
if (options.text != null) child.setText(options.text);
|
|
797
832
|
if (options.cls) {
|
|
798
833
|
child.attrs.class = Array.isArray(options.cls)
|
|
799
834
|
? options.cls.join(" ")
|
|
@@ -832,13 +867,15 @@ export class VirtualEl {
|
|
|
832
867
|
}
|
|
833
868
|
|
|
834
869
|
_serialize() {
|
|
835
|
-
|
|
870
|
+
const serialized = {
|
|
871
|
+
type: "element",
|
|
836
872
|
tag: this.tag,
|
|
837
873
|
attrs: this.attrs,
|
|
838
|
-
text: this.text,
|
|
839
|
-
children: this.children.map((child) => child._serialize()),
|
|
840
874
|
events: this.events,
|
|
875
|
+
children: this.children.map((child) => child._serialize()),
|
|
841
876
|
};
|
|
877
|
+
if (Object.keys(this.styles).length > 0) serialized.styles = this.styles;
|
|
878
|
+
return serialized;
|
|
842
879
|
}
|
|
843
880
|
}
|
|
844
881
|
|