@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
package/dist/vite.cjs
CHANGED
|
@@ -14609,7 +14609,7 @@ var require_lib = __commonJS({
|
|
|
14609
14609
|
var vite_exports = {};
|
|
14610
14610
|
__export(vite_exports, {
|
|
14611
14611
|
default: () => vite_default,
|
|
14612
|
-
|
|
14612
|
+
larkMvcPlugin: () => larkMvcPlugin
|
|
14613
14613
|
});
|
|
14614
14614
|
module.exports = __toCommonJS(vite_exports);
|
|
14615
14615
|
var import_path = __toESM(require("path"), 1);
|
|
@@ -14628,9 +14628,9 @@ function jsObjectToUrlParams(paramsStr) {
|
|
|
14628
14628
|
if (objMatch) {
|
|
14629
14629
|
const inner = objMatch[1];
|
|
14630
14630
|
const pairs = [];
|
|
14631
|
-
const
|
|
14631
|
+
const pairRegExp = /(\w+)\s*:\s*(?:'([^']*)'|"([^"]*)"|([^,}]+))/g;
|
|
14632
14632
|
let m;
|
|
14633
|
-
while ((m =
|
|
14633
|
+
while ((m = pairRegExp.exec(inner)) !== null) {
|
|
14634
14634
|
const key = m[1];
|
|
14635
14635
|
const value = m[2] ?? m[3] ?? m[4]?.trim() ?? "";
|
|
14636
14636
|
pairs.push(`${key}=${value}`);
|
|
@@ -14652,19 +14652,19 @@ function restoreComments(source, comments) {
|
|
|
14652
14652
|
return comments[parseInt(index, 10)];
|
|
14653
14653
|
});
|
|
14654
14654
|
}
|
|
14655
|
-
function
|
|
14655
|
+
function processViewEvents(source) {
|
|
14656
14656
|
return source.replace(
|
|
14657
|
-
/
|
|
14657
|
+
/v-(\w+)="([^"]+)"/g,
|
|
14658
14658
|
(fullAttr, eventName, attrValue) => {
|
|
14659
14659
|
const eventMatch = attrValue.match(/^(\w+)\((.*)\)$/s);
|
|
14660
14660
|
if (!eventMatch) return fullAttr;
|
|
14661
14661
|
const handlerName = eventMatch[1];
|
|
14662
14662
|
const paramsStr = eventMatch[2].trim();
|
|
14663
14663
|
if (!paramsStr) {
|
|
14664
|
-
return `
|
|
14664
|
+
return `v-${eventName}="${VIEW_ID_PLACEHOLDER}${SPLITTER}${handlerName}()"`;
|
|
14665
14665
|
}
|
|
14666
14666
|
const urlParams = jsObjectToUrlParams(paramsStr);
|
|
14667
|
-
return `
|
|
14667
|
+
return `v-${eventName}="${VIEW_ID_PLACEHOLDER}${SPLITTER}${handlerName}(${urlParams})"`;
|
|
14668
14668
|
}
|
|
14669
14669
|
);
|
|
14670
14670
|
}
|
|
@@ -14737,7 +14737,7 @@ function convertArtSyntax(source, debug) {
|
|
|
14737
14737
|
}
|
|
14738
14738
|
if (blockStack.length > 0) {
|
|
14739
14739
|
const unclosed = blockStack.map((b) => `"${b.ctrl}" at line ${b.line}`).join(", ");
|
|
14740
|
-
throw new Error(`[
|
|
14740
|
+
throw new Error(`[@lark/mvc error] unclosed block(s): ${unclosed}`);
|
|
14741
14741
|
}
|
|
14742
14742
|
return result.join("");
|
|
14743
14743
|
}
|
|
@@ -14836,7 +14836,7 @@ function convertArtExpression(code, debug, lineNo, blockStack = []) {
|
|
|
14836
14836
|
const object = tokens[0];
|
|
14837
14837
|
if (tokens.length > 1 && tokens[1] !== "as") {
|
|
14838
14838
|
throw new Error(
|
|
14839
|
-
`[
|
|
14839
|
+
`[@lark/mvc error] bad each syntax: {{${code}}}. Expected "as" keyword, got "${tokens[1]}". Usage: {{each list as item [index]}}`
|
|
14840
14840
|
);
|
|
14841
14841
|
}
|
|
14842
14842
|
const restTokens = tokens.slice(2);
|
|
@@ -14858,12 +14858,12 @@ function convertArtExpression(code, debug, lineNo, blockStack = []) {
|
|
|
14858
14858
|
}
|
|
14859
14859
|
return `${debugPrefix}<%for(let ${index}=0${refExpr},${refObjCount}=${refObj}.length${lastCount};${index}<${refObjCount};${index}++){${firstAndLast}${valueDecl}%>`;
|
|
14860
14860
|
}
|
|
14861
|
-
case "
|
|
14862
|
-
blockStack.push({ ctrl: "
|
|
14861
|
+
case "parse": {
|
|
14862
|
+
blockStack.push({ ctrl: "parse", line: lineNo });
|
|
14863
14863
|
const object = tokens[0];
|
|
14864
14864
|
if (tokens.length > 1 && tokens[1] !== "as") {
|
|
14865
14865
|
throw new Error(
|
|
14866
|
-
`[
|
|
14866
|
+
`[@lark/mvc error] bad parse syntax: {{${code}}}. Expected "as" keyword, got "${tokens[1]}". Usage: {{for-in obj as val [key]}}`
|
|
14867
14867
|
);
|
|
14868
14868
|
}
|
|
14869
14869
|
const restTokens2 = tokens.slice(2);
|
|
@@ -14884,18 +14884,18 @@ function convertArtExpression(code, debug, lineNo, blockStack = []) {
|
|
|
14884
14884
|
return `${debugPrefix}<%let ${tokens.join(" ")};%>`;
|
|
14885
14885
|
case "/if":
|
|
14886
14886
|
case "/each":
|
|
14887
|
-
case "/
|
|
14887
|
+
case "/parse":
|
|
14888
14888
|
case "/for": {
|
|
14889
14889
|
const expectedCtrl = keyword.substring(1);
|
|
14890
14890
|
const last = blockStack.pop();
|
|
14891
14891
|
if (!last) {
|
|
14892
14892
|
throw new Error(
|
|
14893
|
-
`[
|
|
14893
|
+
`[@lark/mvc error(template] unexpected {{${code}}}: no matching open block`
|
|
14894
14894
|
);
|
|
14895
14895
|
}
|
|
14896
14896
|
if (last.ctrl !== expectedCtrl) {
|
|
14897
14897
|
throw new Error(
|
|
14898
|
-
`[
|
|
14898
|
+
`[@lark/mvc error(template] unexpected {{${code}}}: expected {{/${last.ctrl}}} to close block opened at line ${last.line}`
|
|
14899
14899
|
);
|
|
14900
14900
|
}
|
|
14901
14901
|
return `${debugPrefix}<%}%>`;
|
|
@@ -14972,12 +14972,12 @@ function compileToFunction(source, debug, file) {
|
|
|
14972
14972
|
index - 2
|
|
14973
14973
|
);
|
|
14974
14974
|
const x11 = String.fromCharCode(17);
|
|
14975
|
-
const
|
|
14976
|
-
const artM = expr.match(
|
|
14975
|
+
const artRegExp = new RegExp(`^'(\\d+)${x11}([^${x11}]+)${x11}'$`);
|
|
14976
|
+
const artM = expr.match(artRegExp);
|
|
14977
14977
|
let art = "";
|
|
14978
14978
|
let line = -1;
|
|
14979
14979
|
if (artM) {
|
|
14980
|
-
expr = expr.replace(
|
|
14980
|
+
expr = expr.replace(artRegExp, "");
|
|
14981
14981
|
art = artM[2];
|
|
14982
14982
|
line = parseInt(artM[1], 10);
|
|
14983
14983
|
} else {
|
|
@@ -15036,8 +15036,8 @@ function compileToFunction(source, debug, file) {
|
|
|
15036
15036
|
const filePart = file ? `\\r\\n\\tat file:${file}` : "";
|
|
15037
15037
|
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;}`;
|
|
15038
15038
|
}
|
|
15039
|
-
const
|
|
15040
|
-
funcSource = funcSource.replace(
|
|
15039
|
+
const viewIdRegExp = new RegExp(String.fromCharCode(31), "g");
|
|
15040
|
+
funcSource = funcSource.replace(viewIdRegExp, `'+$viewId+'`);
|
|
15041
15041
|
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;}}` : "";
|
|
15042
15042
|
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)}`;
|
|
15043
15043
|
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)}`;
|
|
@@ -15051,8 +15051,8 @@ function compileTemplate(source, options = {}) {
|
|
|
15051
15051
|
const { debug = false, globalVars = [], file } = options;
|
|
15052
15052
|
const { protectedSource, comments } = protectComments(source);
|
|
15053
15053
|
const converted = convertArtSyntax(protectedSource, debug);
|
|
15054
|
-
const
|
|
15055
|
-
const finalSource = restoreComments(
|
|
15054
|
+
const viewEventProcessed = processViewEvents(converted);
|
|
15055
|
+
const finalSource = restoreComments(viewEventProcessed, comments);
|
|
15056
15056
|
const funcBody = compileToFunction(finalSource, debug, file);
|
|
15057
15057
|
const varDeclarations = globalVars.map((key) => `,${key}=$$.${key}`).join("");
|
|
15058
15058
|
const funcWithVars = funcBody.replace("{{VARS}}", () => varDeclarations);
|
|
@@ -15070,20 +15070,20 @@ function compileTemplate(source, options = {}) {
|
|
|
15070
15070
|
}
|
|
15071
15071
|
function extractGlobalVars(source) {
|
|
15072
15072
|
const { protectedSource, comments: _comments } = protectComments(source);
|
|
15073
|
-
const
|
|
15074
|
-
const converted = convertArtSyntax(
|
|
15075
|
-
const
|
|
15076
|
-
const
|
|
15073
|
+
const viewEventProcessed = processViewEvents(protectedSource);
|
|
15074
|
+
const converted = convertArtSyntax(viewEventProcessed, false);
|
|
15075
|
+
const template = restoreComments(converted, _comments);
|
|
15076
|
+
const templateCmdRegExp = /<%([@=!:])?([\s\S]*?)%>|$/g;
|
|
15077
15077
|
const fnParts = [];
|
|
15078
15078
|
const htmlStore = {};
|
|
15079
15079
|
let htmlIndex = 0;
|
|
15080
15080
|
let lastIndex = 0;
|
|
15081
15081
|
const htmlKey = "";
|
|
15082
|
-
|
|
15083
|
-
|
|
15082
|
+
template.replace(
|
|
15083
|
+
templateCmdRegExp,
|
|
15084
15084
|
(match, operate, content, offset) => {
|
|
15085
15085
|
const start = operate ? 3 : 2;
|
|
15086
|
-
const htmlText =
|
|
15086
|
+
const htmlText = template.substring(lastIndex, offset + start);
|
|
15087
15087
|
const key = htmlKey + htmlIndex++ + htmlKey;
|
|
15088
15088
|
htmlStore[key] = htmlText;
|
|
15089
15089
|
lastIndex = offset + match.length - 2;
|
|
@@ -15168,17 +15168,17 @@ function extractGlobalVars(source) {
|
|
|
15168
15168
|
}
|
|
15169
15169
|
function fallbackExtractVariables(source) {
|
|
15170
15170
|
const vars = /* @__PURE__ */ new Set();
|
|
15171
|
-
const
|
|
15171
|
+
const outputRegExp = /\{\{[:=!@]\s*([a-zA-Z_$][\w$]*)[^}]*\}\}/g;
|
|
15172
15172
|
let m;
|
|
15173
|
-
while ((m =
|
|
15173
|
+
while ((m = outputRegExp.exec(source)) !== null) {
|
|
15174
15174
|
vars.add(m[1]);
|
|
15175
15175
|
}
|
|
15176
|
-
const
|
|
15177
|
-
while ((m =
|
|
15176
|
+
const eachRegExp = /\{\{each\s+([a-zA-Z_$][\w$]*)\s+as/g;
|
|
15177
|
+
while ((m = eachRegExp.exec(source)) !== null) {
|
|
15178
15178
|
vars.add(m[1]);
|
|
15179
15179
|
}
|
|
15180
|
-
const
|
|
15181
|
-
while ((m =
|
|
15180
|
+
const ifRegExp = /\{\{(?:else\s+)?if\s+([a-zA-Z_$][\w$]*)[^}]*\}\}/g;
|
|
15181
|
+
while ((m = ifRegExp.exec(source)) !== null) {
|
|
15182
15182
|
vars.add(m[1]);
|
|
15183
15183
|
}
|
|
15184
15184
|
return Array.from(vars).filter((v) => !BUILTIN_GLOBAL_SET.has(v));
|
|
@@ -15241,7 +15241,7 @@ var BUILTIN_GLOBALS = {
|
|
|
15241
15241
|
// {'&':'amp','<':'gt','>':'gt','"':'#34','\'':'#39','`':'#96'}
|
|
15242
15242
|
// Not a standalone function; referenced inside $e's closure.
|
|
15243
15243
|
$em: 1,
|
|
15244
|
-
// HTML entity RegExp — internal
|
|
15244
|
+
// HTML entity RegExp — internal regexp used by $e:
|
|
15245
15245
|
// /[&<>"'`]/g
|
|
15246
15246
|
$er: 1,
|
|
15247
15247
|
// HTML entity replacer function — internal helper used by $e:
|
|
@@ -15260,14 +15260,14 @@ var BUILTIN_GLOBALS = {
|
|
|
15260
15260
|
$i: 1,
|
|
15261
15261
|
// URI encoder: v => encodeURIComponent($n(v)).replace(/[!')(*]/g, extraMap)
|
|
15262
15262
|
// Extends encodeURIComponent with encoding of ! ' ( ) *.
|
|
15263
|
-
// Applied to values in
|
|
15263
|
+
// Applied to values in v-event URL parameters and {{!uri}} contexts.
|
|
15264
15264
|
$eu: 1,
|
|
15265
15265
|
// Quote encoder: v => $n(v).replace(/['"\\]/g, '\\$&')
|
|
15266
15266
|
// Escapes quotes and backslashes for safe embedding in HTML attribute
|
|
15267
15267
|
// values (e.g. data-json='...').
|
|
15268
15268
|
$eq: 1,
|
|
15269
15269
|
// View ID — the unique identifier of the owning View instance.
|
|
15270
|
-
// Injected into
|
|
15270
|
+
// Injected into v-event attribute values at render time so that
|
|
15271
15271
|
// EventDelegator can dispatch events to the correct View handler.
|
|
15272
15272
|
// The \x1f placeholder in compiled output is replaced with '+$viewId+'.
|
|
15273
15273
|
$viewId: 1,
|
|
@@ -15355,21 +15355,21 @@ var BUILTIN_GLOBALS = {
|
|
|
15355
15355
|
var BUILTIN_GLOBAL_SET = new Set(Object.keys(BUILTIN_GLOBALS));
|
|
15356
15356
|
|
|
15357
15357
|
// src/vite.ts
|
|
15358
|
-
var
|
|
15359
|
-
function
|
|
15358
|
+
var LARK_TEMPLATE_SUFFIX = "?lark-template";
|
|
15359
|
+
function larkMvcPlugin(options = {}) {
|
|
15360
15360
|
const { debug = false } = options;
|
|
15361
15361
|
return {
|
|
15362
|
-
name: "lark-
|
|
15362
|
+
name: "lark-template",
|
|
15363
15363
|
enforce: "pre",
|
|
15364
15364
|
resolveId(source, importer) {
|
|
15365
15365
|
if (source.endsWith(".html") && importer) {
|
|
15366
|
-
return import_path.default.resolve(import_path.default.dirname(importer), source) +
|
|
15366
|
+
return import_path.default.resolve(import_path.default.dirname(importer), source) + LARK_TEMPLATE_SUFFIX;
|
|
15367
15367
|
}
|
|
15368
15368
|
return void 0;
|
|
15369
15369
|
},
|
|
15370
15370
|
load(id) {
|
|
15371
|
-
if (id.endsWith(
|
|
15372
|
-
const filePath = id.slice(0, -
|
|
15371
|
+
if (id.endsWith(LARK_TEMPLATE_SUFFIX)) {
|
|
15372
|
+
const filePath = id.slice(0, -LARK_TEMPLATE_SUFFIX.length);
|
|
15373
15373
|
const raw = import_fs.default.readFileSync(filePath, "utf-8");
|
|
15374
15374
|
const globalVars = extractGlobalVars(raw);
|
|
15375
15375
|
return compileTemplate(raw, { debug, globalVars });
|
|
@@ -15378,8 +15378,8 @@ function larkTmplPlugin(options = {}) {
|
|
|
15378
15378
|
}
|
|
15379
15379
|
};
|
|
15380
15380
|
}
|
|
15381
|
-
var vite_default =
|
|
15381
|
+
var vite_default = larkMvcPlugin;
|
|
15382
15382
|
// Annotate the CommonJS export names for ESM import in node:
|
|
15383
15383
|
0 && (module.exports = {
|
|
15384
|
-
|
|
15384
|
+
larkMvcPlugin
|
|
15385
15385
|
});
|
package/dist/vite.d.cts
CHANGED
|
@@ -8,7 +8,7 @@ import { Plugin } from 'vite';
|
|
|
8
8
|
*
|
|
9
9
|
* 0 configuration — just add the plugin and it works.
|
|
10
10
|
* - All template operators: = (escape), ! (raw), @ (ref lookup), : (binding)
|
|
11
|
-
* -
|
|
11
|
+
* - v-event attribute processing with $g prefix
|
|
12
12
|
* - $eu (URI encoding), $eq (quote encoding), $i (reference lookup)
|
|
13
13
|
* - Debug mode with line tracking
|
|
14
14
|
* - View ID injection
|
|
@@ -16,10 +16,10 @@ import { Plugin } from 'vite';
|
|
|
16
16
|
*
|
|
17
17
|
* Usage in vite.config.ts:
|
|
18
18
|
* ```ts
|
|
19
|
-
* import {
|
|
19
|
+
* import { larkMvcPlugin } from '@lark/framework/vite-plugin';
|
|
20
20
|
*
|
|
21
21
|
* export default defineConfig({
|
|
22
|
-
* plugins: [
|
|
22
|
+
* plugins: [larkMvcPlugin()],
|
|
23
23
|
* });
|
|
24
24
|
* ```
|
|
25
25
|
*/
|
|
@@ -31,8 +31,8 @@ import { Plugin } from 'vite';
|
|
|
31
31
|
* @param options.debug - Enable debug mode with line tracking (default: false)
|
|
32
32
|
* @returns Vite plugin instance
|
|
33
33
|
*/
|
|
34
|
-
declare function
|
|
34
|
+
declare function larkMvcPlugin(options?: {
|
|
35
35
|
debug?: boolean;
|
|
36
36
|
}): Plugin;
|
|
37
37
|
|
|
38
|
-
export {
|
|
38
|
+
export { larkMvcPlugin as default, larkMvcPlugin };
|
package/dist/vite.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ import { Plugin } from 'vite';
|
|
|
8
8
|
*
|
|
9
9
|
* 0 configuration — just add the plugin and it works.
|
|
10
10
|
* - All template operators: = (escape), ! (raw), @ (ref lookup), : (binding)
|
|
11
|
-
* -
|
|
11
|
+
* - v-event attribute processing with $g prefix
|
|
12
12
|
* - $eu (URI encoding), $eq (quote encoding), $i (reference lookup)
|
|
13
13
|
* - Debug mode with line tracking
|
|
14
14
|
* - View ID injection
|
|
@@ -16,10 +16,10 @@ import { Plugin } from 'vite';
|
|
|
16
16
|
*
|
|
17
17
|
* Usage in vite.config.ts:
|
|
18
18
|
* ```ts
|
|
19
|
-
* import {
|
|
19
|
+
* import { larkMvcPlugin } from '@lark/framework/vite-plugin';
|
|
20
20
|
*
|
|
21
21
|
* export default defineConfig({
|
|
22
|
-
* plugins: [
|
|
22
|
+
* plugins: [larkMvcPlugin()],
|
|
23
23
|
* });
|
|
24
24
|
* ```
|
|
25
25
|
*/
|
|
@@ -31,8 +31,8 @@ import { Plugin } from 'vite';
|
|
|
31
31
|
* @param options.debug - Enable debug mode with line tracking (default: false)
|
|
32
32
|
* @returns Vite plugin instance
|
|
33
33
|
*/
|
|
34
|
-
declare function
|
|
34
|
+
declare function larkMvcPlugin(options?: {
|
|
35
35
|
debug?: boolean;
|
|
36
36
|
}): Plugin;
|
|
37
37
|
|
|
38
|
-
export {
|
|
38
|
+
export { larkMvcPlugin as default, larkMvcPlugin };
|
package/dist/vite.js
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
import {
|
|
2
2
|
compileTemplate,
|
|
3
3
|
extractGlobalVars
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-5OEHRF3U.js";
|
|
5
5
|
|
|
6
6
|
// src/vite.ts
|
|
7
7
|
import path from "path";
|
|
8
8
|
import fs from "fs";
|
|
9
|
-
var
|
|
10
|
-
function
|
|
9
|
+
var LARK_TEMPLATE_SUFFIX = "?lark-template";
|
|
10
|
+
function larkMvcPlugin(options = {}) {
|
|
11
11
|
const { debug = false } = options;
|
|
12
12
|
return {
|
|
13
|
-
name: "lark-
|
|
13
|
+
name: "lark-template",
|
|
14
14
|
enforce: "pre",
|
|
15
15
|
resolveId(source, importer) {
|
|
16
16
|
if (source.endsWith(".html") && importer) {
|
|
17
|
-
return path.resolve(path.dirname(importer), source) +
|
|
17
|
+
return path.resolve(path.dirname(importer), source) + LARK_TEMPLATE_SUFFIX;
|
|
18
18
|
}
|
|
19
19
|
return void 0;
|
|
20
20
|
},
|
|
21
21
|
load(id) {
|
|
22
|
-
if (id.endsWith(
|
|
23
|
-
const filePath = id.slice(0, -
|
|
22
|
+
if (id.endsWith(LARK_TEMPLATE_SUFFIX)) {
|
|
23
|
+
const filePath = id.slice(0, -LARK_TEMPLATE_SUFFIX.length);
|
|
24
24
|
const raw = fs.readFileSync(filePath, "utf-8");
|
|
25
25
|
const globalVars = extractGlobalVars(raw);
|
|
26
26
|
return compileTemplate(raw, { debug, globalVars });
|
|
@@ -29,8 +29,8 @@ function larkTmplPlugin(options = {}) {
|
|
|
29
29
|
}
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
|
-
var vite_default =
|
|
32
|
+
var vite_default = larkMvcPlugin;
|
|
33
33
|
export {
|
|
34
34
|
vite_default as default,
|
|
35
|
-
|
|
35
|
+
larkMvcPlugin
|
|
36
36
|
};
|
package/dist/webpack.cjs
CHANGED
|
@@ -14609,7 +14609,7 @@ var require_lib = __commonJS({
|
|
|
14609
14609
|
var webpack_exports = {};
|
|
14610
14610
|
__export(webpack_exports, {
|
|
14611
14611
|
default: () => webpack_default,
|
|
14612
|
-
|
|
14612
|
+
larkMvcLoader: () => larkMvcLoader
|
|
14613
14613
|
});
|
|
14614
14614
|
module.exports = __toCommonJS(webpack_exports);
|
|
14615
14615
|
|
|
@@ -14626,9 +14626,9 @@ function jsObjectToUrlParams(paramsStr) {
|
|
|
14626
14626
|
if (objMatch) {
|
|
14627
14627
|
const inner = objMatch[1];
|
|
14628
14628
|
const pairs = [];
|
|
14629
|
-
const
|
|
14629
|
+
const pairRegExp = /(\w+)\s*:\s*(?:'([^']*)'|"([^"]*)"|([^,}]+))/g;
|
|
14630
14630
|
let m;
|
|
14631
|
-
while ((m =
|
|
14631
|
+
while ((m = pairRegExp.exec(inner)) !== null) {
|
|
14632
14632
|
const key = m[1];
|
|
14633
14633
|
const value = m[2] ?? m[3] ?? m[4]?.trim() ?? "";
|
|
14634
14634
|
pairs.push(`${key}=${value}`);
|
|
@@ -14650,19 +14650,19 @@ function restoreComments(source, comments) {
|
|
|
14650
14650
|
return comments[parseInt(index, 10)];
|
|
14651
14651
|
});
|
|
14652
14652
|
}
|
|
14653
|
-
function
|
|
14653
|
+
function processViewEvents(source) {
|
|
14654
14654
|
return source.replace(
|
|
14655
|
-
/
|
|
14655
|
+
/v-(\w+)="([^"]+)"/g,
|
|
14656
14656
|
(fullAttr, eventName, attrValue) => {
|
|
14657
14657
|
const eventMatch = attrValue.match(/^(\w+)\((.*)\)$/s);
|
|
14658
14658
|
if (!eventMatch) return fullAttr;
|
|
14659
14659
|
const handlerName = eventMatch[1];
|
|
14660
14660
|
const paramsStr = eventMatch[2].trim();
|
|
14661
14661
|
if (!paramsStr) {
|
|
14662
|
-
return `
|
|
14662
|
+
return `v-${eventName}="${VIEW_ID_PLACEHOLDER}${SPLITTER}${handlerName}()"`;
|
|
14663
14663
|
}
|
|
14664
14664
|
const urlParams = jsObjectToUrlParams(paramsStr);
|
|
14665
|
-
return `
|
|
14665
|
+
return `v-${eventName}="${VIEW_ID_PLACEHOLDER}${SPLITTER}${handlerName}(${urlParams})"`;
|
|
14666
14666
|
}
|
|
14667
14667
|
);
|
|
14668
14668
|
}
|
|
@@ -14735,7 +14735,7 @@ function convertArtSyntax(source, debug) {
|
|
|
14735
14735
|
}
|
|
14736
14736
|
if (blockStack.length > 0) {
|
|
14737
14737
|
const unclosed = blockStack.map((b) => `"${b.ctrl}" at line ${b.line}`).join(", ");
|
|
14738
|
-
throw new Error(`[
|
|
14738
|
+
throw new Error(`[@lark/mvc error] unclosed block(s): ${unclosed}`);
|
|
14739
14739
|
}
|
|
14740
14740
|
return result.join("");
|
|
14741
14741
|
}
|
|
@@ -14834,7 +14834,7 @@ function convertArtExpression(code, debug, lineNo, blockStack = []) {
|
|
|
14834
14834
|
const object = tokens[0];
|
|
14835
14835
|
if (tokens.length > 1 && tokens[1] !== "as") {
|
|
14836
14836
|
throw new Error(
|
|
14837
|
-
`[
|
|
14837
|
+
`[@lark/mvc error] bad each syntax: {{${code}}}. Expected "as" keyword, got "${tokens[1]}". Usage: {{each list as item [index]}}`
|
|
14838
14838
|
);
|
|
14839
14839
|
}
|
|
14840
14840
|
const restTokens = tokens.slice(2);
|
|
@@ -14856,12 +14856,12 @@ function convertArtExpression(code, debug, lineNo, blockStack = []) {
|
|
|
14856
14856
|
}
|
|
14857
14857
|
return `${debugPrefix}<%for(let ${index}=0${refExpr},${refObjCount}=${refObj}.length${lastCount};${index}<${refObjCount};${index}++){${firstAndLast}${valueDecl}%>`;
|
|
14858
14858
|
}
|
|
14859
|
-
case "
|
|
14860
|
-
blockStack.push({ ctrl: "
|
|
14859
|
+
case "parse": {
|
|
14860
|
+
blockStack.push({ ctrl: "parse", line: lineNo });
|
|
14861
14861
|
const object = tokens[0];
|
|
14862
14862
|
if (tokens.length > 1 && tokens[1] !== "as") {
|
|
14863
14863
|
throw new Error(
|
|
14864
|
-
`[
|
|
14864
|
+
`[@lark/mvc error] bad parse syntax: {{${code}}}. Expected "as" keyword, got "${tokens[1]}". Usage: {{for-in obj as val [key]}}`
|
|
14865
14865
|
);
|
|
14866
14866
|
}
|
|
14867
14867
|
const restTokens2 = tokens.slice(2);
|
|
@@ -14882,18 +14882,18 @@ function convertArtExpression(code, debug, lineNo, blockStack = []) {
|
|
|
14882
14882
|
return `${debugPrefix}<%let ${tokens.join(" ")};%>`;
|
|
14883
14883
|
case "/if":
|
|
14884
14884
|
case "/each":
|
|
14885
|
-
case "/
|
|
14885
|
+
case "/parse":
|
|
14886
14886
|
case "/for": {
|
|
14887
14887
|
const expectedCtrl = keyword.substring(1);
|
|
14888
14888
|
const last = blockStack.pop();
|
|
14889
14889
|
if (!last) {
|
|
14890
14890
|
throw new Error(
|
|
14891
|
-
`[
|
|
14891
|
+
`[@lark/mvc error(template] unexpected {{${code}}}: no matching open block`
|
|
14892
14892
|
);
|
|
14893
14893
|
}
|
|
14894
14894
|
if (last.ctrl !== expectedCtrl) {
|
|
14895
14895
|
throw new Error(
|
|
14896
|
-
`[
|
|
14896
|
+
`[@lark/mvc error(template] unexpected {{${code}}}: expected {{/${last.ctrl}}} to close block opened at line ${last.line}`
|
|
14897
14897
|
);
|
|
14898
14898
|
}
|
|
14899
14899
|
return `${debugPrefix}<%}%>`;
|
|
@@ -14970,12 +14970,12 @@ function compileToFunction(source, debug, file) {
|
|
|
14970
14970
|
index - 2
|
|
14971
14971
|
);
|
|
14972
14972
|
const x11 = String.fromCharCode(17);
|
|
14973
|
-
const
|
|
14974
|
-
const artM = expr.match(
|
|
14973
|
+
const artRegExp = new RegExp(`^'(\\d+)${x11}([^${x11}]+)${x11}'$`);
|
|
14974
|
+
const artM = expr.match(artRegExp);
|
|
14975
14975
|
let art = "";
|
|
14976
14976
|
let line = -1;
|
|
14977
14977
|
if (artM) {
|
|
14978
|
-
expr = expr.replace(
|
|
14978
|
+
expr = expr.replace(artRegExp, "");
|
|
14979
14979
|
art = artM[2];
|
|
14980
14980
|
line = parseInt(artM[1], 10);
|
|
14981
14981
|
} else {
|
|
@@ -15034,8 +15034,8 @@ function compileToFunction(source, debug, file) {
|
|
|
15034
15034
|
const filePart = file ? `\\r\\n\\tat file:${file}` : "";
|
|
15035
15035
|
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;}`;
|
|
15036
15036
|
}
|
|
15037
|
-
const
|
|
15038
|
-
funcSource = funcSource.replace(
|
|
15037
|
+
const viewIdRegExp = new RegExp(String.fromCharCode(31), "g");
|
|
15038
|
+
funcSource = funcSource.replace(viewIdRegExp, `'+$viewId+'`);
|
|
15039
15039
|
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;}}` : "";
|
|
15040
15040
|
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)}`;
|
|
15041
15041
|
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)}`;
|
|
@@ -15049,8 +15049,8 @@ function compileTemplate(source, options = {}) {
|
|
|
15049
15049
|
const { debug = false, globalVars = [], file } = options;
|
|
15050
15050
|
const { protectedSource, comments } = protectComments(source);
|
|
15051
15051
|
const converted = convertArtSyntax(protectedSource, debug);
|
|
15052
|
-
const
|
|
15053
|
-
const finalSource = restoreComments(
|
|
15052
|
+
const viewEventProcessed = processViewEvents(converted);
|
|
15053
|
+
const finalSource = restoreComments(viewEventProcessed, comments);
|
|
15054
15054
|
const funcBody = compileToFunction(finalSource, debug, file);
|
|
15055
15055
|
const varDeclarations = globalVars.map((key) => `,${key}=$$.${key}`).join("");
|
|
15056
15056
|
const funcWithVars = funcBody.replace("{{VARS}}", () => varDeclarations);
|
|
@@ -15068,20 +15068,20 @@ function compileTemplate(source, options = {}) {
|
|
|
15068
15068
|
}
|
|
15069
15069
|
function extractGlobalVars(source) {
|
|
15070
15070
|
const { protectedSource, comments: _comments } = protectComments(source);
|
|
15071
|
-
const
|
|
15072
|
-
const converted = convertArtSyntax(
|
|
15073
|
-
const
|
|
15074
|
-
const
|
|
15071
|
+
const viewEventProcessed = processViewEvents(protectedSource);
|
|
15072
|
+
const converted = convertArtSyntax(viewEventProcessed, false);
|
|
15073
|
+
const template = restoreComments(converted, _comments);
|
|
15074
|
+
const templateCmdRegExp = /<%([@=!:])?([\s\S]*?)%>|$/g;
|
|
15075
15075
|
const fnParts = [];
|
|
15076
15076
|
const htmlStore = {};
|
|
15077
15077
|
let htmlIndex = 0;
|
|
15078
15078
|
let lastIndex = 0;
|
|
15079
15079
|
const htmlKey = "";
|
|
15080
|
-
|
|
15081
|
-
|
|
15080
|
+
template.replace(
|
|
15081
|
+
templateCmdRegExp,
|
|
15082
15082
|
(match, operate, content, offset) => {
|
|
15083
15083
|
const start = operate ? 3 : 2;
|
|
15084
|
-
const htmlText =
|
|
15084
|
+
const htmlText = template.substring(lastIndex, offset + start);
|
|
15085
15085
|
const key = htmlKey + htmlIndex++ + htmlKey;
|
|
15086
15086
|
htmlStore[key] = htmlText;
|
|
15087
15087
|
lastIndex = offset + match.length - 2;
|
|
@@ -15166,17 +15166,17 @@ function extractGlobalVars(source) {
|
|
|
15166
15166
|
}
|
|
15167
15167
|
function fallbackExtractVariables(source) {
|
|
15168
15168
|
const vars = /* @__PURE__ */ new Set();
|
|
15169
|
-
const
|
|
15169
|
+
const outputRegExp = /\{\{[:=!@]\s*([a-zA-Z_$][\w$]*)[^}]*\}\}/g;
|
|
15170
15170
|
let m;
|
|
15171
|
-
while ((m =
|
|
15171
|
+
while ((m = outputRegExp.exec(source)) !== null) {
|
|
15172
15172
|
vars.add(m[1]);
|
|
15173
15173
|
}
|
|
15174
|
-
const
|
|
15175
|
-
while ((m =
|
|
15174
|
+
const eachRegExp = /\{\{each\s+([a-zA-Z_$][\w$]*)\s+as/g;
|
|
15175
|
+
while ((m = eachRegExp.exec(source)) !== null) {
|
|
15176
15176
|
vars.add(m[1]);
|
|
15177
15177
|
}
|
|
15178
|
-
const
|
|
15179
|
-
while ((m =
|
|
15178
|
+
const ifRegExp = /\{\{(?:else\s+)?if\s+([a-zA-Z_$][\w$]*)[^}]*\}\}/g;
|
|
15179
|
+
while ((m = ifRegExp.exec(source)) !== null) {
|
|
15180
15180
|
vars.add(m[1]);
|
|
15181
15181
|
}
|
|
15182
15182
|
return Array.from(vars).filter((v) => !BUILTIN_GLOBAL_SET.has(v));
|
|
@@ -15239,7 +15239,7 @@ var BUILTIN_GLOBALS = {
|
|
|
15239
15239
|
// {'&':'amp','<':'gt','>':'gt','"':'#34','\'':'#39','`':'#96'}
|
|
15240
15240
|
// Not a standalone function; referenced inside $e's closure.
|
|
15241
15241
|
$em: 1,
|
|
15242
|
-
// HTML entity RegExp — internal
|
|
15242
|
+
// HTML entity RegExp — internal regexp used by $e:
|
|
15243
15243
|
// /[&<>"'`]/g
|
|
15244
15244
|
$er: 1,
|
|
15245
15245
|
// HTML entity replacer function — internal helper used by $e:
|
|
@@ -15258,14 +15258,14 @@ var BUILTIN_GLOBALS = {
|
|
|
15258
15258
|
$i: 1,
|
|
15259
15259
|
// URI encoder: v => encodeURIComponent($n(v)).replace(/[!')(*]/g, extraMap)
|
|
15260
15260
|
// Extends encodeURIComponent with encoding of ! ' ( ) *.
|
|
15261
|
-
// Applied to values in
|
|
15261
|
+
// Applied to values in v-event URL parameters and {{!uri}} contexts.
|
|
15262
15262
|
$eu: 1,
|
|
15263
15263
|
// Quote encoder: v => $n(v).replace(/['"\\]/g, '\\$&')
|
|
15264
15264
|
// Escapes quotes and backslashes for safe embedding in HTML attribute
|
|
15265
15265
|
// values (e.g. data-json='...').
|
|
15266
15266
|
$eq: 1,
|
|
15267
15267
|
// View ID — the unique identifier of the owning View instance.
|
|
15268
|
-
// Injected into
|
|
15268
|
+
// Injected into v-event attribute values at render time so that
|
|
15269
15269
|
// EventDelegator can dispatch events to the correct View handler.
|
|
15270
15270
|
// The \x1f placeholder in compiled output is replaced with '+$viewId+'.
|
|
15271
15271
|
$viewId: 1,
|
|
@@ -15353,7 +15353,7 @@ var BUILTIN_GLOBALS = {
|
|
|
15353
15353
|
var BUILTIN_GLOBAL_SET = new Set(Object.keys(BUILTIN_GLOBALS));
|
|
15354
15354
|
|
|
15355
15355
|
// src/webpack.ts
|
|
15356
|
-
function
|
|
15356
|
+
function larkMvcLoader(source) {
|
|
15357
15357
|
const options = this.getOptions();
|
|
15358
15358
|
const debug = options.debug ?? false;
|
|
15359
15359
|
try {
|
|
@@ -15364,8 +15364,8 @@ function larkTmplLoader(source) {
|
|
|
15364
15364
|
this.callback(error instanceof Error ? error : new Error(String(error)));
|
|
15365
15365
|
}
|
|
15366
15366
|
}
|
|
15367
|
-
var webpack_default =
|
|
15367
|
+
var webpack_default = larkMvcLoader;
|
|
15368
15368
|
// Annotate the CommonJS export names for ESM import in node:
|
|
15369
15369
|
0 && (module.exports = {
|
|
15370
|
-
|
|
15370
|
+
larkMvcLoader
|
|
15371
15371
|
});
|
package/dist/webpack.d.cts
CHANGED
|
@@ -13,6 +13,6 @@ interface LoaderContext {
|
|
|
13
13
|
* Webpack loader entry point.
|
|
14
14
|
* Compiles .html template files into JS function modules.
|
|
15
15
|
*/
|
|
16
|
-
declare function
|
|
16
|
+
declare function larkMvcLoader(this: LoaderContext, source: string): void;
|
|
17
17
|
|
|
18
|
-
export {
|
|
18
|
+
export { larkMvcLoader as default, larkMvcLoader };
|
package/dist/webpack.d.ts
CHANGED
|
@@ -13,6 +13,6 @@ interface LoaderContext {
|
|
|
13
13
|
* Webpack loader entry point.
|
|
14
14
|
* Compiles .html template files into JS function modules.
|
|
15
15
|
*/
|
|
16
|
-
declare function
|
|
16
|
+
declare function larkMvcLoader(this: LoaderContext, source: string): void;
|
|
17
17
|
|
|
18
|
-
export {
|
|
18
|
+
export { larkMvcLoader as default, larkMvcLoader };
|
package/dist/webpack.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
compileTemplate,
|
|
3
3
|
extractGlobalVars
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-5OEHRF3U.js";
|
|
5
5
|
|
|
6
6
|
// src/webpack.ts
|
|
7
|
-
function
|
|
7
|
+
function larkMvcLoader(source) {
|
|
8
8
|
const options = this.getOptions();
|
|
9
9
|
const debug = options.debug ?? false;
|
|
10
10
|
try {
|
|
@@ -15,8 +15,8 @@ function larkTmplLoader(source) {
|
|
|
15
15
|
this.callback(error instanceof Error ? error : new Error(String(error)));
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
|
-
var webpack_default =
|
|
18
|
+
var webpack_default = larkMvcLoader;
|
|
19
19
|
export {
|
|
20
20
|
webpack_default as default,
|
|
21
|
-
|
|
21
|
+
larkMvcLoader
|
|
22
22
|
};
|