@lark.js/mvc 0.0.1 → 0.0.3
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-Y72BUONO.js} +38 -39
- package/dist/index.cjs +236 -125
- package/dist/index.d.cts +89 -29
- package/dist/index.d.ts +89 -29
- package/dist/index.js +231 -119
- package/dist/vite.cjs +47 -48
- package/dist/vite.d.cts +5 -5
- package/dist/vite.d.ts +5 -5
- package/dist/vite.js +9 -9
- package/dist/webpack.cjs +42 -43
- package/dist/webpack.d.cts +2 -2
- package/dist/webpack.d.ts +2 -2
- package/dist/webpack.js +4 -4
- package/package.json +8 -3
|
@@ -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
|
+
/@(\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 `@${eventName}="${VIEW_ID_PLACEHOLDER}${SPLITTER}${handlerName}()"`;
|
|
14649
14649
|
}
|
|
14650
14650
|
const urlParams = jsObjectToUrlParams(paramsStr);
|
|
14651
|
-
return
|
|
14651
|
+
return `@${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] 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] 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:
|
|
@@ -15239,19 +15239,18 @@ var BUILTIN_GLOBALS = {
|
|
|
15239
15239
|
// Reference lookup: (refData, value) => key
|
|
15240
15240
|
// Finds or allocates a SPLITTER-prefixed key in refData for a given
|
|
15241
15241
|
// object reference. Used by {{@ref}} operator for passing object
|
|
15242
|
-
// references to child views via lark
|
|
15243
|
-
// Aligned with mx.js Updater_Ref.
|
|
15242
|
+
// references to child views via v-lark attributes.
|
|
15244
15243
|
$i: 1,
|
|
15245
15244
|
// URI encoder: v => encodeURIComponent($n(v)).replace(/[!')(*]/g, extraMap)
|
|
15246
15245
|
// Extends encodeURIComponent with encoding of ! ' ( ) *.
|
|
15247
|
-
// Applied to values in
|
|
15246
|
+
// Applied to values in @event URL parameters and {{!uri}} contexts.
|
|
15248
15247
|
$eu: 1,
|
|
15249
15248
|
// Quote encoder: v => $n(v).replace(/['"\\]/g, '\\$&')
|
|
15250
15249
|
// Escapes quotes and backslashes for safe embedding in HTML attribute
|
|
15251
15250
|
// values (e.g. data-json='...').
|
|
15252
15251
|
$eq: 1,
|
|
15253
15252
|
// View ID — the unique identifier of the owning View instance.
|
|
15254
|
-
// Injected into
|
|
15253
|
+
// Injected into @event attribute values at render time so that
|
|
15255
15254
|
// EventDelegator can dispatch events to the correct View handler.
|
|
15256
15255
|
// The \x1f placeholder in compiled output is replaced with '+$viewId+'.
|
|
15257
15256
|
$viewId: 1,
|