@lark.js/mvc 0.0.1 → 0.0.2
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/README.md +945 -1
- package/dist/{chunk-DZUOIUWX.js → chunk-5OEHRF3U.js} +37 -37
- package/dist/index.cjs +79 -79
- package/dist/index.d.cts +13 -13
- package/dist/index.d.ts +13 -13
- package/dist/index.js +76 -76
- package/dist/vite.cjs +46 -46
- package/dist/vite.d.cts +5 -5
- package/dist/vite.d.ts +5 -5
- package/dist/vite.js +9 -9
- package/dist/webpack.cjs +41 -41
- package/dist/webpack.d.cts +2 -2
- package/dist/webpack.d.ts +2 -2
- package/dist/webpack.js +4 -4
- package/lark.d.ts +1176 -0
- package/package.json +4 -2
|
@@ -14612,9 +14612,9 @@ function jsObjectToUrlParams(paramsStr) {
|
|
|
14612
14612
|
if (objMatch) {
|
|
14613
14613
|
const inner = objMatch[1];
|
|
14614
14614
|
const pairs = [];
|
|
14615
|
-
const
|
|
14615
|
+
const pairRegExp = /(\w+)\s*:\s*(?:'([^']*)'|"([^"]*)"|([^,}]+))/g;
|
|
14616
14616
|
let m;
|
|
14617
|
-
while ((m =
|
|
14617
|
+
while ((m = pairRegExp.exec(inner)) !== null) {
|
|
14618
14618
|
const key = m[1];
|
|
14619
14619
|
const value = m[2] ?? m[3] ?? m[4]?.trim() ?? "";
|
|
14620
14620
|
pairs.push(`${key}=${value}`);
|
|
@@ -14636,19 +14636,19 @@ function restoreComments(source, comments) {
|
|
|
14636
14636
|
return comments[parseInt(index, 10)];
|
|
14637
14637
|
});
|
|
14638
14638
|
}
|
|
14639
|
-
function
|
|
14639
|
+
function processViewEvents(source) {
|
|
14640
14640
|
return source.replace(
|
|
14641
|
-
/
|
|
14641
|
+
/v-(\w+)="([^"]+)"/g,
|
|
14642
14642
|
(fullAttr, eventName, attrValue) => {
|
|
14643
14643
|
const eventMatch = attrValue.match(/^(\w+)\((.*)\)$/s);
|
|
14644
14644
|
if (!eventMatch) return fullAttr;
|
|
14645
14645
|
const handlerName = eventMatch[1];
|
|
14646
14646
|
const paramsStr = eventMatch[2].trim();
|
|
14647
14647
|
if (!paramsStr) {
|
|
14648
|
-
return `
|
|
14648
|
+
return `v-${eventName}="${VIEW_ID_PLACEHOLDER}${SPLITTER}${handlerName}()"`;
|
|
14649
14649
|
}
|
|
14650
14650
|
const urlParams = jsObjectToUrlParams(paramsStr);
|
|
14651
|
-
return `
|
|
14651
|
+
return `v-${eventName}="${VIEW_ID_PLACEHOLDER}${SPLITTER}${handlerName}(${urlParams})"`;
|
|
14652
14652
|
}
|
|
14653
14653
|
);
|
|
14654
14654
|
}
|
|
@@ -14721,7 +14721,7 @@ function convertArtSyntax(source, debug) {
|
|
|
14721
14721
|
}
|
|
14722
14722
|
if (blockStack.length > 0) {
|
|
14723
14723
|
const unclosed = blockStack.map((b) => `"${b.ctrl}" at line ${b.line}`).join(", ");
|
|
14724
|
-
throw new Error(`[
|
|
14724
|
+
throw new Error(`[@lark/mvc error] unclosed block(s): ${unclosed}`);
|
|
14725
14725
|
}
|
|
14726
14726
|
return result.join("");
|
|
14727
14727
|
}
|
|
@@ -14820,7 +14820,7 @@ function convertArtExpression(code, debug, lineNo, blockStack = []) {
|
|
|
14820
14820
|
const object = tokens[0];
|
|
14821
14821
|
if (tokens.length > 1 && tokens[1] !== "as") {
|
|
14822
14822
|
throw new Error(
|
|
14823
|
-
`[
|
|
14823
|
+
`[@lark/mvc error] bad each syntax: {{${code}}}. Expected "as" keyword, got "${tokens[1]}". Usage: {{each list as item [index]}}`
|
|
14824
14824
|
);
|
|
14825
14825
|
}
|
|
14826
14826
|
const restTokens = tokens.slice(2);
|
|
@@ -14842,12 +14842,12 @@ function convertArtExpression(code, debug, lineNo, blockStack = []) {
|
|
|
14842
14842
|
}
|
|
14843
14843
|
return `${debugPrefix}<%for(let ${index}=0${refExpr},${refObjCount}=${refObj}.length${lastCount};${index}<${refObjCount};${index}++){${firstAndLast}${valueDecl}%>`;
|
|
14844
14844
|
}
|
|
14845
|
-
case "
|
|
14846
|
-
blockStack.push({ ctrl: "
|
|
14845
|
+
case "parse": {
|
|
14846
|
+
blockStack.push({ ctrl: "parse", line: lineNo });
|
|
14847
14847
|
const object = tokens[0];
|
|
14848
14848
|
if (tokens.length > 1 && tokens[1] !== "as") {
|
|
14849
14849
|
throw new Error(
|
|
14850
|
-
`[
|
|
14850
|
+
`[@lark/mvc error] bad parse syntax: {{${code}}}. Expected "as" keyword, got "${tokens[1]}". Usage: {{for-in obj as val [key]}}`
|
|
14851
14851
|
);
|
|
14852
14852
|
}
|
|
14853
14853
|
const restTokens2 = tokens.slice(2);
|
|
@@ -14868,18 +14868,18 @@ function convertArtExpression(code, debug, lineNo, blockStack = []) {
|
|
|
14868
14868
|
return `${debugPrefix}<%let ${tokens.join(" ")};%>`;
|
|
14869
14869
|
case "/if":
|
|
14870
14870
|
case "/each":
|
|
14871
|
-
case "/
|
|
14871
|
+
case "/parse":
|
|
14872
14872
|
case "/for": {
|
|
14873
14873
|
const expectedCtrl = keyword.substring(1);
|
|
14874
14874
|
const last = blockStack.pop();
|
|
14875
14875
|
if (!last) {
|
|
14876
14876
|
throw new Error(
|
|
14877
|
-
`[
|
|
14877
|
+
`[@lark/mvc error(template] unexpected {{${code}}}: no matching open block`
|
|
14878
14878
|
);
|
|
14879
14879
|
}
|
|
14880
14880
|
if (last.ctrl !== expectedCtrl) {
|
|
14881
14881
|
throw new Error(
|
|
14882
|
-
`[
|
|
14882
|
+
`[@lark/mvc error(template] unexpected {{${code}}}: expected {{/${last.ctrl}}} to close block opened at line ${last.line}`
|
|
14883
14883
|
);
|
|
14884
14884
|
}
|
|
14885
14885
|
return `${debugPrefix}<%}%>`;
|
|
@@ -14956,12 +14956,12 @@ function compileToFunction(source, debug, file) {
|
|
|
14956
14956
|
index - 2
|
|
14957
14957
|
);
|
|
14958
14958
|
const x11 = String.fromCharCode(17);
|
|
14959
|
-
const
|
|
14960
|
-
const artM = expr.match(
|
|
14959
|
+
const artRegExp = new RegExp(`^'(\\d+)${x11}([^${x11}]+)${x11}'$`);
|
|
14960
|
+
const artM = expr.match(artRegExp);
|
|
14961
14961
|
let art = "";
|
|
14962
14962
|
let line = -1;
|
|
14963
14963
|
if (artM) {
|
|
14964
|
-
expr = expr.replace(
|
|
14964
|
+
expr = expr.replace(artRegExp, "");
|
|
14965
14965
|
art = artM[2];
|
|
14966
14966
|
line = parseInt(artM[1], 10);
|
|
14967
14967
|
} else {
|
|
@@ -15020,8 +15020,8 @@ function compileToFunction(source, debug, file) {
|
|
|
15020
15020
|
const filePart = file ? `\\r\\n\\tat file:${file}` : "";
|
|
15021
15021
|
funcSource = `let $expr,$art,$line;try{${funcSource}}catch(ex){let msg='render view error:'+(ex.message||ex);if($art)msg+='\\r\\n\\tsrc art:{{'+$art+'}}\\r\\n\\tat line:'+$line;msg+='\\r\\n\\t'+($art?'translate to:':'expr:');msg+=$expr+'${filePart}';throw msg;}`;
|
|
15022
15022
|
}
|
|
15023
|
-
const
|
|
15024
|
-
funcSource = funcSource.replace(
|
|
15023
|
+
const viewIdRegExp = new RegExp(String.fromCharCode(31), "g");
|
|
15024
|
+
funcSource = funcSource.replace(viewIdRegExp, `'+$viewId+'`);
|
|
15025
15025
|
const atRule = hasAtRule ? `if(!$i){$i=(ref,v,k,f)=>{for(f=ref[$g];--f;)if(ref[k=$g+f]===v)return k;ref[k=$g+ref[$g]++]=v;return k;}}` : "";
|
|
15026
15026
|
const encode = `if(!$n){let $em={'&':'amp','<':'lt','>':'gt','"':'#34','\\'':'#39','\`':'#96'},$er=/[&<>"'\`]/g,$ef=m=>'&'+$em[m]+';';$n=v=>''+(v==null?'':v);$e=v=>$n(v).replace($er,$ef)}`;
|
|
15027
15027
|
const encodeURIMore = `if(!$eu){let $um={'!':'%21','\\'':'%27','(':'%28',')':'%29','*':'%2A'},$uf=m=>$um[m],$uq=/[!')(*]/g;$eu=v=>encodeURIComponent($n(v)).replace($uq,$uf)}`;
|
|
@@ -15035,8 +15035,8 @@ function compileTemplate(source, options = {}) {
|
|
|
15035
15035
|
const { debug = false, globalVars = [], file } = options;
|
|
15036
15036
|
const { protectedSource, comments } = protectComments(source);
|
|
15037
15037
|
const converted = convertArtSyntax(protectedSource, debug);
|
|
15038
|
-
const
|
|
15039
|
-
const finalSource = restoreComments(
|
|
15038
|
+
const viewEventProcessed = processViewEvents(converted);
|
|
15039
|
+
const finalSource = restoreComments(viewEventProcessed, comments);
|
|
15040
15040
|
const funcBody = compileToFunction(finalSource, debug, file);
|
|
15041
15041
|
const varDeclarations = globalVars.map((key) => `,${key}=$$.${key}`).join("");
|
|
15042
15042
|
const funcWithVars = funcBody.replace("{{VARS}}", () => varDeclarations);
|
|
@@ -15054,20 +15054,20 @@ function compileTemplate(source, options = {}) {
|
|
|
15054
15054
|
}
|
|
15055
15055
|
function extractGlobalVars(source) {
|
|
15056
15056
|
const { protectedSource, comments: _comments } = protectComments(source);
|
|
15057
|
-
const
|
|
15058
|
-
const converted = convertArtSyntax(
|
|
15059
|
-
const
|
|
15060
|
-
const
|
|
15057
|
+
const viewEventProcessed = processViewEvents(protectedSource);
|
|
15058
|
+
const converted = convertArtSyntax(viewEventProcessed, false);
|
|
15059
|
+
const template = restoreComments(converted, _comments);
|
|
15060
|
+
const templateCmdRegExp = /<%([@=!:])?([\s\S]*?)%>|$/g;
|
|
15061
15061
|
const fnParts = [];
|
|
15062
15062
|
const htmlStore = {};
|
|
15063
15063
|
let htmlIndex = 0;
|
|
15064
15064
|
let lastIndex = 0;
|
|
15065
15065
|
const htmlKey = "";
|
|
15066
|
-
|
|
15067
|
-
|
|
15066
|
+
template.replace(
|
|
15067
|
+
templateCmdRegExp,
|
|
15068
15068
|
(match, operate, content, offset) => {
|
|
15069
15069
|
const start = operate ? 3 : 2;
|
|
15070
|
-
const htmlText =
|
|
15070
|
+
const htmlText = template.substring(lastIndex, offset + start);
|
|
15071
15071
|
const key = htmlKey + htmlIndex++ + htmlKey;
|
|
15072
15072
|
htmlStore[key] = htmlText;
|
|
15073
15073
|
lastIndex = offset + match.length - 2;
|
|
@@ -15152,17 +15152,17 @@ function extractGlobalVars(source) {
|
|
|
15152
15152
|
}
|
|
15153
15153
|
function fallbackExtractVariables(source) {
|
|
15154
15154
|
const vars = /* @__PURE__ */ new Set();
|
|
15155
|
-
const
|
|
15155
|
+
const outputRegExp = /\{\{[:=!@]\s*([a-zA-Z_$][\w$]*)[^}]*\}\}/g;
|
|
15156
15156
|
let m;
|
|
15157
|
-
while ((m =
|
|
15157
|
+
while ((m = outputRegExp.exec(source)) !== null) {
|
|
15158
15158
|
vars.add(m[1]);
|
|
15159
15159
|
}
|
|
15160
|
-
const
|
|
15161
|
-
while ((m =
|
|
15160
|
+
const eachRegExp = /\{\{each\s+([a-zA-Z_$][\w$]*)\s+as/g;
|
|
15161
|
+
while ((m = eachRegExp.exec(source)) !== null) {
|
|
15162
15162
|
vars.add(m[1]);
|
|
15163
15163
|
}
|
|
15164
|
-
const
|
|
15165
|
-
while ((m =
|
|
15164
|
+
const ifRegExp = /\{\{(?:else\s+)?if\s+([a-zA-Z_$][\w$]*)[^}]*\}\}/g;
|
|
15165
|
+
while ((m = ifRegExp.exec(source)) !== null) {
|
|
15166
15166
|
vars.add(m[1]);
|
|
15167
15167
|
}
|
|
15168
15168
|
return Array.from(vars).filter((v) => !BUILTIN_GLOBAL_SET.has(v));
|
|
@@ -15225,7 +15225,7 @@ var BUILTIN_GLOBALS = {
|
|
|
15225
15225
|
// {'&':'amp','<':'gt','>':'gt','"':'#34','\'':'#39','`':'#96'}
|
|
15226
15226
|
// Not a standalone function; referenced inside $e's closure.
|
|
15227
15227
|
$em: 1,
|
|
15228
|
-
// HTML entity RegExp — internal
|
|
15228
|
+
// HTML entity RegExp — internal regexp used by $e:
|
|
15229
15229
|
// /[&<>"'`]/g
|
|
15230
15230
|
$er: 1,
|
|
15231
15231
|
// HTML entity replacer function — internal helper used by $e:
|
|
@@ -15244,14 +15244,14 @@ var BUILTIN_GLOBALS = {
|
|
|
15244
15244
|
$i: 1,
|
|
15245
15245
|
// URI encoder: v => encodeURIComponent($n(v)).replace(/[!')(*]/g, extraMap)
|
|
15246
15246
|
// Extends encodeURIComponent with encoding of ! ' ( ) *.
|
|
15247
|
-
// Applied to values in
|
|
15247
|
+
// Applied to values in v-event URL parameters and {{!uri}} contexts.
|
|
15248
15248
|
$eu: 1,
|
|
15249
15249
|
// Quote encoder: v => $n(v).replace(/['"\\]/g, '\\$&')
|
|
15250
15250
|
// Escapes quotes and backslashes for safe embedding in HTML attribute
|
|
15251
15251
|
// values (e.g. data-json='...').
|
|
15252
15252
|
$eq: 1,
|
|
15253
15253
|
// View ID — the unique identifier of the owning View instance.
|
|
15254
|
-
// Injected into
|
|
15254
|
+
// Injected into v-event attribute values at render time so that
|
|
15255
15255
|
// EventDelegator can dispatch events to the correct View handler.
|
|
15256
15256
|
// The \x1f placeholder in compiled output is replaced with '+$viewId+'.
|
|
15257
15257
|
$viewId: 1,
|
package/dist/index.cjs
CHANGED
|
@@ -23,7 +23,7 @@ __export(index_exports, {
|
|
|
23
23
|
Bag: () => Bag,
|
|
24
24
|
CALL_BREAK_TIME: () => CALL_BREAK_TIME,
|
|
25
25
|
Cache: () => Cache,
|
|
26
|
-
|
|
26
|
+
EVENT_METHOD_REGEXP: () => EVENT_METHOD_REGEXP,
|
|
27
27
|
EventDelegator: () => EventDelegator,
|
|
28
28
|
EventEmitter: () => EventEmitter,
|
|
29
29
|
Frame: () => Frame,
|
|
@@ -37,10 +37,10 @@ __export(index_exports, {
|
|
|
37
37
|
State: () => State,
|
|
38
38
|
TAG_ATTR_KEY: () => TAG_ATTR_KEY,
|
|
39
39
|
TAG_KEY: () => TAG_KEY,
|
|
40
|
-
|
|
40
|
+
TAG_NAME_REGEXP: () => TAG_NAME_REGEXP,
|
|
41
41
|
TAG_VIEW_KEY: () => TAG_VIEW_KEY,
|
|
42
42
|
Updater: () => Updater,
|
|
43
|
-
|
|
43
|
+
VIEW_EVENT_METHOD_REGEXP: () => VIEW_EVENT_METHOD_REGEXP,
|
|
44
44
|
View: () => View,
|
|
45
45
|
applyIdUpdates: () => applyIdUpdates,
|
|
46
46
|
applyStyle: () => applyStyle,
|
|
@@ -120,17 +120,17 @@ var TAG_KEY = "lark-key";
|
|
|
120
120
|
var TAG_ATTR_KEY = "lark-attr-key";
|
|
121
121
|
var TAG_VIEW_KEY = "lark-view-key";
|
|
122
122
|
var LARK_VIEW = "lark-view";
|
|
123
|
-
var
|
|
123
|
+
var EVENT_METHOD_REGEXP = new RegExp(
|
|
124
124
|
`(?:([\\w-]+)${SPLITTER})?([^(]+)\\(([\\s\\S]*?)?\\)`
|
|
125
125
|
);
|
|
126
|
-
var
|
|
127
|
-
var
|
|
128
|
-
var
|
|
129
|
-
var
|
|
130
|
-
var
|
|
126
|
+
var VIEW_EVENT_METHOD_REGEXP = /^(\$?)([\w]*)<(.*?)>(?:<([\w ,]*)>)?$/;
|
|
127
|
+
var URL_TRIM_HASH_REGEXP = /(?:^.*\/\/[^/]+|#.*$)/gi;
|
|
128
|
+
var URL_TRIM_QUERY_REGEXP = /^[^#]*#?!?/;
|
|
129
|
+
var URL_PARAM_REGEXP = /([^=&?/#]+)=?([^&#?]*)/g;
|
|
130
|
+
var URL_QUERY_HASH_REGEXP = /[#?].*$/;
|
|
131
131
|
var SVG_NS = "http://www.w3.org/2000/svg";
|
|
132
132
|
var MATH_NS = "http://www.w3.org/1998/Math/MathML";
|
|
133
|
-
var
|
|
133
|
+
var TAG_NAME_REGEXP = /<([a-z][^/\0>\x20\t\r\n\f]+)/i;
|
|
134
134
|
var CALL_BREAK_TIME = 48;
|
|
135
135
|
function nextCounter() {
|
|
136
136
|
return ++globalCounter;
|
|
@@ -268,10 +268,10 @@ function paramsReplacer(_match, name, value) {
|
|
|
268
268
|
}
|
|
269
269
|
function parseUri(uri) {
|
|
270
270
|
paramsTemp = {};
|
|
271
|
-
const path = uri.replace(
|
|
271
|
+
const path = uri.replace(URL_QUERY_HASH_REGEXP, "");
|
|
272
272
|
const pathname = path;
|
|
273
273
|
const actualPath = uri === pathname && IS_URL_PARAMS.test(pathname) ? "" : pathname;
|
|
274
|
-
uri.replace(actualPath, "").replace(
|
|
274
|
+
uri.replace(actualPath, "").replace(URL_PARAM_REGEXP, paramsReplacer);
|
|
275
275
|
return {
|
|
276
276
|
path: actualPath,
|
|
277
277
|
params: { ...paramsTemp }
|
|
@@ -965,8 +965,8 @@ var Router = {
|
|
|
965
965
|
if (cached) {
|
|
966
966
|
return cached;
|
|
967
967
|
}
|
|
968
|
-
const srcQuery = href.replace(
|
|
969
|
-
const srcHash = href.replace(
|
|
968
|
+
const srcQuery = href.replace(URL_TRIM_HASH_REGEXP, "");
|
|
969
|
+
const srcHash = href.replace(URL_TRIM_QUERY_REGEXP, "");
|
|
970
970
|
const query = parseUri(srcQuery);
|
|
971
971
|
const hash = parseUri(srcHash);
|
|
972
972
|
const params = assign({}, query["params"], hash["params"]);
|
|
@@ -1068,9 +1068,9 @@ var Router = {
|
|
|
1068
1068
|
join(...paths) {
|
|
1069
1069
|
let result = paths.join("/");
|
|
1070
1070
|
result = result.replace(/\/\.\//g, "/");
|
|
1071
|
-
const
|
|
1072
|
-
while (
|
|
1073
|
-
result = result.replace(
|
|
1071
|
+
const doubleDotRegExp = /\/[^/]+\/\.\.\//;
|
|
1072
|
+
while (doubleDotRegExp.test(result)) {
|
|
1073
|
+
result = result.replace(doubleDotRegExp, "/");
|
|
1074
1074
|
}
|
|
1075
1075
|
result = result.replace(/\/{2,}/g, "/");
|
|
1076
1076
|
return result;
|
|
@@ -1172,7 +1172,7 @@ function parseEventInfo(eventInfo) {
|
|
|
1172
1172
|
if (cached) {
|
|
1173
1173
|
return assign({}, cached, { r: eventInfo });
|
|
1174
1174
|
}
|
|
1175
|
-
const match = eventInfo.match(
|
|
1175
|
+
const match = eventInfo.match(EVENT_METHOD_REGEXP) || [];
|
|
1176
1176
|
const result = {
|
|
1177
1177
|
v: match[1] || "",
|
|
1178
1178
|
n: match[2] || "",
|
|
@@ -1184,7 +1184,7 @@ function parseEventInfo(eventInfo) {
|
|
|
1184
1184
|
function findFrameInfo(current, eventType) {
|
|
1185
1185
|
const eventInfos = [];
|
|
1186
1186
|
let begin = current;
|
|
1187
|
-
const info = current.getAttribute(`
|
|
1187
|
+
const info = current.getAttribute(`v-${eventType}`);
|
|
1188
1188
|
let match;
|
|
1189
1189
|
if (info) {
|
|
1190
1190
|
match = parseEventInfo(info);
|
|
@@ -1229,7 +1229,7 @@ function findFrameInfo(current, eventType) {
|
|
|
1229
1229
|
}
|
|
1230
1230
|
}
|
|
1231
1231
|
}
|
|
1232
|
-
if (view.
|
|
1232
|
+
if (view.template && !backtrace) {
|
|
1233
1233
|
if (match && !match.v) {
|
|
1234
1234
|
match.v = frameId;
|
|
1235
1235
|
}
|
|
@@ -1408,7 +1408,7 @@ function vdomGetNode(html, refNode) {
|
|
|
1408
1408
|
} else if (ns === MATH_NS) {
|
|
1409
1409
|
tag = "m";
|
|
1410
1410
|
} else {
|
|
1411
|
-
const match =
|
|
1411
|
+
const match = TAG_NAME_REGEXP.exec(html);
|
|
1412
1412
|
tag = match ? match[1] : "";
|
|
1413
1413
|
}
|
|
1414
1414
|
const wrap = WrapMeta[tag] || WrapMeta["_"];
|
|
@@ -1637,10 +1637,10 @@ var EncoderMap = {
|
|
|
1637
1637
|
"'": "#39",
|
|
1638
1638
|
"`": "#96"
|
|
1639
1639
|
};
|
|
1640
|
-
var
|
|
1640
|
+
var ENCODE_REGEXP = /[&<>"'`]/g;
|
|
1641
1641
|
function encodeHTML(v) {
|
|
1642
1642
|
return String(v == null ? "" : v).replace(
|
|
1643
|
-
|
|
1643
|
+
ENCODE_REGEXP,
|
|
1644
1644
|
(m) => "&" + EncoderMap[m] + ";"
|
|
1645
1645
|
);
|
|
1646
1646
|
}
|
|
@@ -1654,16 +1654,16 @@ var URIMap = {
|
|
|
1654
1654
|
")": "%29",
|
|
1655
1655
|
"*": "%2A"
|
|
1656
1656
|
};
|
|
1657
|
-
var
|
|
1657
|
+
var URI_ENCODE_REGEXP = /[!')(*]/g;
|
|
1658
1658
|
function encodeURIExtra(v) {
|
|
1659
1659
|
return encodeURIComponent(encodeSafe(v)).replace(
|
|
1660
|
-
|
|
1660
|
+
URI_ENCODE_REGEXP,
|
|
1661
1661
|
(m) => URIMap[m]
|
|
1662
1662
|
);
|
|
1663
1663
|
}
|
|
1664
|
-
var
|
|
1664
|
+
var QUOTE_REGEXP = /['"\\]/g;
|
|
1665
1665
|
function encodeQ(v) {
|
|
1666
|
-
return encodeSafe(v).replace(
|
|
1666
|
+
return encodeSafe(v).replace(QUOTE_REGEXP, "\\$&");
|
|
1667
1667
|
}
|
|
1668
1668
|
|
|
1669
1669
|
// src/updater.ts
|
|
@@ -1762,9 +1762,9 @@ var Updater = class {
|
|
|
1762
1762
|
const view = frame?.view;
|
|
1763
1763
|
const node = getById(this.viewId);
|
|
1764
1764
|
if (changed && view && node && view.signature > 0) {
|
|
1765
|
-
const
|
|
1766
|
-
if (
|
|
1767
|
-
const html =
|
|
1765
|
+
const template = view.template;
|
|
1766
|
+
if (template && typeof template === "function") {
|
|
1767
|
+
const html = template(
|
|
1768
1768
|
this.data,
|
|
1769
1769
|
this.viewId,
|
|
1770
1770
|
this.refData,
|
|
@@ -1869,7 +1869,7 @@ function viewPrepare(oView) {
|
|
|
1869
1869
|
if (!has(proto, p)) continue;
|
|
1870
1870
|
const currentFn = proto[p];
|
|
1871
1871
|
if (typeof currentFn !== "function") continue;
|
|
1872
|
-
const matches = p.match(
|
|
1872
|
+
const matches = p.match(VIEW_EVENT_METHOD_REGEXP);
|
|
1873
1873
|
if (!matches) continue;
|
|
1874
1874
|
const isSelector = matches[1];
|
|
1875
1875
|
const selectorOrCallback = matches[2];
|
|
@@ -1980,7 +1980,7 @@ function viewMergeMixins(mixins, viewClass, ctors) {
|
|
|
1980
1980
|
ctors.push(fn);
|
|
1981
1981
|
continue;
|
|
1982
1982
|
}
|
|
1983
|
-
if (
|
|
1983
|
+
if (VIEW_EVENT_METHOD_REGEXP.test(p)) {
|
|
1984
1984
|
if (exist) {
|
|
1985
1985
|
temp[p] = processMixinsSameEvent(fn, exist);
|
|
1986
1986
|
} else {
|
|
@@ -2078,7 +2078,7 @@ var View = class _View {
|
|
|
2078
2078
|
/** Whether rendered at least once */
|
|
2079
2079
|
rendered;
|
|
2080
2080
|
/** Whether view has template */
|
|
2081
|
-
|
|
2081
|
+
template;
|
|
2082
2082
|
/** Location observation config */
|
|
2083
2083
|
locationObserved = {
|
|
2084
2084
|
flag: 0,
|
|
@@ -2340,7 +2340,7 @@ var View = class _View {
|
|
|
2340
2340
|
initParams,
|
|
2341
2341
|
{
|
|
2342
2342
|
node,
|
|
2343
|
-
deep: !this.
|
|
2343
|
+
deep: !this.template
|
|
2344
2344
|
}
|
|
2345
2345
|
];
|
|
2346
2346
|
const concatCtors = ctors.concat(mixinCtors || []);
|
|
@@ -2468,8 +2468,8 @@ var Frame = class _Frame extends EventEmitter {
|
|
|
2468
2468
|
* 5. Create View instance
|
|
2469
2469
|
* 6. View_DelegateEvents (bind DOM events)
|
|
2470
2470
|
* 7. Call view.init()
|
|
2471
|
-
* 8. If view has
|
|
2472
|
-
* 9. If no
|
|
2471
|
+
* 8. If view has template, call render via Updater
|
|
2472
|
+
* 9. If no template, call endUpdate directly
|
|
2473
2473
|
*/
|
|
2474
2474
|
mountView(viewPath, viewInitParams) {
|
|
2475
2475
|
const node = document.getElementById(this.id);
|
|
@@ -2513,14 +2513,14 @@ var Frame = class _Frame extends EventEmitter {
|
|
|
2513
2513
|
viewDelegateEvents(view);
|
|
2514
2514
|
const initResult = funcWithTry(
|
|
2515
2515
|
view.init,
|
|
2516
|
-
[params, { node, deep: !view.
|
|
2516
|
+
[params, { node, deep: !view.template }],
|
|
2517
2517
|
view,
|
|
2518
2518
|
noop
|
|
2519
2519
|
);
|
|
2520
2520
|
const nextSign = ++this.signature;
|
|
2521
2521
|
Promise.resolve(initResult).then(() => {
|
|
2522
2522
|
if (nextSign !== this.signature) return;
|
|
2523
|
-
if (view.
|
|
2523
|
+
if (view.template) {
|
|
2524
2524
|
const renderFn = view.$b;
|
|
2525
2525
|
if (renderFn) {
|
|
2526
2526
|
renderFn.call(view);
|
|
@@ -3366,7 +3366,7 @@ var Framework = {
|
|
|
3366
3366
|
const rootFrame2 = Frame.root(config.rootId);
|
|
3367
3367
|
Router._bind();
|
|
3368
3368
|
const defaultView = config.defaultView || "";
|
|
3369
|
-
if (defaultView) {
|
|
3369
|
+
if (defaultView && !rootFrame2.view) {
|
|
3370
3370
|
rootFrame2.mountView(defaultView);
|
|
3371
3371
|
}
|
|
3372
3372
|
},
|
|
@@ -4326,9 +4326,9 @@ function jsObjectToUrlParams(paramsStr) {
|
|
|
4326
4326
|
if (objMatch) {
|
|
4327
4327
|
const inner = objMatch[1];
|
|
4328
4328
|
const pairs = [];
|
|
4329
|
-
const
|
|
4329
|
+
const pairRegExp = /(\w+)\s*:\s*(?:'([^']*)'|"([^"]*)"|([^,}]+))/g;
|
|
4330
4330
|
let m;
|
|
4331
|
-
while ((m =
|
|
4331
|
+
while ((m = pairRegExp.exec(inner)) !== null) {
|
|
4332
4332
|
const key = m[1];
|
|
4333
4333
|
const value = m[2] ?? m[3] ?? m[4]?.trim() ?? "";
|
|
4334
4334
|
pairs.push(`${key}=${value}`);
|
|
@@ -4350,19 +4350,19 @@ function restoreComments(source, comments) {
|
|
|
4350
4350
|
return comments[parseInt(index, 10)];
|
|
4351
4351
|
});
|
|
4352
4352
|
}
|
|
4353
|
-
function
|
|
4353
|
+
function processViewEvents(source) {
|
|
4354
4354
|
return source.replace(
|
|
4355
|
-
/
|
|
4355
|
+
/v-(\w+)="([^"]+)"/g,
|
|
4356
4356
|
(fullAttr, eventName, attrValue) => {
|
|
4357
4357
|
const eventMatch = attrValue.match(/^(\w+)\((.*)\)$/s);
|
|
4358
4358
|
if (!eventMatch) return fullAttr;
|
|
4359
4359
|
const handlerName = eventMatch[1];
|
|
4360
4360
|
const paramsStr = eventMatch[2].trim();
|
|
4361
4361
|
if (!paramsStr) {
|
|
4362
|
-
return `
|
|
4362
|
+
return `v-${eventName}="${VIEW_ID_PLACEHOLDER}${SPLITTER2}${handlerName}()"`;
|
|
4363
4363
|
}
|
|
4364
4364
|
const urlParams = jsObjectToUrlParams(paramsStr);
|
|
4365
|
-
return `
|
|
4365
|
+
return `v-${eventName}="${VIEW_ID_PLACEHOLDER}${SPLITTER2}${handlerName}(${urlParams})"`;
|
|
4366
4366
|
}
|
|
4367
4367
|
);
|
|
4368
4368
|
}
|
|
@@ -4435,7 +4435,7 @@ function convertArtSyntax(source, debug) {
|
|
|
4435
4435
|
}
|
|
4436
4436
|
if (blockStack.length > 0) {
|
|
4437
4437
|
const unclosed = blockStack.map((b) => `"${b.ctrl}" at line ${b.line}`).join(", ");
|
|
4438
|
-
throw new Error(`[
|
|
4438
|
+
throw new Error(`[@lark/mvc error] unclosed block(s): ${unclosed}`);
|
|
4439
4439
|
}
|
|
4440
4440
|
return result.join("");
|
|
4441
4441
|
}
|
|
@@ -4534,7 +4534,7 @@ function convertArtExpression(code, debug, lineNo, blockStack = []) {
|
|
|
4534
4534
|
const object = tokens[0];
|
|
4535
4535
|
if (tokens.length > 1 && tokens[1] !== "as") {
|
|
4536
4536
|
throw new Error(
|
|
4537
|
-
`[
|
|
4537
|
+
`[@lark/mvc error] bad each syntax: {{${code}}}. Expected "as" keyword, got "${tokens[1]}". Usage: {{each list as item [index]}}`
|
|
4538
4538
|
);
|
|
4539
4539
|
}
|
|
4540
4540
|
const restTokens = tokens.slice(2);
|
|
@@ -4556,12 +4556,12 @@ function convertArtExpression(code, debug, lineNo, blockStack = []) {
|
|
|
4556
4556
|
}
|
|
4557
4557
|
return `${debugPrefix}<%for(let ${index}=0${refExpr},${refObjCount}=${refObj}.length${lastCount};${index}<${refObjCount};${index}++){${firstAndLast}${valueDecl}%>`;
|
|
4558
4558
|
}
|
|
4559
|
-
case "
|
|
4560
|
-
blockStack.push({ ctrl: "
|
|
4559
|
+
case "parse": {
|
|
4560
|
+
blockStack.push({ ctrl: "parse", line: lineNo });
|
|
4561
4561
|
const object = tokens[0];
|
|
4562
4562
|
if (tokens.length > 1 && tokens[1] !== "as") {
|
|
4563
4563
|
throw new Error(
|
|
4564
|
-
`[
|
|
4564
|
+
`[@lark/mvc error] bad parse syntax: {{${code}}}. Expected "as" keyword, got "${tokens[1]}". Usage: {{for-in obj as val [key]}}`
|
|
4565
4565
|
);
|
|
4566
4566
|
}
|
|
4567
4567
|
const restTokens2 = tokens.slice(2);
|
|
@@ -4582,18 +4582,18 @@ function convertArtExpression(code, debug, lineNo, blockStack = []) {
|
|
|
4582
4582
|
return `${debugPrefix}<%let ${tokens.join(" ")};%>`;
|
|
4583
4583
|
case "/if":
|
|
4584
4584
|
case "/each":
|
|
4585
|
-
case "/
|
|
4585
|
+
case "/parse":
|
|
4586
4586
|
case "/for": {
|
|
4587
4587
|
const expectedCtrl = keyword.substring(1);
|
|
4588
4588
|
const last = blockStack.pop();
|
|
4589
4589
|
if (!last) {
|
|
4590
4590
|
throw new Error(
|
|
4591
|
-
`[
|
|
4591
|
+
`[@lark/mvc error(template] unexpected {{${code}}}: no matching open block`
|
|
4592
4592
|
);
|
|
4593
4593
|
}
|
|
4594
4594
|
if (last.ctrl !== expectedCtrl) {
|
|
4595
4595
|
throw new Error(
|
|
4596
|
-
`[
|
|
4596
|
+
`[@lark/mvc error(template] unexpected {{${code}}}: expected {{/${last.ctrl}}} to close block opened at line ${last.line}`
|
|
4597
4597
|
);
|
|
4598
4598
|
}
|
|
4599
4599
|
return `${debugPrefix}<%}%>`;
|
|
@@ -4670,12 +4670,12 @@ function compileToFunction(source, debug, file) {
|
|
|
4670
4670
|
index - 2
|
|
4671
4671
|
);
|
|
4672
4672
|
const x11 = String.fromCharCode(17);
|
|
4673
|
-
const
|
|
4674
|
-
const artM = expr.match(
|
|
4673
|
+
const artRegExp = new RegExp(`^'(\\d+)${x11}([^${x11}]+)${x11}'$`);
|
|
4674
|
+
const artM = expr.match(artRegExp);
|
|
4675
4675
|
let art = "";
|
|
4676
4676
|
let line = -1;
|
|
4677
4677
|
if (artM) {
|
|
4678
|
-
expr = expr.replace(
|
|
4678
|
+
expr = expr.replace(artRegExp, "");
|
|
4679
4679
|
art = artM[2];
|
|
4680
4680
|
line = parseInt(artM[1], 10);
|
|
4681
4681
|
} else {
|
|
@@ -4734,8 +4734,8 @@ function compileToFunction(source, debug, file) {
|
|
|
4734
4734
|
const filePart = file ? `\\r\\n\\tat file:${file}` : "";
|
|
4735
4735
|
funcSource = `let $expr,$art,$line;try{${funcSource}}catch(ex){let msg='render view error:'+(ex.message||ex);if($art)msg+='\\r\\n\\tsrc art:{{'+$art+'}}\\r\\n\\tat line:'+$line;msg+='\\r\\n\\t'+($art?'translate to:':'expr:');msg+=$expr+'${filePart}';throw msg;}`;
|
|
4736
4736
|
}
|
|
4737
|
-
const
|
|
4738
|
-
funcSource = funcSource.replace(
|
|
4737
|
+
const viewIdRegExp = new RegExp(String.fromCharCode(31), "g");
|
|
4738
|
+
funcSource = funcSource.replace(viewIdRegExp, `'+$viewId+'`);
|
|
4739
4739
|
const atRule = hasAtRule ? `if(!$i){$i=(ref,v,k,f)=>{for(f=ref[$g];--f;)if(ref[k=$g+f]===v)return k;ref[k=$g+ref[$g]++]=v;return k;}}` : "";
|
|
4740
4740
|
const encode = `if(!$n){let $em={'&':'amp','<':'lt','>':'gt','"':'#34','\\'':'#39','\`':'#96'},$er=/[&<>"'\`]/g,$ef=m=>'&'+$em[m]+';';$n=v=>''+(v==null?'':v);$e=v=>$n(v).replace($er,$ef)}`;
|
|
4741
4741
|
const encodeURIMore = `if(!$eu){let $um={'!':'%21','\\'':'%27','(':'%28',')':'%29','*':'%2A'},$uf=m=>$um[m],$uq=/[!')(*]/g;$eu=v=>encodeURIComponent($n(v)).replace($uq,$uf)}`;
|
|
@@ -4749,8 +4749,8 @@ function compileTemplate(source, options = {}) {
|
|
|
4749
4749
|
const { debug = false, globalVars = [], file } = options;
|
|
4750
4750
|
const { protectedSource, comments } = protectComments(source);
|
|
4751
4751
|
const converted = convertArtSyntax(protectedSource, debug);
|
|
4752
|
-
const
|
|
4753
|
-
const finalSource = restoreComments(
|
|
4752
|
+
const viewEventProcessed = processViewEvents(converted);
|
|
4753
|
+
const finalSource = restoreComments(viewEventProcessed, comments);
|
|
4754
4754
|
const funcBody = compileToFunction(finalSource, debug, file);
|
|
4755
4755
|
const varDeclarations = globalVars.map((key) => `,${key}=$$.${key}`).join("");
|
|
4756
4756
|
const funcWithVars = funcBody.replace("{{VARS}}", () => varDeclarations);
|
|
@@ -4768,20 +4768,20 @@ function compileTemplate(source, options = {}) {
|
|
|
4768
4768
|
}
|
|
4769
4769
|
function extractGlobalVars(source) {
|
|
4770
4770
|
const { protectedSource, comments: _comments } = protectComments(source);
|
|
4771
|
-
const
|
|
4772
|
-
const converted = convertArtSyntax(
|
|
4773
|
-
const
|
|
4774
|
-
const
|
|
4771
|
+
const viewEventProcessed = processViewEvents(protectedSource);
|
|
4772
|
+
const converted = convertArtSyntax(viewEventProcessed, false);
|
|
4773
|
+
const template = restoreComments(converted, _comments);
|
|
4774
|
+
const templateCmdRegExp = /<%([@=!:])?([\s\S]*?)%>|$/g;
|
|
4775
4775
|
const fnParts = [];
|
|
4776
4776
|
const htmlStore = {};
|
|
4777
4777
|
let htmlIndex = 0;
|
|
4778
4778
|
let lastIndex = 0;
|
|
4779
4779
|
const htmlKey = "";
|
|
4780
|
-
|
|
4781
|
-
|
|
4780
|
+
template.replace(
|
|
4781
|
+
templateCmdRegExp,
|
|
4782
4782
|
(match, operate, content, offset) => {
|
|
4783
4783
|
const start = operate ? 3 : 2;
|
|
4784
|
-
const htmlText =
|
|
4784
|
+
const htmlText = template.substring(lastIndex, offset + start);
|
|
4785
4785
|
const key = htmlKey + htmlIndex++ + htmlKey;
|
|
4786
4786
|
htmlStore[key] = htmlText;
|
|
4787
4787
|
lastIndex = offset + match.length - 2;
|
|
@@ -4866,17 +4866,17 @@ function extractGlobalVars(source) {
|
|
|
4866
4866
|
}
|
|
4867
4867
|
function fallbackExtractVariables(source) {
|
|
4868
4868
|
const vars = /* @__PURE__ */ new Set();
|
|
4869
|
-
const
|
|
4869
|
+
const outputRegExp = /\{\{[:=!@]\s*([a-zA-Z_$][\w$]*)[^}]*\}\}/g;
|
|
4870
4870
|
let m;
|
|
4871
|
-
while ((m =
|
|
4871
|
+
while ((m = outputRegExp.exec(source)) !== null) {
|
|
4872
4872
|
vars.add(m[1]);
|
|
4873
4873
|
}
|
|
4874
|
-
const
|
|
4875
|
-
while ((m =
|
|
4874
|
+
const eachRegExp = /\{\{each\s+([a-zA-Z_$][\w$]*)\s+as/g;
|
|
4875
|
+
while ((m = eachRegExp.exec(source)) !== null) {
|
|
4876
4876
|
vars.add(m[1]);
|
|
4877
4877
|
}
|
|
4878
|
-
const
|
|
4879
|
-
while ((m =
|
|
4878
|
+
const ifRegExp = /\{\{(?:else\s+)?if\s+([a-zA-Z_$][\w$]*)[^}]*\}\}/g;
|
|
4879
|
+
while ((m = ifRegExp.exec(source)) !== null) {
|
|
4880
4880
|
vars.add(m[1]);
|
|
4881
4881
|
}
|
|
4882
4882
|
return Array.from(vars).filter((v) => !BUILTIN_GLOBAL_SET.has(v));
|
|
@@ -4939,7 +4939,7 @@ var BUILTIN_GLOBALS = {
|
|
|
4939
4939
|
// {'&':'amp','<':'gt','>':'gt','"':'#34','\'':'#39','`':'#96'}
|
|
4940
4940
|
// Not a standalone function; referenced inside $e's closure.
|
|
4941
4941
|
$em: 1,
|
|
4942
|
-
// HTML entity RegExp — internal
|
|
4942
|
+
// HTML entity RegExp — internal regexp used by $e:
|
|
4943
4943
|
// /[&<>"'`]/g
|
|
4944
4944
|
$er: 1,
|
|
4945
4945
|
// HTML entity replacer function — internal helper used by $e:
|
|
@@ -4958,14 +4958,14 @@ var BUILTIN_GLOBALS = {
|
|
|
4958
4958
|
$i: 1,
|
|
4959
4959
|
// URI encoder: v => encodeURIComponent($n(v)).replace(/[!')(*]/g, extraMap)
|
|
4960
4960
|
// Extends encodeURIComponent with encoding of ! ' ( ) *.
|
|
4961
|
-
// Applied to values in
|
|
4961
|
+
// Applied to values in v-event URL parameters and {{!uri}} contexts.
|
|
4962
4962
|
$eu: 1,
|
|
4963
4963
|
// Quote encoder: v => $n(v).replace(/['"\\]/g, '\\$&')
|
|
4964
4964
|
// Escapes quotes and backslashes for safe embedding in HTML attribute
|
|
4965
4965
|
// values (e.g. data-json='...').
|
|
4966
4966
|
$eq: 1,
|
|
4967
4967
|
// View ID — the unique identifier of the owning View instance.
|
|
4968
|
-
// Injected into
|
|
4968
|
+
// Injected into v-event attribute values at render time so that
|
|
4969
4969
|
// EventDelegator can dispatch events to the correct View handler.
|
|
4970
4970
|
// The \x1f placeholder in compiled output is replaced with '+$viewId+'.
|
|
4971
4971
|
$viewId: 1,
|
|
@@ -5056,7 +5056,7 @@ var BUILTIN_GLOBAL_SET = new Set(Object.keys(BUILTIN_GLOBALS));
|
|
|
5056
5056
|
Bag,
|
|
5057
5057
|
CALL_BREAK_TIME,
|
|
5058
5058
|
Cache,
|
|
5059
|
-
|
|
5059
|
+
EVENT_METHOD_REGEXP,
|
|
5060
5060
|
EventDelegator,
|
|
5061
5061
|
EventEmitter,
|
|
5062
5062
|
Frame,
|
|
@@ -5070,10 +5070,10 @@ var BUILTIN_GLOBAL_SET = new Set(Object.keys(BUILTIN_GLOBALS));
|
|
|
5070
5070
|
State,
|
|
5071
5071
|
TAG_ATTR_KEY,
|
|
5072
5072
|
TAG_KEY,
|
|
5073
|
-
|
|
5073
|
+
TAG_NAME_REGEXP,
|
|
5074
5074
|
TAG_VIEW_KEY,
|
|
5075
5075
|
Updater,
|
|
5076
|
-
|
|
5076
|
+
VIEW_EVENT_METHOD_REGEXP,
|
|
5077
5077
|
View,
|
|
5078
5078
|
applyIdUpdates,
|
|
5079
5079
|
applyStyle,
|