@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.
@@ -14612,9 +14612,9 @@ function jsObjectToUrlParams(paramsStr) {
14612
14612
  if (objMatch) {
14613
14613
  const inner = objMatch[1];
14614
14614
  const pairs = [];
14615
- const pairRegex = /(\w+)\s*:\s*(?:'([^']*)'|"([^"]*)"|([^,}]+))/g;
14615
+ const pairRegExp = /(\w+)\s*:\s*(?:'([^']*)'|"([^"]*)"|([^,}]+))/g;
14616
14616
  let m;
14617
- while ((m = pairRegex.exec(inner)) !== null) {
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 processLarkEvents(source) {
14639
+ function processViewEvents(source) {
14640
14640
  return source.replace(
14641
- /lark-(\w+)="([^"]+)"/g,
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 `lark-${eventName}="${VIEW_ID_PLACEHOLDER}${SPLITTER}${handlerName}()"`;
14648
+ return `@${eventName}="${VIEW_ID_PLACEHOLDER}${SPLITTER}${handlerName}()"`;
14649
14649
  }
14650
14650
  const urlParams = jsObjectToUrlParams(paramsStr);
14651
- return `lark-${eventName}="${VIEW_ID_PLACEHOLDER}${SPLITTER}${handlerName}(${urlParams})"`;
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(`[Lark Error(tmpl-art)] unclosed block(s): ${unclosed}`);
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
- `[Lark Error(tmpl-art)] bad each syntax: {{${code}}}. Expected "as" keyword, got "${tokens[1]}". Usage: {{each list as item [index]}}`
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 "forin": {
14846
- blockStack.push({ ctrl: "forin", line: lineNo });
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
- `[Lark Error(tmpl-art)] bad forin syntax: {{${code}}}. Expected "as" keyword, got "${tokens[1]}". Usage: {{forin obj as val [key]}}`
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 "/forin":
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
- `[Lark Error(tmpl-art)] unexpected {{${code}}}: no matching open block`
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
- `[Lark Error(tmpl-art)] unexpected {{${code}}}: expected {{/${last.ctrl}}} to close block opened at line ${last.line}`
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 artReg = new RegExp(`^'(\\d+)${x11}([^${x11}]+)${x11}'$`);
14960
- const artM = expr.match(artReg);
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(artReg, "");
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 viewIdReg = new RegExp(String.fromCharCode(31), "g");
15024
- funcSource = funcSource.replace(viewIdReg, `'+$viewId+'`);
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 larkEventProcessed = processLarkEvents(converted);
15039
- const finalSource = restoreComments(larkEventProcessed, comments);
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 larkEventProcessed = processLarkEvents(protectedSource);
15058
- const converted = convertArtSyntax(larkEventProcessed, false);
15059
- const tmpl = restoreComments(converted, _comments);
15060
- const tmplCmdReg = /<%([@=!:])?([\s\S]*?)%>|$/g;
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
- tmpl.replace(
15067
- tmplCmdReg,
15066
+ template.replace(
15067
+ templateCmdRegExp,
15068
15068
  (match, operate, content, offset) => {
15069
15069
  const start = operate ? 3 : 2;
15070
- const htmlText = tmpl.substring(lastIndex, offset + start);
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 outputReg = /\{\{[:=!@]\s*([a-zA-Z_$][\w$]*)[^}]*\}\}/g;
15155
+ const outputRegExp = /\{\{[:=!@]\s*([a-zA-Z_$][\w$]*)[^}]*\}\}/g;
15156
15156
  let m;
15157
- while ((m = outputReg.exec(source)) !== null) {
15157
+ while ((m = outputRegExp.exec(source)) !== null) {
15158
15158
  vars.add(m[1]);
15159
15159
  }
15160
- const eachReg = /\{\{each\s+([a-zA-Z_$][\w$]*)\s+as/g;
15161
- while ((m = eachReg.exec(source)) !== null) {
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 ifReg = /\{\{(?:else\s+)?if\s+([a-zA-Z_$][\w$]*)[^}]*\}\}/g;
15165
- while ((m = ifReg.exec(source)) !== null) {
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 regex used by $e:
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-view attributes.
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 lark-event URL parameters and {{!uri}} contexts.
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 lark-event attribute values at render time so that
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,