jails-js 6.0.1-beta.3 → 6.0.1-beta.5
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/dist/index.js +50 -63
- package/dist/index.js.map +1 -1
- package/dist/jails.js +1 -1
- package/dist/jails.js.map +1 -1
- package/package.json +1 -1
- package/src/component.ts +32 -37
- package/src/index.ts +1 -1
- package/src/template-system.ts +12 -24
- package/src/utils/index.ts +0 -27
package/dist/index.js
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
document.createElement("textarea");
|
2
1
|
const g = {
|
3
2
|
scope: {}
|
4
3
|
};
|
@@ -11,6 +10,9 @@ const rAF = (fn) => {
|
|
11
10
|
const uuid = () => {
|
12
11
|
return Math.random().toString(36).substring(2, 9);
|
13
12
|
};
|
13
|
+
const dup = (o) => {
|
14
|
+
return JSON.parse(JSON.stringify(o));
|
15
|
+
};
|
14
16
|
const safe = (execute, val) => {
|
15
17
|
try {
|
16
18
|
return execute();
|
@@ -788,13 +790,13 @@ const Component = ({ name, module, dependencies, node, templates: templates2, si
|
|
788
790
|
const _model = module.model || {};
|
789
791
|
const initialState = new Function(`return ${node.getAttribute("html-model") || "{}"}`)();
|
790
792
|
const tplid = node.getAttribute("tplid");
|
791
|
-
const scopeid = node.getAttribute("html-
|
793
|
+
const scopeid = node.getAttribute("html-scopeid");
|
792
794
|
const tpl = templates2[tplid];
|
793
|
-
const
|
794
|
-
const model = ((_a = module == null ? void 0 : module.model) == null ? void 0 : _a.apply) ? _model({ elm: node, initialState }) : _model;
|
795
|
-
const state = Object.assign({},
|
796
|
-
const view = module.view ? module.view : (
|
797
|
-
let
|
795
|
+
const scope = g.scope[scopeid];
|
796
|
+
const model = dup(((_a = module == null ? void 0 : module.model) == null ? void 0 : _a.apply) ? _model({ elm: node, initialState }) : _model);
|
797
|
+
const state = Object.assign({}, scope, model, initialState);
|
798
|
+
const view = module.view ? module.view : (data) => data;
|
799
|
+
let preserve = [];
|
798
800
|
const base = {
|
799
801
|
name,
|
800
802
|
model,
|
@@ -810,29 +812,32 @@ const Component = ({ name, module, dependencies, node, templates: templates2, si
|
|
810
812
|
* @State
|
811
813
|
*/
|
812
814
|
state: {
|
813
|
-
|
814
|
-
if (
|
815
|
-
|
815
|
+
protected(list) {
|
816
|
+
if (list) {
|
817
|
+
preserve = list;
|
818
|
+
} else {
|
819
|
+
return preserve;
|
820
|
+
}
|
821
|
+
},
|
822
|
+
save(data) {
|
823
|
+
if (data.constructor === Function) {
|
824
|
+
data(state);
|
816
825
|
} else {
|
817
|
-
Object.assign(state,
|
826
|
+
Object.assign(state, data);
|
818
827
|
}
|
819
828
|
},
|
820
|
-
set(
|
829
|
+
set(data) {
|
821
830
|
if (!document.body.contains(node)) {
|
822
831
|
return;
|
823
832
|
}
|
824
|
-
|
825
|
-
|
826
|
-
|
827
|
-
|
828
|
-
|
829
|
-
|
830
|
-
|
831
|
-
|
832
|
-
updates = [];
|
833
|
-
}
|
834
|
-
});
|
835
|
-
});
|
833
|
+
if (data.constructor === Function) {
|
834
|
+
data(state);
|
835
|
+
} else {
|
836
|
+
Object.assign(state, data);
|
837
|
+
}
|
838
|
+
const newstate = Object.assign({}, state, scope);
|
839
|
+
render(newstate);
|
840
|
+
return Promise.resolve(newstate);
|
836
841
|
},
|
837
842
|
get() {
|
838
843
|
return Object.assign({}, state);
|
@@ -872,17 +877,17 @@ const Component = ({ name, module, dependencies, node, templates: templates2, si
|
|
872
877
|
node.removeEventListener(ev, callback.handler);
|
873
878
|
}
|
874
879
|
},
|
875
|
-
trigger(ev, selectorOrCallback,
|
880
|
+
trigger(ev, selectorOrCallback, data) {
|
876
881
|
if (selectorOrCallback.constructor === String) {
|
877
882
|
Array.from(node.querySelectorAll(selectorOrCallback)).forEach((children) => {
|
878
|
-
children.dispatchEvent(new CustomEvent(ev, { bubbles: true, detail: { args:
|
883
|
+
children.dispatchEvent(new CustomEvent(ev, { bubbles: true, detail: { args: data } }));
|
879
884
|
});
|
880
885
|
} else {
|
881
|
-
node.dispatchEvent(new CustomEvent(ev, { bubbles: true, detail: { args:
|
886
|
+
node.dispatchEvent(new CustomEvent(ev, { bubbles: true, detail: { args: data } }));
|
882
887
|
}
|
883
888
|
},
|
884
|
-
emit(ev,
|
885
|
-
node.dispatchEvent(new CustomEvent(ev, { bubbles: true, detail: { args:
|
889
|
+
emit(ev, data) {
|
890
|
+
node.dispatchEvent(new CustomEvent(ev, { bubbles: true, detail: { args: data } }));
|
886
891
|
},
|
887
892
|
unmount(fn) {
|
888
893
|
node.addEventListener(":unmount", fn);
|
@@ -895,24 +900,17 @@ const Component = ({ name, module, dependencies, node, templates: templates2, si
|
|
895
900
|
rAF((_) => Idiomorph.morph(element, clone, IdiomorphOptions));
|
896
901
|
}
|
897
902
|
};
|
898
|
-
const render = (
|
899
|
-
const html = tpl.render.call(view(
|
903
|
+
const render = (data) => {
|
904
|
+
const html = tpl.render.call(view(data), node, safe, g);
|
900
905
|
Idiomorph.morph(node, html, IdiomorphOptions(node));
|
901
|
-
|
902
|
-
|
903
|
-
|
904
|
-
|
905
|
-
|
906
|
-
|
907
|
-
|
908
|
-
}
|
909
|
-
return acc;
|
910
|
-
}, null);
|
911
|
-
if (props) {
|
912
|
-
base2.state.set(props);
|
913
|
-
}
|
906
|
+
rAF(() => {
|
907
|
+
node.querySelectorAll("[tplid]").forEach((element) => {
|
908
|
+
if (!element.base) return;
|
909
|
+
element.base.state.protected().forEach((key) => delete data[key]);
|
910
|
+
element.base.state.set(data);
|
911
|
+
});
|
912
|
+
rAF(() => g.scope = {});
|
914
913
|
});
|
915
|
-
rAF(() => g.scope = {});
|
916
914
|
};
|
917
915
|
node.base = base;
|
918
916
|
return module.default(base);
|
@@ -979,8 +977,7 @@ const template = (target, { components: components2 }) => {
|
|
979
977
|
setTemplates(clone, components2);
|
980
978
|
return templates;
|
981
979
|
};
|
982
|
-
const compile = (
|
983
|
-
const html = transformAttributes(outerHTML);
|
980
|
+
const compile = (html) => {
|
984
981
|
const parsedHtml = JSON.stringify(html);
|
985
982
|
return new Function("$element", "safe", "$g", `
|
986
983
|
var $data = this;
|
@@ -1004,7 +1001,7 @@ const tagElements = (target, keys) => {
|
|
1004
1001
|
const transformAttributes = (html) => {
|
1005
1002
|
const regexTags = new RegExp(`\\${config.tags[0]}(.+?)\\${config.tags[1]}`, "g");
|
1006
1003
|
return html.replace(/jails___scope-id/g, "%%_=$scopeid_%%").replace(regexTags, "%%_=$1_%%").replace(/html-(allowfullscreen|async|autofocus|autoplay|checked|controls|default|defer|disabled|formnovalidate|inert|ismap|itemscope|loop|multiple|muted|nomodule|novalidate|open|playsinline|readonly|required|reversed|selected)=\"(.*?)\"/g, `%%_if(safe(function(){ return $2 })){_%%$1%%_}_%%`).replace(/html-(.*?)=\"(.*?)\"/g, (all, key, value) => {
|
1007
|
-
if (key === "key" || key === "model" || key === "
|
1004
|
+
if (key === "key" || key === "model" || key === "scopeid") {
|
1008
1005
|
return all;
|
1009
1006
|
}
|
1010
1007
|
if (value) {
|
@@ -1026,7 +1023,8 @@ const transformTemplate = (clone) => {
|
|
1026
1023
|
const split = htmlFor.match(/(.*)\sin\s(.*)/) || "";
|
1027
1024
|
const varname = split[1];
|
1028
1025
|
const object = split[2];
|
1029
|
-
const
|
1026
|
+
const objectname = object.split(/\./).shift();
|
1027
|
+
const open = document.createTextNode(`%%_ ;(function(){ var $index = 0; for(var $key in safe(function(){ return ${object} }) ){ var $scopeid = Math.random().toString(36).substring(2, 9); var ${varname} = ${object}[$key]; $g.scope[$scopeid] = Object.assign({}, { ${objectname}: ${objectname} }, { ${varname} :${varname}, $index: $index, $key: $key }); _%%`);
|
1030
1028
|
const close = document.createTextNode(`%%_ $index++; } })() _%%`);
|
1031
1029
|
wrap(open, element, close);
|
1032
1030
|
}
|
@@ -1053,24 +1051,13 @@ const setTemplates = (clone, components2) => {
|
|
1053
1051
|
Array.from(clone.querySelectorAll("[tplid]")).reverse().forEach((node) => {
|
1054
1052
|
const tplid = node.getAttribute("tplid");
|
1055
1053
|
const name = node.localName;
|
1056
|
-
node.setAttribute("html-
|
1054
|
+
node.setAttribute("html-scopeid", "jails___scope-id");
|
1057
1055
|
if (name in components2 && components2[name].module.template) {
|
1058
1056
|
const children = node.innerHTML;
|
1059
1057
|
const html2 = components2[name].module.template({ elm: node, children });
|
1060
|
-
|
1061
|
-
html2.then((htmlstring) => {
|
1062
|
-
node.innerHTML = htmlstring;
|
1063
|
-
const html3 = node.outerHTML;
|
1064
|
-
templates[tplid] = {
|
1065
|
-
template: html3,
|
1066
|
-
render: compile(html3)
|
1067
|
-
};
|
1068
|
-
});
|
1069
|
-
} else {
|
1070
|
-
node.innerHTML = html2;
|
1071
|
-
}
|
1058
|
+
node.innerHTML = html2;
|
1072
1059
|
}
|
1073
|
-
const html = node.outerHTML;
|
1060
|
+
const html = transformAttributes(node.outerHTML);
|
1074
1061
|
templates[tplid] = {
|
1075
1062
|
template: html,
|
1076
1063
|
render: compile(html)
|