@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/index.d.cts
CHANGED
|
@@ -155,7 +155,7 @@ interface ViewInstance {
|
|
|
155
155
|
/** Whether rendered at least once */
|
|
156
156
|
rendered?: boolean;
|
|
157
157
|
/** Whether view has template */
|
|
158
|
-
|
|
158
|
+
template?: AnyFunc | string;
|
|
159
159
|
/** Location observation config */
|
|
160
160
|
locationObserved: ViewLocationObserved;
|
|
161
161
|
/** Observed state keys */
|
|
@@ -439,11 +439,11 @@ declare const LARK_VIEW = "lark-view";
|
|
|
439
439
|
* Group 2: handler name
|
|
440
440
|
* Group 3: params string
|
|
441
441
|
*/
|
|
442
|
-
declare const
|
|
442
|
+
declare const EVENT_METHOD_REGEXP: RegExp;
|
|
443
443
|
/** View event method name regex: e.g. "name<click,mousedown>" or "$selector<click>" */
|
|
444
|
-
declare const
|
|
445
|
-
/** Tag name
|
|
446
|
-
declare const
|
|
444
|
+
declare const VIEW_EVENT_METHOD_REGEXP: RegExp;
|
|
445
|
+
/** Tag name regexp for I_GetNode */
|
|
446
|
+
declare const TAG_NAME_REGEXP: RegExp;
|
|
447
447
|
/** Async task break time (ms) */
|
|
448
448
|
declare const CALL_BREAK_TIME = 48;
|
|
449
449
|
/** Increment global counter and return new value */
|
|
@@ -665,7 +665,7 @@ declare class View {
|
|
|
665
665
|
/** Whether rendered at least once */
|
|
666
666
|
rendered?: boolean;
|
|
667
667
|
/** Whether view has template */
|
|
668
|
-
|
|
668
|
+
template?: AnyFunc | string;
|
|
669
669
|
/** Location observation config */
|
|
670
670
|
locationObserved: ViewLocationObserved;
|
|
671
671
|
/** Observed state keys */
|
|
@@ -813,8 +813,8 @@ declare class Frame extends EventEmitter implements FrameLike {
|
|
|
813
813
|
* 5. Create View instance
|
|
814
814
|
* 6. View_DelegateEvents (bind DOM events)
|
|
815
815
|
* 7. Call view.init()
|
|
816
|
-
* 8. If view has
|
|
817
|
-
* 9. If no
|
|
816
|
+
* 8. If view has template, call render via Updater
|
|
817
|
+
* 9. If no template, call endUpdate directly
|
|
818
818
|
*/
|
|
819
819
|
mountView(viewPath: string, viewInitParams?: Record<string, unknown>): void;
|
|
820
820
|
/**
|
|
@@ -1399,12 +1399,12 @@ declare function multi<S = Record<string, unknown>>(useStore: LarkUseStore<S>):
|
|
|
1399
1399
|
* @lark/framework Template Compiler
|
|
1400
1400
|
*
|
|
1401
1401
|
* convertArtSyntax() ({{}} → <% %>)
|
|
1402
|
-
*
|
|
1402
|
+
* processViewEvents() (v-event prefix + param encoding)
|
|
1403
1403
|
* compileToFunction() (<% %> → JS template function)
|
|
1404
1404
|
* extractGlobalVars() (AST-based global var analysis via @babel/parser)
|
|
1405
1405
|
*
|
|
1406
1406
|
* - All template operators: = (escape), ! (raw), @ (ref lookup), : (binding)
|
|
1407
|
-
* -
|
|
1407
|
+
* - v-event attribute processing with $g prefix + \x1e separator
|
|
1408
1408
|
* - $n (null-safe toString), $e (HTML entity encode), $eu (URI encode), $eq (quote encode), $i (ref lookup)
|
|
1409
1409
|
* - Debug mode with line tracking ($expr/$art/$line) and try-catch error wrapper
|
|
1410
1410
|
* - View ID injection (\x1f → '+$viewId+')
|
|
@@ -1418,12 +1418,12 @@ declare function multi<S = Record<string, unknown>>(useStore: LarkUseStore<S>):
|
|
|
1418
1418
|
* {{@variable}} → reference lookup for component data passing
|
|
1419
1419
|
* {{each list as item}} → loop
|
|
1420
1420
|
* {{each list as item idx}} → loop with index
|
|
1421
|
-
* {{
|
|
1421
|
+
* {{parse obj as val key}} → object iteration
|
|
1422
1422
|
* {{for(let i=0;i<n;i++)}} → generic for loop
|
|
1423
1423
|
* {{if condition}} → conditional
|
|
1424
1424
|
* {{else if condition}} → else-if
|
|
1425
1425
|
* {{else}} → else
|
|
1426
|
-
* {{/if}} / {{/each}} / {{/
|
|
1426
|
+
* {{/if}} / {{/each}} / {{/parse}} / {{/for}} → close blocks
|
|
1427
1427
|
* {{set a = b}} → variable declaration
|
|
1428
1428
|
*/
|
|
1429
1429
|
/** Options for compileTemplate() */
|
|
@@ -1468,4 +1468,4 @@ declare function compileTemplate(source: string, options?: CompileOptions): stri
|
|
|
1468
1468
|
*/
|
|
1469
1469
|
declare function extractGlobalVars(source: string): string[];
|
|
1470
1470
|
|
|
1471
|
-
export { type AnyFunc, Bag, type BagEntry, CALL_BREAK_TIME, Cache, type CacheEntry, type CacheOptions, type CompileOptions, type Constructable,
|
|
1471
|
+
export { type AnyFunc, Bag, type BagEntry, CALL_BREAK_TIME, Cache, type CacheEntry, type CacheOptions, type CompileOptions, type Constructable, EVENT_METHOD_REGEXP, EventDelegator, EventEmitter, type EventListenerEntry, Frame, type FrameBoundElement, type FrameChildrenMap, type FrameInvokeEntry, type FrameLike, type FrameReadyMap, Framework, type FrameworkConfig, LARK_VIEW, type LarkUseStore, type Location, type LocationDiff, type MixinEventHandler, type NodeUseStore, type ObservePayload, type ParamDiff, type ParsedUri, type PendingCacheEntry, Platform, ROUTER_EVENTS, type ReactUseStore, type RouteViewConfig, Router, SPLITTER, Service, type ServiceCacheInfo, type ServiceConstructor, type ServiceEntry, type ServiceMetaEntry, type ServiceOptions, State, type StoreConfig, type StoreMethods, TAG_ATTR_KEY, TAG_KEY, TAG_NAME_REGEXP, TAG_VIEW_KEY, Updater, type UpdaterLike, type VDomOp, type VDomRef, VIEW_EVENT_METHOD_REGEXP, type VdomElement, View, type ViewClassInternal, type ViewEventObjectMap, type ViewEventSelectorEntry, type ViewEventSelectorMap, type ViewGlobalEventEntry, type ViewInstance, type ViewLocationObserved, type ViewResourceEntry, type ViewResourceMap, type VoidFunc, applyIdUpdates, applyStyle, applyVdomOps, assign, cell, classExtend, cloneData, cloneStore, compileTemplate, createState, createVdomRef, defineStore, delStore, encodeHTML, encodeQ, encodeSafe, encodeURIExtra, ensureElementId, extractGlobalVars, funcWithTry, generateId, getAttribute, getById, getPlatform, getStore, getUseStore, has, isArray, isPlainObject, isPrimitive, isPrimitiveOrFunc, isState, isStoreActive, keys, lazySet, mark$1 as mark, markBooted, markRouterBooted, multi, nextCounter, nodeInside, noop, now, observeCell, parseUri, registerViewClass, safeguard, setData, shallowSet, mark as storeMark, unmark as storeUnmark, syncCounter, toMap, toUri, translateData, unmark$1 as unmark, vdomGetCompareKey, vdomGetNode, vdomSetAttributes, vdomSetChildNodes, vdomSetNode, vdomSpecialDiff, vdomUnmountFrames };
|
package/dist/index.d.ts
CHANGED
|
@@ -155,7 +155,7 @@ interface ViewInstance {
|
|
|
155
155
|
/** Whether rendered at least once */
|
|
156
156
|
rendered?: boolean;
|
|
157
157
|
/** Whether view has template */
|
|
158
|
-
|
|
158
|
+
template?: AnyFunc | string;
|
|
159
159
|
/** Location observation config */
|
|
160
160
|
locationObserved: ViewLocationObserved;
|
|
161
161
|
/** Observed state keys */
|
|
@@ -439,11 +439,11 @@ declare const LARK_VIEW = "lark-view";
|
|
|
439
439
|
* Group 2: handler name
|
|
440
440
|
* Group 3: params string
|
|
441
441
|
*/
|
|
442
|
-
declare const
|
|
442
|
+
declare const EVENT_METHOD_REGEXP: RegExp;
|
|
443
443
|
/** View event method name regex: e.g. "name<click,mousedown>" or "$selector<click>" */
|
|
444
|
-
declare const
|
|
445
|
-
/** Tag name
|
|
446
|
-
declare const
|
|
444
|
+
declare const VIEW_EVENT_METHOD_REGEXP: RegExp;
|
|
445
|
+
/** Tag name regexp for I_GetNode */
|
|
446
|
+
declare const TAG_NAME_REGEXP: RegExp;
|
|
447
447
|
/** Async task break time (ms) */
|
|
448
448
|
declare const CALL_BREAK_TIME = 48;
|
|
449
449
|
/** Increment global counter and return new value */
|
|
@@ -665,7 +665,7 @@ declare class View {
|
|
|
665
665
|
/** Whether rendered at least once */
|
|
666
666
|
rendered?: boolean;
|
|
667
667
|
/** Whether view has template */
|
|
668
|
-
|
|
668
|
+
template?: AnyFunc | string;
|
|
669
669
|
/** Location observation config */
|
|
670
670
|
locationObserved: ViewLocationObserved;
|
|
671
671
|
/** Observed state keys */
|
|
@@ -813,8 +813,8 @@ declare class Frame extends EventEmitter implements FrameLike {
|
|
|
813
813
|
* 5. Create View instance
|
|
814
814
|
* 6. View_DelegateEvents (bind DOM events)
|
|
815
815
|
* 7. Call view.init()
|
|
816
|
-
* 8. If view has
|
|
817
|
-
* 9. If no
|
|
816
|
+
* 8. If view has template, call render via Updater
|
|
817
|
+
* 9. If no template, call endUpdate directly
|
|
818
818
|
*/
|
|
819
819
|
mountView(viewPath: string, viewInitParams?: Record<string, unknown>): void;
|
|
820
820
|
/**
|
|
@@ -1399,12 +1399,12 @@ declare function multi<S = Record<string, unknown>>(useStore: LarkUseStore<S>):
|
|
|
1399
1399
|
* @lark/framework Template Compiler
|
|
1400
1400
|
*
|
|
1401
1401
|
* convertArtSyntax() ({{}} → <% %>)
|
|
1402
|
-
*
|
|
1402
|
+
* processViewEvents() (v-event prefix + param encoding)
|
|
1403
1403
|
* compileToFunction() (<% %> → JS template function)
|
|
1404
1404
|
* extractGlobalVars() (AST-based global var analysis via @babel/parser)
|
|
1405
1405
|
*
|
|
1406
1406
|
* - All template operators: = (escape), ! (raw), @ (ref lookup), : (binding)
|
|
1407
|
-
* -
|
|
1407
|
+
* - v-event attribute processing with $g prefix + \x1e separator
|
|
1408
1408
|
* - $n (null-safe toString), $e (HTML entity encode), $eu (URI encode), $eq (quote encode), $i (ref lookup)
|
|
1409
1409
|
* - Debug mode with line tracking ($expr/$art/$line) and try-catch error wrapper
|
|
1410
1410
|
* - View ID injection (\x1f → '+$viewId+')
|
|
@@ -1418,12 +1418,12 @@ declare function multi<S = Record<string, unknown>>(useStore: LarkUseStore<S>):
|
|
|
1418
1418
|
* {{@variable}} → reference lookup for component data passing
|
|
1419
1419
|
* {{each list as item}} → loop
|
|
1420
1420
|
* {{each list as item idx}} → loop with index
|
|
1421
|
-
* {{
|
|
1421
|
+
* {{parse obj as val key}} → object iteration
|
|
1422
1422
|
* {{for(let i=0;i<n;i++)}} → generic for loop
|
|
1423
1423
|
* {{if condition}} → conditional
|
|
1424
1424
|
* {{else if condition}} → else-if
|
|
1425
1425
|
* {{else}} → else
|
|
1426
|
-
* {{/if}} / {{/each}} / {{/
|
|
1426
|
+
* {{/if}} / {{/each}} / {{/parse}} / {{/for}} → close blocks
|
|
1427
1427
|
* {{set a = b}} → variable declaration
|
|
1428
1428
|
*/
|
|
1429
1429
|
/** Options for compileTemplate() */
|
|
@@ -1468,4 +1468,4 @@ declare function compileTemplate(source: string, options?: CompileOptions): stri
|
|
|
1468
1468
|
*/
|
|
1469
1469
|
declare function extractGlobalVars(source: string): string[];
|
|
1470
1470
|
|
|
1471
|
-
export { type AnyFunc, Bag, type BagEntry, CALL_BREAK_TIME, Cache, type CacheEntry, type CacheOptions, type CompileOptions, type Constructable,
|
|
1471
|
+
export { type AnyFunc, Bag, type BagEntry, CALL_BREAK_TIME, Cache, type CacheEntry, type CacheOptions, type CompileOptions, type Constructable, EVENT_METHOD_REGEXP, EventDelegator, EventEmitter, type EventListenerEntry, Frame, type FrameBoundElement, type FrameChildrenMap, type FrameInvokeEntry, type FrameLike, type FrameReadyMap, Framework, type FrameworkConfig, LARK_VIEW, type LarkUseStore, type Location, type LocationDiff, type MixinEventHandler, type NodeUseStore, type ObservePayload, type ParamDiff, type ParsedUri, type PendingCacheEntry, Platform, ROUTER_EVENTS, type ReactUseStore, type RouteViewConfig, Router, SPLITTER, Service, type ServiceCacheInfo, type ServiceConstructor, type ServiceEntry, type ServiceMetaEntry, type ServiceOptions, State, type StoreConfig, type StoreMethods, TAG_ATTR_KEY, TAG_KEY, TAG_NAME_REGEXP, TAG_VIEW_KEY, Updater, type UpdaterLike, type VDomOp, type VDomRef, VIEW_EVENT_METHOD_REGEXP, type VdomElement, View, type ViewClassInternal, type ViewEventObjectMap, type ViewEventSelectorEntry, type ViewEventSelectorMap, type ViewGlobalEventEntry, type ViewInstance, type ViewLocationObserved, type ViewResourceEntry, type ViewResourceMap, type VoidFunc, applyIdUpdates, applyStyle, applyVdomOps, assign, cell, classExtend, cloneData, cloneStore, compileTemplate, createState, createVdomRef, defineStore, delStore, encodeHTML, encodeQ, encodeSafe, encodeURIExtra, ensureElementId, extractGlobalVars, funcWithTry, generateId, getAttribute, getById, getPlatform, getStore, getUseStore, has, isArray, isPlainObject, isPrimitive, isPrimitiveOrFunc, isState, isStoreActive, keys, lazySet, mark$1 as mark, markBooted, markRouterBooted, multi, nextCounter, nodeInside, noop, now, observeCell, parseUri, registerViewClass, safeguard, setData, shallowSet, mark as storeMark, unmark as storeUnmark, syncCounter, toMap, toUri, translateData, unmark$1 as unmark, vdomGetCompareKey, vdomGetNode, vdomSetAttributes, vdomSetChildNodes, vdomSetNode, vdomSpecialDiff, vdomUnmountFrames };
|
package/dist/index.js
CHANGED
|
@@ -10,17 +10,17 @@ var TAG_KEY = "lark-key";
|
|
|
10
10
|
var TAG_ATTR_KEY = "lark-attr-key";
|
|
11
11
|
var TAG_VIEW_KEY = "lark-view-key";
|
|
12
12
|
var LARK_VIEW = "lark-view";
|
|
13
|
-
var
|
|
13
|
+
var EVENT_METHOD_REGEXP = new RegExp(
|
|
14
14
|
`(?:([\\w-]+)${SPLITTER})?([^(]+)\\(([\\s\\S]*?)?\\)`
|
|
15
15
|
);
|
|
16
|
-
var
|
|
17
|
-
var
|
|
18
|
-
var
|
|
19
|
-
var
|
|
20
|
-
var
|
|
16
|
+
var VIEW_EVENT_METHOD_REGEXP = /^(\$?)([\w]*)<(.*?)>(?:<([\w ,]*)>)?$/;
|
|
17
|
+
var URL_TRIM_HASH_REGEXP = /(?:^.*\/\/[^/]+|#.*$)/gi;
|
|
18
|
+
var URL_TRIM_QUERY_REGEXP = /^[^#]*#?!?/;
|
|
19
|
+
var URL_PARAM_REGEXP = /([^=&?/#]+)=?([^&#?]*)/g;
|
|
20
|
+
var URL_QUERY_HASH_REGEXP = /[#?].*$/;
|
|
21
21
|
var SVG_NS = "http://www.w3.org/2000/svg";
|
|
22
22
|
var MATH_NS = "http://www.w3.org/1998/Math/MathML";
|
|
23
|
-
var
|
|
23
|
+
var TAG_NAME_REGEXP = /<([a-z][^/\0>\x20\t\r\n\f]+)/i;
|
|
24
24
|
var CALL_BREAK_TIME = 48;
|
|
25
25
|
function nextCounter() {
|
|
26
26
|
return ++globalCounter;
|
|
@@ -158,10 +158,10 @@ function paramsReplacer(_match, name, value) {
|
|
|
158
158
|
}
|
|
159
159
|
function parseUri(uri) {
|
|
160
160
|
paramsTemp = {};
|
|
161
|
-
const path = uri.replace(
|
|
161
|
+
const path = uri.replace(URL_QUERY_HASH_REGEXP, "");
|
|
162
162
|
const pathname = path;
|
|
163
163
|
const actualPath = uri === pathname && IS_URL_PARAMS.test(pathname) ? "" : pathname;
|
|
164
|
-
uri.replace(actualPath, "").replace(
|
|
164
|
+
uri.replace(actualPath, "").replace(URL_PARAM_REGEXP, paramsReplacer);
|
|
165
165
|
return {
|
|
166
166
|
path: actualPath,
|
|
167
167
|
params: { ...paramsTemp }
|
|
@@ -855,8 +855,8 @@ var Router = {
|
|
|
855
855
|
if (cached) {
|
|
856
856
|
return cached;
|
|
857
857
|
}
|
|
858
|
-
const srcQuery = href.replace(
|
|
859
|
-
const srcHash = href.replace(
|
|
858
|
+
const srcQuery = href.replace(URL_TRIM_HASH_REGEXP, "");
|
|
859
|
+
const srcHash = href.replace(URL_TRIM_QUERY_REGEXP, "");
|
|
860
860
|
const query = parseUri(srcQuery);
|
|
861
861
|
const hash = parseUri(srcHash);
|
|
862
862
|
const params = assign({}, query["params"], hash["params"]);
|
|
@@ -958,9 +958,9 @@ var Router = {
|
|
|
958
958
|
join(...paths) {
|
|
959
959
|
let result = paths.join("/");
|
|
960
960
|
result = result.replace(/\/\.\//g, "/");
|
|
961
|
-
const
|
|
962
|
-
while (
|
|
963
|
-
result = result.replace(
|
|
961
|
+
const doubleDotRegExp = /\/[^/]+\/\.\.\//;
|
|
962
|
+
while (doubleDotRegExp.test(result)) {
|
|
963
|
+
result = result.replace(doubleDotRegExp, "/");
|
|
964
964
|
}
|
|
965
965
|
result = result.replace(/\/{2,}/g, "/");
|
|
966
966
|
return result;
|
|
@@ -1062,7 +1062,7 @@ function parseEventInfo(eventInfo) {
|
|
|
1062
1062
|
if (cached) {
|
|
1063
1063
|
return assign({}, cached, { r: eventInfo });
|
|
1064
1064
|
}
|
|
1065
|
-
const match = eventInfo.match(
|
|
1065
|
+
const match = eventInfo.match(EVENT_METHOD_REGEXP) || [];
|
|
1066
1066
|
const result = {
|
|
1067
1067
|
v: match[1] || "",
|
|
1068
1068
|
n: match[2] || "",
|
|
@@ -1074,7 +1074,7 @@ function parseEventInfo(eventInfo) {
|
|
|
1074
1074
|
function findFrameInfo(current, eventType) {
|
|
1075
1075
|
const eventInfos = [];
|
|
1076
1076
|
let begin = current;
|
|
1077
|
-
const info = current.getAttribute(`
|
|
1077
|
+
const info = current.getAttribute(`v-${eventType}`);
|
|
1078
1078
|
let match;
|
|
1079
1079
|
if (info) {
|
|
1080
1080
|
match = parseEventInfo(info);
|
|
@@ -1119,7 +1119,7 @@ function findFrameInfo(current, eventType) {
|
|
|
1119
1119
|
}
|
|
1120
1120
|
}
|
|
1121
1121
|
}
|
|
1122
|
-
if (view.
|
|
1122
|
+
if (view.template && !backtrace) {
|
|
1123
1123
|
if (match && !match.v) {
|
|
1124
1124
|
match.v = frameId;
|
|
1125
1125
|
}
|
|
@@ -1298,7 +1298,7 @@ function vdomGetNode(html, refNode) {
|
|
|
1298
1298
|
} else if (ns === MATH_NS) {
|
|
1299
1299
|
tag = "m";
|
|
1300
1300
|
} else {
|
|
1301
|
-
const match =
|
|
1301
|
+
const match = TAG_NAME_REGEXP.exec(html);
|
|
1302
1302
|
tag = match ? match[1] : "";
|
|
1303
1303
|
}
|
|
1304
1304
|
const wrap = WrapMeta[tag] || WrapMeta["_"];
|
|
@@ -1527,10 +1527,10 @@ var EncoderMap = {
|
|
|
1527
1527
|
"'": "#39",
|
|
1528
1528
|
"`": "#96"
|
|
1529
1529
|
};
|
|
1530
|
-
var
|
|
1530
|
+
var ENCODE_REGEXP = /[&<>"'`]/g;
|
|
1531
1531
|
function encodeHTML(v) {
|
|
1532
1532
|
return String(v == null ? "" : v).replace(
|
|
1533
|
-
|
|
1533
|
+
ENCODE_REGEXP,
|
|
1534
1534
|
(m) => "&" + EncoderMap[m] + ";"
|
|
1535
1535
|
);
|
|
1536
1536
|
}
|
|
@@ -1544,16 +1544,16 @@ var URIMap = {
|
|
|
1544
1544
|
")": "%29",
|
|
1545
1545
|
"*": "%2A"
|
|
1546
1546
|
};
|
|
1547
|
-
var
|
|
1547
|
+
var URI_ENCODE_REGEXP = /[!')(*]/g;
|
|
1548
1548
|
function encodeURIExtra(v) {
|
|
1549
1549
|
return encodeURIComponent(encodeSafe(v)).replace(
|
|
1550
|
-
|
|
1550
|
+
URI_ENCODE_REGEXP,
|
|
1551
1551
|
(m) => URIMap[m]
|
|
1552
1552
|
);
|
|
1553
1553
|
}
|
|
1554
|
-
var
|
|
1554
|
+
var QUOTE_REGEXP = /['"\\]/g;
|
|
1555
1555
|
function encodeQ(v) {
|
|
1556
|
-
return encodeSafe(v).replace(
|
|
1556
|
+
return encodeSafe(v).replace(QUOTE_REGEXP, "\\$&");
|
|
1557
1557
|
}
|
|
1558
1558
|
|
|
1559
1559
|
// src/updater.ts
|
|
@@ -1652,9 +1652,9 @@ var Updater = class {
|
|
|
1652
1652
|
const view = frame?.view;
|
|
1653
1653
|
const node = getById(this.viewId);
|
|
1654
1654
|
if (changed && view && node && view.signature > 0) {
|
|
1655
|
-
const
|
|
1656
|
-
if (
|
|
1657
|
-
const html =
|
|
1655
|
+
const template = view.template;
|
|
1656
|
+
if (template && typeof template === "function") {
|
|
1657
|
+
const html = template(
|
|
1658
1658
|
this.data,
|
|
1659
1659
|
this.viewId,
|
|
1660
1660
|
this.refData,
|
|
@@ -1759,7 +1759,7 @@ function viewPrepare(oView) {
|
|
|
1759
1759
|
if (!has(proto, p)) continue;
|
|
1760
1760
|
const currentFn = proto[p];
|
|
1761
1761
|
if (typeof currentFn !== "function") continue;
|
|
1762
|
-
const matches = p.match(
|
|
1762
|
+
const matches = p.match(VIEW_EVENT_METHOD_REGEXP);
|
|
1763
1763
|
if (!matches) continue;
|
|
1764
1764
|
const isSelector = matches[1];
|
|
1765
1765
|
const selectorOrCallback = matches[2];
|
|
@@ -1870,7 +1870,7 @@ function viewMergeMixins(mixins, viewClass, ctors) {
|
|
|
1870
1870
|
ctors.push(fn);
|
|
1871
1871
|
continue;
|
|
1872
1872
|
}
|
|
1873
|
-
if (
|
|
1873
|
+
if (VIEW_EVENT_METHOD_REGEXP.test(p)) {
|
|
1874
1874
|
if (exist) {
|
|
1875
1875
|
temp[p] = processMixinsSameEvent(fn, exist);
|
|
1876
1876
|
} else {
|
|
@@ -1968,7 +1968,7 @@ var View = class _View {
|
|
|
1968
1968
|
/** Whether rendered at least once */
|
|
1969
1969
|
rendered;
|
|
1970
1970
|
/** Whether view has template */
|
|
1971
|
-
|
|
1971
|
+
template;
|
|
1972
1972
|
/** Location observation config */
|
|
1973
1973
|
locationObserved = {
|
|
1974
1974
|
flag: 0,
|
|
@@ -2230,7 +2230,7 @@ var View = class _View {
|
|
|
2230
2230
|
initParams,
|
|
2231
2231
|
{
|
|
2232
2232
|
node,
|
|
2233
|
-
deep: !this.
|
|
2233
|
+
deep: !this.template
|
|
2234
2234
|
}
|
|
2235
2235
|
];
|
|
2236
2236
|
const concatCtors = ctors.concat(mixinCtors || []);
|
|
@@ -2358,8 +2358,8 @@ var Frame = class _Frame extends EventEmitter {
|
|
|
2358
2358
|
* 5. Create View instance
|
|
2359
2359
|
* 6. View_DelegateEvents (bind DOM events)
|
|
2360
2360
|
* 7. Call view.init()
|
|
2361
|
-
* 8. If view has
|
|
2362
|
-
* 9. If no
|
|
2361
|
+
* 8. If view has template, call render via Updater
|
|
2362
|
+
* 9. If no template, call endUpdate directly
|
|
2363
2363
|
*/
|
|
2364
2364
|
mountView(viewPath, viewInitParams) {
|
|
2365
2365
|
const node = document.getElementById(this.id);
|
|
@@ -2403,14 +2403,14 @@ var Frame = class _Frame extends EventEmitter {
|
|
|
2403
2403
|
viewDelegateEvents(view);
|
|
2404
2404
|
const initResult = funcWithTry(
|
|
2405
2405
|
view.init,
|
|
2406
|
-
[params, { node, deep: !view.
|
|
2406
|
+
[params, { node, deep: !view.template }],
|
|
2407
2407
|
view,
|
|
2408
2408
|
noop
|
|
2409
2409
|
);
|
|
2410
2410
|
const nextSign = ++this.signature;
|
|
2411
2411
|
Promise.resolve(initResult).then(() => {
|
|
2412
2412
|
if (nextSign !== this.signature) return;
|
|
2413
|
-
if (view.
|
|
2413
|
+
if (view.template) {
|
|
2414
2414
|
const renderFn = view.$b;
|
|
2415
2415
|
if (renderFn) {
|
|
2416
2416
|
renderFn.call(view);
|
|
@@ -3256,7 +3256,7 @@ var Framework = {
|
|
|
3256
3256
|
const rootFrame2 = Frame.root(config.rootId);
|
|
3257
3257
|
Router._bind();
|
|
3258
3258
|
const defaultView = config.defaultView || "";
|
|
3259
|
-
if (defaultView) {
|
|
3259
|
+
if (defaultView && !rootFrame2.view) {
|
|
3260
3260
|
rootFrame2.mountView(defaultView);
|
|
3261
3261
|
}
|
|
3262
3262
|
},
|
|
@@ -4216,9 +4216,9 @@ function jsObjectToUrlParams(paramsStr) {
|
|
|
4216
4216
|
if (objMatch) {
|
|
4217
4217
|
const inner = objMatch[1];
|
|
4218
4218
|
const pairs = [];
|
|
4219
|
-
const
|
|
4219
|
+
const pairRegExp = /(\w+)\s*:\s*(?:'([^']*)'|"([^"]*)"|([^,}]+))/g;
|
|
4220
4220
|
let m;
|
|
4221
|
-
while ((m =
|
|
4221
|
+
while ((m = pairRegExp.exec(inner)) !== null) {
|
|
4222
4222
|
const key = m[1];
|
|
4223
4223
|
const value = m[2] ?? m[3] ?? m[4]?.trim() ?? "";
|
|
4224
4224
|
pairs.push(`${key}=${value}`);
|
|
@@ -4240,19 +4240,19 @@ function restoreComments(source, comments) {
|
|
|
4240
4240
|
return comments[parseInt(index, 10)];
|
|
4241
4241
|
});
|
|
4242
4242
|
}
|
|
4243
|
-
function
|
|
4243
|
+
function processViewEvents(source) {
|
|
4244
4244
|
return source.replace(
|
|
4245
|
-
/
|
|
4245
|
+
/v-(\w+)="([^"]+)"/g,
|
|
4246
4246
|
(fullAttr, eventName, attrValue) => {
|
|
4247
4247
|
const eventMatch = attrValue.match(/^(\w+)\((.*)\)$/s);
|
|
4248
4248
|
if (!eventMatch) return fullAttr;
|
|
4249
4249
|
const handlerName = eventMatch[1];
|
|
4250
4250
|
const paramsStr = eventMatch[2].trim();
|
|
4251
4251
|
if (!paramsStr) {
|
|
4252
|
-
return `
|
|
4252
|
+
return `v-${eventName}="${VIEW_ID_PLACEHOLDER}${SPLITTER2}${handlerName}()"`;
|
|
4253
4253
|
}
|
|
4254
4254
|
const urlParams = jsObjectToUrlParams(paramsStr);
|
|
4255
|
-
return `
|
|
4255
|
+
return `v-${eventName}="${VIEW_ID_PLACEHOLDER}${SPLITTER2}${handlerName}(${urlParams})"`;
|
|
4256
4256
|
}
|
|
4257
4257
|
);
|
|
4258
4258
|
}
|
|
@@ -4325,7 +4325,7 @@ function convertArtSyntax(source, debug) {
|
|
|
4325
4325
|
}
|
|
4326
4326
|
if (blockStack.length > 0) {
|
|
4327
4327
|
const unclosed = blockStack.map((b) => `"${b.ctrl}" at line ${b.line}`).join(", ");
|
|
4328
|
-
throw new Error(`[
|
|
4328
|
+
throw new Error(`[@lark/mvc error] unclosed block(s): ${unclosed}`);
|
|
4329
4329
|
}
|
|
4330
4330
|
return result.join("");
|
|
4331
4331
|
}
|
|
@@ -4424,7 +4424,7 @@ function convertArtExpression(code, debug, lineNo, blockStack = []) {
|
|
|
4424
4424
|
const object = tokens[0];
|
|
4425
4425
|
if (tokens.length > 1 && tokens[1] !== "as") {
|
|
4426
4426
|
throw new Error(
|
|
4427
|
-
`[
|
|
4427
|
+
`[@lark/mvc error] bad each syntax: {{${code}}}. Expected "as" keyword, got "${tokens[1]}". Usage: {{each list as item [index]}}`
|
|
4428
4428
|
);
|
|
4429
4429
|
}
|
|
4430
4430
|
const restTokens = tokens.slice(2);
|
|
@@ -4446,12 +4446,12 @@ function convertArtExpression(code, debug, lineNo, blockStack = []) {
|
|
|
4446
4446
|
}
|
|
4447
4447
|
return `${debugPrefix}<%for(let ${index}=0${refExpr},${refObjCount}=${refObj}.length${lastCount};${index}<${refObjCount};${index}++){${firstAndLast}${valueDecl}%>`;
|
|
4448
4448
|
}
|
|
4449
|
-
case "
|
|
4450
|
-
blockStack.push({ ctrl: "
|
|
4449
|
+
case "parse": {
|
|
4450
|
+
blockStack.push({ ctrl: "parse", line: lineNo });
|
|
4451
4451
|
const object = tokens[0];
|
|
4452
4452
|
if (tokens.length > 1 && tokens[1] !== "as") {
|
|
4453
4453
|
throw new Error(
|
|
4454
|
-
`[
|
|
4454
|
+
`[@lark/mvc error] bad parse syntax: {{${code}}}. Expected "as" keyword, got "${tokens[1]}". Usage: {{for-in obj as val [key]}}`
|
|
4455
4455
|
);
|
|
4456
4456
|
}
|
|
4457
4457
|
const restTokens2 = tokens.slice(2);
|
|
@@ -4472,18 +4472,18 @@ function convertArtExpression(code, debug, lineNo, blockStack = []) {
|
|
|
4472
4472
|
return `${debugPrefix}<%let ${tokens.join(" ")};%>`;
|
|
4473
4473
|
case "/if":
|
|
4474
4474
|
case "/each":
|
|
4475
|
-
case "/
|
|
4475
|
+
case "/parse":
|
|
4476
4476
|
case "/for": {
|
|
4477
4477
|
const expectedCtrl = keyword.substring(1);
|
|
4478
4478
|
const last = blockStack.pop();
|
|
4479
4479
|
if (!last) {
|
|
4480
4480
|
throw new Error(
|
|
4481
|
-
`[
|
|
4481
|
+
`[@lark/mvc error(template] unexpected {{${code}}}: no matching open block`
|
|
4482
4482
|
);
|
|
4483
4483
|
}
|
|
4484
4484
|
if (last.ctrl !== expectedCtrl) {
|
|
4485
4485
|
throw new Error(
|
|
4486
|
-
`[
|
|
4486
|
+
`[@lark/mvc error(template] unexpected {{${code}}}: expected {{/${last.ctrl}}} to close block opened at line ${last.line}`
|
|
4487
4487
|
);
|
|
4488
4488
|
}
|
|
4489
4489
|
return `${debugPrefix}<%}%>`;
|
|
@@ -4560,12 +4560,12 @@ function compileToFunction(source, debug, file) {
|
|
|
4560
4560
|
index - 2
|
|
4561
4561
|
);
|
|
4562
4562
|
const x11 = String.fromCharCode(17);
|
|
4563
|
-
const
|
|
4564
|
-
const artM = expr.match(
|
|
4563
|
+
const artRegExp = new RegExp(`^'(\\d+)${x11}([^${x11}]+)${x11}'$`);
|
|
4564
|
+
const artM = expr.match(artRegExp);
|
|
4565
4565
|
let art = "";
|
|
4566
4566
|
let line = -1;
|
|
4567
4567
|
if (artM) {
|
|
4568
|
-
expr = expr.replace(
|
|
4568
|
+
expr = expr.replace(artRegExp, "");
|
|
4569
4569
|
art = artM[2];
|
|
4570
4570
|
line = parseInt(artM[1], 10);
|
|
4571
4571
|
} else {
|
|
@@ -4624,8 +4624,8 @@ function compileToFunction(source, debug, file) {
|
|
|
4624
4624
|
const filePart = file ? `\\r\\n\\tat file:${file}` : "";
|
|
4625
4625
|
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;}`;
|
|
4626
4626
|
}
|
|
4627
|
-
const
|
|
4628
|
-
funcSource = funcSource.replace(
|
|
4627
|
+
const viewIdRegExp = new RegExp(String.fromCharCode(31), "g");
|
|
4628
|
+
funcSource = funcSource.replace(viewIdRegExp, `'+$viewId+'`);
|
|
4629
4629
|
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;}}` : "";
|
|
4630
4630
|
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)}`;
|
|
4631
4631
|
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)}`;
|
|
@@ -4639,8 +4639,8 @@ function compileTemplate(source, options = {}) {
|
|
|
4639
4639
|
const { debug = false, globalVars = [], file } = options;
|
|
4640
4640
|
const { protectedSource, comments } = protectComments(source);
|
|
4641
4641
|
const converted = convertArtSyntax(protectedSource, debug);
|
|
4642
|
-
const
|
|
4643
|
-
const finalSource = restoreComments(
|
|
4642
|
+
const viewEventProcessed = processViewEvents(converted);
|
|
4643
|
+
const finalSource = restoreComments(viewEventProcessed, comments);
|
|
4644
4644
|
const funcBody = compileToFunction(finalSource, debug, file);
|
|
4645
4645
|
const varDeclarations = globalVars.map((key) => `,${key}=$$.${key}`).join("");
|
|
4646
4646
|
const funcWithVars = funcBody.replace("{{VARS}}", () => varDeclarations);
|
|
@@ -4658,20 +4658,20 @@ function compileTemplate(source, options = {}) {
|
|
|
4658
4658
|
}
|
|
4659
4659
|
function extractGlobalVars(source) {
|
|
4660
4660
|
const { protectedSource, comments: _comments } = protectComments(source);
|
|
4661
|
-
const
|
|
4662
|
-
const converted = convertArtSyntax(
|
|
4663
|
-
const
|
|
4664
|
-
const
|
|
4661
|
+
const viewEventProcessed = processViewEvents(protectedSource);
|
|
4662
|
+
const converted = convertArtSyntax(viewEventProcessed, false);
|
|
4663
|
+
const template = restoreComments(converted, _comments);
|
|
4664
|
+
const templateCmdRegExp = /<%([@=!:])?([\s\S]*?)%>|$/g;
|
|
4665
4665
|
const fnParts = [];
|
|
4666
4666
|
const htmlStore = {};
|
|
4667
4667
|
let htmlIndex = 0;
|
|
4668
4668
|
let lastIndex = 0;
|
|
4669
4669
|
const htmlKey = "";
|
|
4670
|
-
|
|
4671
|
-
|
|
4670
|
+
template.replace(
|
|
4671
|
+
templateCmdRegExp,
|
|
4672
4672
|
(match, operate, content, offset) => {
|
|
4673
4673
|
const start = operate ? 3 : 2;
|
|
4674
|
-
const htmlText =
|
|
4674
|
+
const htmlText = template.substring(lastIndex, offset + start);
|
|
4675
4675
|
const key = htmlKey + htmlIndex++ + htmlKey;
|
|
4676
4676
|
htmlStore[key] = htmlText;
|
|
4677
4677
|
lastIndex = offset + match.length - 2;
|
|
@@ -4756,17 +4756,17 @@ function extractGlobalVars(source) {
|
|
|
4756
4756
|
}
|
|
4757
4757
|
function fallbackExtractVariables(source) {
|
|
4758
4758
|
const vars = /* @__PURE__ */ new Set();
|
|
4759
|
-
const
|
|
4759
|
+
const outputRegExp = /\{\{[:=!@]\s*([a-zA-Z_$][\w$]*)[^}]*\}\}/g;
|
|
4760
4760
|
let m;
|
|
4761
|
-
while ((m =
|
|
4761
|
+
while ((m = outputRegExp.exec(source)) !== null) {
|
|
4762
4762
|
vars.add(m[1]);
|
|
4763
4763
|
}
|
|
4764
|
-
const
|
|
4765
|
-
while ((m =
|
|
4764
|
+
const eachRegExp = /\{\{each\s+([a-zA-Z_$][\w$]*)\s+as/g;
|
|
4765
|
+
while ((m = eachRegExp.exec(source)) !== null) {
|
|
4766
4766
|
vars.add(m[1]);
|
|
4767
4767
|
}
|
|
4768
|
-
const
|
|
4769
|
-
while ((m =
|
|
4768
|
+
const ifRegExp = /\{\{(?:else\s+)?if\s+([a-zA-Z_$][\w$]*)[^}]*\}\}/g;
|
|
4769
|
+
while ((m = ifRegExp.exec(source)) !== null) {
|
|
4770
4770
|
vars.add(m[1]);
|
|
4771
4771
|
}
|
|
4772
4772
|
return Array.from(vars).filter((v) => !BUILTIN_GLOBAL_SET.has(v));
|
|
@@ -4829,7 +4829,7 @@ var BUILTIN_GLOBALS = {
|
|
|
4829
4829
|
// {'&':'amp','<':'gt','>':'gt','"':'#34','\'':'#39','`':'#96'}
|
|
4830
4830
|
// Not a standalone function; referenced inside $e's closure.
|
|
4831
4831
|
$em: 1,
|
|
4832
|
-
// HTML entity RegExp — internal
|
|
4832
|
+
// HTML entity RegExp — internal regexp used by $e:
|
|
4833
4833
|
// /[&<>"'`]/g
|
|
4834
4834
|
$er: 1,
|
|
4835
4835
|
// HTML entity replacer function — internal helper used by $e:
|
|
@@ -4848,14 +4848,14 @@ var BUILTIN_GLOBALS = {
|
|
|
4848
4848
|
$i: 1,
|
|
4849
4849
|
// URI encoder: v => encodeURIComponent($n(v)).replace(/[!')(*]/g, extraMap)
|
|
4850
4850
|
// Extends encodeURIComponent with encoding of ! ' ( ) *.
|
|
4851
|
-
// Applied to values in
|
|
4851
|
+
// Applied to values in v-event URL parameters and {{!uri}} contexts.
|
|
4852
4852
|
$eu: 1,
|
|
4853
4853
|
// Quote encoder: v => $n(v).replace(/['"\\]/g, '\\$&')
|
|
4854
4854
|
// Escapes quotes and backslashes for safe embedding in HTML attribute
|
|
4855
4855
|
// values (e.g. data-json='...').
|
|
4856
4856
|
$eq: 1,
|
|
4857
4857
|
// View ID — the unique identifier of the owning View instance.
|
|
4858
|
-
// Injected into
|
|
4858
|
+
// Injected into v-event attribute values at render time so that
|
|
4859
4859
|
// EventDelegator can dispatch events to the correct View handler.
|
|
4860
4860
|
// The \x1f placeholder in compiled output is replaced with '+$viewId+'.
|
|
4861
4861
|
$viewId: 1,
|
|
@@ -4945,7 +4945,7 @@ export {
|
|
|
4945
4945
|
Bag,
|
|
4946
4946
|
CALL_BREAK_TIME,
|
|
4947
4947
|
Cache,
|
|
4948
|
-
|
|
4948
|
+
EVENT_METHOD_REGEXP,
|
|
4949
4949
|
EventDelegator,
|
|
4950
4950
|
EventEmitter,
|
|
4951
4951
|
Frame,
|
|
@@ -4959,10 +4959,10 @@ export {
|
|
|
4959
4959
|
State,
|
|
4960
4960
|
TAG_ATTR_KEY,
|
|
4961
4961
|
TAG_KEY,
|
|
4962
|
-
|
|
4962
|
+
TAG_NAME_REGEXP,
|
|
4963
4963
|
TAG_VIEW_KEY,
|
|
4964
4964
|
Updater,
|
|
4965
|
-
|
|
4965
|
+
VIEW_EVENT_METHOD_REGEXP,
|
|
4966
4966
|
View,
|
|
4967
4967
|
applyIdUpdates,
|
|
4968
4968
|
applyStyle,
|