wevu 7.1.4 → 7.2.0
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 +20 -6
- package/dist/dev/index.d.mts +3 -3
- package/dist/dev/index.mjs +3 -2
- package/dist/dev/package.mjs +1 -1
- package/dist/dev/reactivity/computed.d.mts +4 -0
- package/dist/dev/reactivity/computed.mjs +10 -1
- package/dist/dev/reactivity/computed.mjs.map +1 -1
- package/dist/dev/reactivity/reactive.mjs +27 -20
- package/dist/dev/reactivity/reactive.mjs.map +1 -1
- package/dist/dev/router/auto-routes.d.mts +8 -0
- package/dist/dev/router/auto-routes.mjs +11 -0
- package/dist/dev/router/auto-routes.mjs.map +1 -0
- package/dist/dev/router/createRouter.d.mts +2 -1
- package/dist/dev/router/createRouter.mjs +3 -4
- package/dist/dev/router/createRouter.mjs.map +1 -1
- package/dist/dev/router/navigationCore.d.mts +3 -2
- package/dist/dev/router/navigationCore.mjs +7 -7
- package/dist/dev/router/navigationCore.mjs.map +1 -1
- package/dist/dev/router/resolve.d.mts +3 -2
- package/dist/dev/router/resolve.mjs.map +1 -1
- package/dist/dev/router/routeSync.d.mts +1 -0
- package/dist/dev/router/types.d.mts +173 -78
- package/dist/dev/router/types.mjs.map +1 -1
- package/dist/dev/router/useRoute.d.mts +4 -3
- package/dist/dev/router/useRoute.mjs.map +1 -1
- package/dist/dev/router/useRouter.d.mts +2 -1
- package/dist/dev/router/useRouter.mjs.map +1 -1
- package/dist/dev/router.d.mts +19 -3
- package/dist/dev/routerInternal/location.d.mts +2 -0
- package/dist/dev/routerInternal/matching.d.mts +2 -0
- package/dist/dev/routerInternal/matching.mjs +1 -1
- package/dist/dev/routerInternal/matching.mjs.map +1 -1
- package/dist/dev/routerInternal/params.d.mts +2 -0
- package/dist/dev/routerInternal/params.mjs.map +1 -1
- package/dist/dev/routerInternal/records.d.mts +2 -0
- package/dist/dev/routerInternal/recordsWarnings.d.mts +2 -0
- package/dist/dev/routerInternal/shared.d.mts +9 -0
- package/dist/dev/routerInternal/snapshots.d.mts +2 -0
- package/dist/dev/runtime/hooks/base.mjs +5 -5
- package/dist/dev/runtime/hooks/base.mjs.map +1 -1
- package/dist/dev/runtime/platform.mjs +31 -24
- package/dist/dev/runtime/platform.mjs.map +1 -1
- package/dist/dev/runtime/register/component/alipay.mjs +72 -0
- package/dist/dev/runtime/register/component/alipay.mjs.map +1 -0
- package/dist/dev/runtime/register/component/registerNativeDefinition.mjs +5 -2
- package/dist/dev/runtime/register/component/registerNativeDefinition.mjs.map +1 -1
- package/dist/dev/store/actions.mjs +27 -29
- package/dist/dev/store/actions.mjs.map +1 -1
- package/dist/dev/store/base.mjs +152 -36
- package/dist/dev/store/base.mjs.map +1 -1
- package/dist/dev/store/define/create.mjs +92 -0
- package/dist/dev/store/define/create.mjs.map +1 -0
- package/dist/dev/store/define.d.mts +5 -16
- package/dist/dev/store/define.mjs +11 -15
- package/dist/dev/store/define.mjs.map +1 -1
- package/dist/dev/store/manager.d.mts +13 -5
- package/dist/dev/store/manager.mjs +55 -14
- package/dist/dev/store/manager.mjs.map +1 -1
- package/dist/dev/store/storeToRefs.d.mts +5 -7
- package/dist/dev/store/storeToRefs.mjs +10 -18
- package/dist/dev/store/storeToRefs.mjs.map +1 -1
- package/dist/dev/store/subscriptions.mjs +17 -0
- package/dist/dev/store/subscriptions.mjs.map +1 -0
- package/dist/dev/store/types.d.mts +85 -59
- package/dist/dev/store/types.mjs +11 -0
- package/dist/dev/store/types.mjs.map +1 -0
- package/dist/dev/store/utils.mjs +1 -37
- package/dist/dev/store/utils.mjs.map +1 -1
- package/dist/dev/store/view.mjs +56 -0
- package/dist/dev/store/view.mjs.map +1 -0
- package/dist/dev/store.d.mts +3 -3
- package/dist/dev/store.mjs +3 -2
- package/dist/dev/vue-demi.d.mts +3 -3
- package/dist/dev/vue-demi.mjs +3 -2
- package/dist/dev/vue-demi.mjs.map +1 -1
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +1 -1
- package/dist/package.mjs +1 -1
- package/dist/reactivity/computed.d.mts +4 -0
- package/dist/reactivity/computed.mjs +1 -1
- package/dist/reactivity/reactive.mjs +1 -1
- package/dist/router/auto-routes.d.mts +7 -0
- package/dist/router/auto-routes.mjs +1 -0
- package/dist/router/createRouter.d.mts +2 -1
- package/dist/router/createRouter.mjs +1 -1
- package/dist/router/navigationCore.d.mts +3 -2
- package/dist/router/navigationCore.mjs +1 -1
- package/dist/router/resolve.d.mts +3 -2
- package/dist/router/routeSync.d.mts +1 -0
- package/dist/router/types.d.mts +173 -78
- package/dist/router/useRoute.d.mts +4 -3
- package/dist/router/useRouter.d.mts +2 -1
- package/dist/router.d.mts +18 -3
- package/dist/routerInternal/location.d.mts +2 -0
- package/dist/routerInternal/matching.d.mts +2 -0
- package/dist/routerInternal/matching.mjs +1 -1
- package/dist/routerInternal/params.d.mts +2 -0
- package/dist/routerInternal/records.d.mts +2 -0
- package/dist/routerInternal/recordsWarnings.d.mts +2 -0
- package/dist/routerInternal/shared.d.mts +9 -0
- package/dist/routerInternal/snapshots.d.mts +2 -0
- package/dist/runtime/hooks/base.mjs +1 -1
- package/dist/runtime/platform.mjs +1 -1
- package/dist/runtime/register/component/alipay.mjs +1 -0
- package/dist/runtime/register/component/registerNativeDefinition.mjs +1 -1
- package/dist/store/actions.mjs +1 -1
- package/dist/store/base.mjs +1 -1
- package/dist/store/define/create.mjs +1 -0
- package/dist/store/define.d.mts +5 -16
- package/dist/store/define.mjs +1 -1
- package/dist/store/manager.d.mts +13 -5
- package/dist/store/manager.mjs +1 -1
- package/dist/store/storeToRefs.d.mts +5 -7
- package/dist/store/storeToRefs.mjs +1 -1
- package/dist/store/subscriptions.mjs +1 -0
- package/dist/store/types.d.mts +85 -59
- package/dist/store/types.mjs +1 -0
- package/dist/store/utils.mjs +1 -1
- package/dist/store/view.mjs +1 -0
- package/dist/store.d.mts +3 -3
- package/dist/store.mjs +1 -1
- package/dist/vue-demi.d.mts +3 -3
- package/dist/vue-demi.mjs +1 -1
- package/package.json +29 -9
- package/dist/dev/store/define/optionsStyle.mjs +0 -117
- package/dist/dev/store/define/optionsStyle.mjs.map +0 -1
- package/dist/dev/store/define/setupStyle.mjs +0 -137
- package/dist/dev/store/define/setupStyle.mjs.map +0 -1
- package/dist/dev/store/define/shared.mjs +0 -81
- package/dist/dev/store/define/shared.mjs.map +0 -1
- package/dist/store/define/optionsStyle.mjs +0 -1
- package/dist/store/define/setupStyle.mjs +0 -1
- package/dist/store/define/shared.mjs +0 -1
|
@@ -25,7 +25,7 @@ function mergeMatchedRouteMeta(matchedRecords) {
|
|
|
25
25
|
let mergedRouteMeta;
|
|
26
26
|
for (const matchedRecord of matchedRecords) {
|
|
27
27
|
if (!matchedRecord.meta) continue;
|
|
28
|
-
if (!mergedRouteMeta) mergedRouteMeta =
|
|
28
|
+
if (!mergedRouteMeta) mergedRouteMeta = Object.create(null);
|
|
29
29
|
Object.assign(mergedRouteMeta, matchedRecord.meta);
|
|
30
30
|
}
|
|
31
31
|
return mergedRouteMeta;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"matching.mjs","names":[],"sources":["../../../src/routerInternal/matching.ts"],"sourcesContent":["import type {\n RouteLocationNormalizedLoaded,\n RouteMeta,\n RouteParams,\n} from '../router'\nimport type {\n MatchedRouteRecordResolveResult,\n NamedRouteLookup,\n RouteRecordNormalized,\n} from './types'\nimport { decodeRouteParamSegment, parsePathParamToken } from './params'\nimport { isDynamicRoutePath } from './path'\n\nfunction splitRoutePathSegments(path: string): string[] {\n return path.split('/').filter(Boolean)\n}\n\nfunction listRouteRecordMatchPaths(record: RouteRecordNormalized): readonly string[] {\n return [record.path, ...record.aliasPaths]\n}\n\nfunction resolveMatchedRouteRecordChain(\n record: RouteRecordNormalized,\n lookup: NamedRouteLookup,\n): RouteRecordNormalized[] {\n const matchedRecords: RouteRecordNormalized[] = []\n const visitedNames = new Set<string>()\n let currentRecord: RouteRecordNormalized | undefined = record\n\n while (currentRecord) {\n if (visitedNames.has(currentRecord.name)) {\n break\n }\n visitedNames.add(currentRecord.name)\n matchedRecords.unshift(currentRecord)\n if (!currentRecord.parentName) {\n break\n }\n currentRecord = lookup.recordByName.get(currentRecord.parentName)\n }\n\n return matchedRecords\n}\n\nexport function mergeMatchedRouteMeta(matchedRecords: readonly RouteRecordNormalized[]): RouteMeta | undefined {\n let mergedRouteMeta: RouteMeta | undefined\n for (const matchedRecord of matchedRecords) {\n if (!matchedRecord.meta) {\n continue\n }\n if (!mergedRouteMeta) {\n mergedRouteMeta = {}\n }\n Object.assign(mergedRouteMeta, matchedRecord.meta)\n }\n return mergedRouteMeta\n}\n\nexport function collectRouteNamesForRemoval(\n routeName: string,\n recordByName: ReadonlyMap<string, RouteRecordNormalized>,\n): Set<string> {\n const namesToRemove = new Set<string>()\n if (!recordByName.has(routeName)) {\n return namesToRemove\n }\n\n namesToRemove.add(routeName)\n let expanded = true\n while (expanded) {\n expanded = false\n for (const [name, record] of recordByName.entries()) {\n if (!record.parentName || namesToRemove.has(name)) {\n continue\n }\n if (namesToRemove.has(record.parentName)) {\n namesToRemove.add(name)\n expanded = true\n }\n }\n }\n\n return namesToRemove\n}\n\nfunction buildRouteParamsFromMatch(matchValues: ReadonlyMap<string, string[]>): RouteParams {\n const params: RouteParams = {}\n for (const [key, values] of matchValues.entries()) {\n if (values.length === 0) {\n continue\n }\n params[key] = values.length === 1 ? values[0] : values\n }\n return params\n}\n\nfunction matchRoutePathParams(pathTemplate: string, targetPath: string): RouteParams | undefined {\n const templateSegments = splitRoutePathSegments(pathTemplate)\n const targetSegments = splitRoutePathSegments(targetPath)\n const matchedValues = new Map<string, string[]>()\n\n const pushValue = (key: string, value: string) => {\n const previous = matchedValues.get(key)\n if (previous) {\n previous.push(value)\n return\n }\n matchedValues.set(key, [value])\n }\n\n const popValue = (key: string) => {\n const previous = matchedValues.get(key)\n if (!previous || previous.length === 0) {\n return\n }\n previous.pop()\n if (previous.length === 0) {\n matchedValues.delete(key)\n }\n }\n\n const consumeRepeatableToken = (key: string, startIndex: number, count: number): () => void => {\n for (let index = 0; index < count; index += 1) {\n pushValue(key, decodeRouteParamSegment(targetSegments[startIndex + index]))\n }\n return () => {\n for (let index = 0; index < count; index += 1) {\n popValue(key)\n }\n }\n }\n\n const matchRecursively = (templateIndex: number, targetIndex: number): boolean => {\n if (templateIndex >= templateSegments.length) {\n return targetIndex >= targetSegments.length\n }\n\n const templateSegment = templateSegments[templateIndex]\n const token = parsePathParamToken(templateSegment)\n if (!token) {\n if (targetIndex >= targetSegments.length || templateSegment !== targetSegments[targetIndex]) {\n return false\n }\n return matchRecursively(templateIndex + 1, targetIndex + 1)\n }\n\n if (token.modifier === '') {\n if (targetIndex >= targetSegments.length) {\n return false\n }\n pushValue(token.key, decodeRouteParamSegment(targetSegments[targetIndex]))\n const matched = matchRecursively(templateIndex + 1, targetIndex + 1)\n if (!matched) {\n popValue(token.key)\n }\n return matched\n }\n\n if (token.modifier === '?') {\n if (targetIndex < targetSegments.length) {\n pushValue(token.key, decodeRouteParamSegment(targetSegments[targetIndex]))\n const consumeMatched = matchRecursively(templateIndex + 1, targetIndex + 1)\n if (consumeMatched) {\n return true\n }\n popValue(token.key)\n }\n return matchRecursively(templateIndex + 1, targetIndex)\n }\n\n const minimumCount = token.modifier === '+' ? 1 : 0\n const maximumCount = targetSegments.length - targetIndex\n\n for (let count = maximumCount; count >= minimumCount; count -= 1) {\n const rollback = consumeRepeatableToken(token.key, targetIndex, count)\n const matched = matchRecursively(templateIndex + 1, targetIndex + count)\n if (matched) {\n return true\n }\n rollback()\n }\n\n return false\n }\n\n if (!matchRecursively(0, 0)) {\n return undefined\n }\n\n return buildRouteParamsFromMatch(matchedValues)\n}\n\nexport function resolveMatchedRouteRecord(\n target: RouteLocationNormalizedLoaded,\n lookup: NamedRouteLookup,\n): MatchedRouteRecordResolveResult | undefined {\n if (target.name) {\n const byName = lookup.recordByName.get(target.name)\n if (byName) {\n return {\n record: byName,\n matchedRecords: resolveMatchedRouteRecordChain(byName, lookup),\n }\n }\n }\n\n const staticNamedRoute = lookup.nameByStaticPath.get(target.path)\n if (staticNamedRoute) {\n const record = lookup.recordByName.get(staticNamedRoute)\n if (record) {\n return {\n record,\n matchedRecords: resolveMatchedRouteRecordChain(record, lookup),\n matchedPath: target.path,\n }\n }\n }\n\n for (const record of lookup.recordByName.values()) {\n for (const routePath of listRouteRecordMatchPaths(record)) {\n if (!isDynamicRoutePath(routePath)) {\n continue\n }\n const matchedParams = matchRoutePathParams(routePath, target.path)\n if (!matchedParams) {\n continue\n }\n return {\n record,\n matchedRecords: resolveMatchedRouteRecordChain(record, lookup),\n matchedPath: routePath,\n params: matchedParams,\n }\n }\n }\n\n return undefined\n}\n"],"mappings":";;;;AAaA,SAAS,uBAAuB,MAAwB;CACtD,OAAO,KAAK,MAAM,GAAG,CAAC,CAAC,OAAO,OAAO;AACvC;AAEA,SAAS,0BAA0B,QAAkD;CACnF,OAAO,CAAC,OAAO,MAAM,GAAG,OAAO,UAAU;AAC3C;AAEA,SAAS,+BACP,QACA,QACyB;CACzB,MAAM,iBAA0C,CAAC;CACjD,MAAM,+BAAe,IAAI,IAAY;CACrC,IAAI,gBAAmD;CAEvD,OAAO,eAAe;EACpB,IAAI,aAAa,IAAI,cAAc,IAAI,GACrC;EAEF,aAAa,IAAI,cAAc,IAAI;EACnC,eAAe,QAAQ,aAAa;EACpC,IAAI,CAAC,cAAc,YACjB;EAEF,gBAAgB,OAAO,aAAa,IAAI,cAAc,UAAU;CAClE;CAEA,OAAO;AACT;AAEA,SAAgB,sBAAsB,gBAAyE;CAC7G,IAAI;CACJ,KAAK,MAAM,iBAAiB,gBAAgB;EAC1C,IAAI,CAAC,cAAc,MACjB;EAEF,IAAI,CAAC,iBACH,kBAAkB,CAAC;EAErB,OAAO,OAAO,iBAAiB,cAAc,IAAI;CACnD;CACA,OAAO;AACT;AAEA,SAAgB,4BACd,WACA,cACa;CACb,MAAM,gCAAgB,IAAI,IAAY;CACt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AI,OAAO,IAAI;EAClD,IAAI,QACF,OAAO;GACL,QAAQ;GACR,gBAAgB,+BAA+B,QAAQ,MAAM;EAC/D;CAEJ;CAEA,MAAM,mBAAmB,OAAO,iBAAiB,IAAI,OAAO,IAAI;CAChE,IAAI,kBAAkB;EACpB,MAAM,SAAS,OAAO,aAAa,IAAI,gBAAgB;EACvD,IAAI,QACF,OAAO;GACL;GACA,gBAAgB,+BAA+B,QAAQ,MAAM;GAC7D,aAAa,OAAO;EACtB;CAEJ;CAEA,KAAK,MAAM,UAAU,OAAO,aAAa,OAAO,GAC9C,KAAK,MAAM,aAAa,0BAA0B,MAAM,GAAG;EACzD,IAAI,CAAC,mBAAmB,SAAS,GAC/B;EAEF,MAAM,gBAAgB,qBAAqB,WAAW,OAAO,IAAI;EACjE,IAAI,CAAC,eACH;EAEF,OAAO;GACL;GACA,gBAAgB,+BAA+B,QAAQ,MAAM;GAC7D,aAAa;GACb,QAAQ;EACV;CACF;AAIJ"}
|
|
1
|
+
{"version":3,"file":"matching.mjs","names":[],"sources":["../../../src/routerInternal/matching.ts"],"sourcesContent":["import type {\n RouteLocationNormalizedLoaded,\n RouteMeta,\n RouteParams,\n} from '../router'\nimport type {\n MatchedRouteRecordResolveResult,\n NamedRouteLookup,\n RouteRecordNormalized,\n} from './types'\nimport { decodeRouteParamSegment, parsePathParamToken } from './params'\nimport { isDynamicRoutePath } from './path'\n\nfunction splitRoutePathSegments(path: string): string[] {\n return path.split('/').filter(Boolean)\n}\n\nfunction listRouteRecordMatchPaths(record: RouteRecordNormalized): readonly string[] {\n return [record.path, ...record.aliasPaths]\n}\n\nfunction resolveMatchedRouteRecordChain(\n record: RouteRecordNormalized,\n lookup: NamedRouteLookup,\n): RouteRecordNormalized[] {\n const matchedRecords: RouteRecordNormalized[] = []\n const visitedNames = new Set<string>()\n let currentRecord: RouteRecordNormalized | undefined = record\n\n while (currentRecord) {\n if (visitedNames.has(currentRecord.name)) {\n break\n }\n visitedNames.add(currentRecord.name)\n matchedRecords.unshift(currentRecord)\n if (!currentRecord.parentName) {\n break\n }\n currentRecord = lookup.recordByName.get(currentRecord.parentName)\n }\n\n return matchedRecords\n}\n\nexport function mergeMatchedRouteMeta(matchedRecords: readonly RouteRecordNormalized[]): RouteMeta | undefined {\n let mergedRouteMeta: RouteMeta | undefined\n for (const matchedRecord of matchedRecords) {\n if (!matchedRecord.meta) {\n continue\n }\n if (!mergedRouteMeta) {\n mergedRouteMeta = Object.create(null) as RouteMeta\n }\n Object.assign(mergedRouteMeta, matchedRecord.meta)\n }\n return mergedRouteMeta\n}\n\nexport function collectRouteNamesForRemoval(\n routeName: string,\n recordByName: ReadonlyMap<string, RouteRecordNormalized>,\n): Set<string> {\n const namesToRemove = new Set<string>()\n if (!recordByName.has(routeName)) {\n return namesToRemove\n }\n\n namesToRemove.add(routeName)\n let expanded = true\n while (expanded) {\n expanded = false\n for (const [name, record] of recordByName.entries()) {\n if (!record.parentName || namesToRemove.has(name)) {\n continue\n }\n if (namesToRemove.has(record.parentName)) {\n namesToRemove.add(name)\n expanded = true\n }\n }\n }\n\n return namesToRemove\n}\n\nfunction buildRouteParamsFromMatch(matchValues: ReadonlyMap<string, string[]>): RouteParams {\n const params: RouteParams = {}\n for (const [key, values] of matchValues.entries()) {\n if (values.length === 0) {\n continue\n }\n params[key] = values.length === 1 ? values[0] : values\n }\n return params\n}\n\nfunction matchRoutePathParams(pathTemplate: string, targetPath: string): RouteParams | undefined {\n const templateSegments = splitRoutePathSegments(pathTemplate)\n const targetSegments = splitRoutePathSegments(targetPath)\n const matchedValues = new Map<string, string[]>()\n\n const pushValue = (key: string, value: string) => {\n const previous = matchedValues.get(key)\n if (previous) {\n previous.push(value)\n return\n }\n matchedValues.set(key, [value])\n }\n\n const popValue = (key: string) => {\n const previous = matchedValues.get(key)\n if (!previous || previous.length === 0) {\n return\n }\n previous.pop()\n if (previous.length === 0) {\n matchedValues.delete(key)\n }\n }\n\n const consumeRepeatableToken = (key: string, startIndex: number, count: number): () => void => {\n for (let index = 0; index < count; index += 1) {\n pushValue(key, decodeRouteParamSegment(targetSegments[startIndex + index]))\n }\n return () => {\n for (let index = 0; index < count; index += 1) {\n popValue(key)\n }\n }\n }\n\n const matchRecursively = (templateIndex: number, targetIndex: number): boolean => {\n if (templateIndex >= templateSegments.length) {\n return targetIndex >= targetSegments.length\n }\n\n const templateSegment = templateSegments[templateIndex]\n const token = parsePathParamToken(templateSegment)\n if (!token) {\n if (targetIndex >= targetSegments.length || templateSegment !== targetSegments[targetIndex]) {\n return false\n }\n return matchRecursively(templateIndex + 1, targetIndex + 1)\n }\n\n if (token.modifier === '') {\n if (targetIndex >= targetSegments.length) {\n return false\n }\n pushValue(token.key, decodeRouteParamSegment(targetSegments[targetIndex]))\n const matched = matchRecursively(templateIndex + 1, targetIndex + 1)\n if (!matched) {\n popValue(token.key)\n }\n return matched\n }\n\n if (token.modifier === '?') {\n if (targetIndex < targetSegments.length) {\n pushValue(token.key, decodeRouteParamSegment(targetSegments[targetIndex]))\n const consumeMatched = matchRecursively(templateIndex + 1, targetIndex + 1)\n if (consumeMatched) {\n return true\n }\n popValue(token.key)\n }\n return matchRecursively(templateIndex + 1, targetIndex)\n }\n\n const minimumCount = token.modifier === '+' ? 1 : 0\n const maximumCount = targetSegments.length - targetIndex\n\n for (let count = maximumCount; count >= minimumCount; count -= 1) {\n const rollback = consumeRepeatableToken(token.key, targetIndex, count)\n const matched = matchRecursively(templateIndex + 1, targetIndex + count)\n if (matched) {\n return true\n }\n rollback()\n }\n\n return false\n }\n\n if (!matchRecursively(0, 0)) {\n return undefined\n }\n\n return buildRouteParamsFromMatch(matchedValues)\n}\n\nexport function resolveMatchedRouteRecord(\n target: RouteLocationNormalizedLoaded,\n lookup: NamedRouteLookup,\n): MatchedRouteRecordResolveResult | undefined {\n if (target.name) {\n const byName = lookup.recordByName.get(target.name)\n if (byName) {\n return {\n record: byName,\n matchedRecords: resolveMatchedRouteRecordChain(byName, lookup),\n }\n }\n }\n\n const staticNamedRoute = lookup.nameByStaticPath.get(target.path)\n if (staticNamedRoute) {\n const record = lookup.recordByName.get(staticNamedRoute)\n if (record) {\n return {\n record,\n matchedRecords: resolveMatchedRouteRecordChain(record, lookup),\n matchedPath: target.path,\n }\n }\n }\n\n for (const record of lookup.recordByName.values()) {\n for (const routePath of listRouteRecordMatchPaths(record)) {\n if (!isDynamicRoutePath(routePath)) {\n continue\n }\n const matchedParams = matchRoutePathParams(routePath, target.path)\n if (!matchedParams) {\n continue\n }\n return {\n record,\n matchedRecords: resolveMatchedRouteRecordChain(record, lookup),\n matchedPath: routePath,\n params: matchedParams,\n }\n }\n }\n\n return undefined\n}\n"],"mappings":";;;;AAaA,SAAS,uBAAuB,MAAwB;CACtD,OAAO,KAAK,MAAM,GAAG,CAAC,CAAC,OAAO,OAAO;AACvC;AAEA,SAAS,0BAA0B,QAAkD;CACnF,OAAO,CAAC,OAAO,MAAM,GAAG,OAAO,UAAU;AAC3C;AAEA,SAAS,+BACP,QACA,QACyB;CACzB,MAAM,iBAA0C,CAAC;CACjD,MAAM,+BAAe,IAAI,IAAY;CACrC,IAAI,gBAAmD;CAEvD,OAAO,eAAe;EACpB,IAAI,aAAa,IAAI,cAAc,IAAI,GACrC;EAEF,aAAa,IAAI,cAAc,IAAI;EACnC,eAAe,QAAQ,aAAa;EACpC,IAAI,CAAC,cAAc,YACjB;EAEF,gBAAgB,OAAO,aAAa,IAAI,cAAc,UAAU;CAClE;CAEA,OAAO;AACT;AAEA,SAAgB,sBAAsB,gBAAyE;CAC7G,IAAI;CACJ,KAAK,MAAM,iBAAiB,gBAAgB;EAC1C,IAAI,CAAC,cAAc,MACjB;EAEF,IAAI,CAAC,iBACH,kBAAkB,OAAO,OAAO,IAAI;EAEtC,OAAO,OAAO,iBAAiB,cAAc,IAAI;CACnD;CACA,OAAO;AACT;AAEA,SAAgB,4BACd,WACA,cACa;CACb,MAAM,gCAAgB,IAAI,IAAY;CACtC,IAAI,CAAC,aAAa,IAAI,SAAS,GAC7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;GACL,QAAQ;GACR,gBAAgB,+BAA+B,QAAQ,MAAM;EAC/D;CAEJ;CAEA,MAAM,mBAAmB,OAAO,iBAAiB,IAAI,OAAO,IAAI;CAChE,IAAI,kBAAkB;EACpB,MAAM,SAAS,OAAO,aAAa,IAAI,gBAAgB;EACvD,IAAI,QACF,OAAO;GACL;GACA,gBAAgB,+BAA+B,QAAQ,MAAM;GAC7D,aAAa,OAAO;EACtB;CAEJ;CAEA,KAAK,MAAM,UAAU,OAAO,aAAa,OAAO,GAC9C,KAAK,MAAM,aAAa,0BAA0B,MAAM,GAAG;EACzD,IAAI,CAAC,mBAAmB,SAAS,GAC/B;EAEF,MAAM,gBAAgB,qBAAqB,WAAW,OAAO,IAAI;EACjE,IAAI,CAAC,eACH;EAEF,OAAO;GACL;GACA,gBAAgB,+BAA+B,QAAQ,MAAM;GAC7D,aAAa;GACb,QAAQ;EACV;CACF;AAIJ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"params.mjs","names":[],"sources":["../../../src/routerInternal/params.ts"],"sourcesContent":["import type {\n RouteLocationRaw,\n RouteParams,\n RouteParamsMode,\n RouteParamValue,\n} from '../router'\nimport type {\n NamedRouteLookup,\n NamedRoutePathResolveResult,\n PathParamToken,\n} from './types'\nimport { normalizeRouteParams } from './query'\n\nconst PATH_PARAM_TOKEN_RE = /^:(\\w+)(?:\\([^)]*\\))?([+*?])?$/\n\nexport function parsePathParamToken(segment: string): PathParamToken | undefined {\n const match = PATH_PARAM_TOKEN_RE.exec(segment)\n if (!match) {\n return undefined\n }\n\n return {\n key: match[1],\n modifier: (match[2] ?? '') as PathParamToken['modifier'],\n }\n}\n\nfunction normalizePathParamValues(value: RouteParamValue | RouteParamValue[] | undefined): RouteParamValue[] {\n if (value === undefined) {\n return []\n }\n if (Array.isArray(value)) {\n return value\n }\n return [value]\n}\n\nfunction stringifyPathParamSegment(value: RouteParamValue): string {\n return encodeURIComponent(value)\n}\n\nexport function decodeRouteParamSegment(value: string): string {\n try {\n return decodeURIComponent(value)\n }\n catch {\n return value\n }\n}\n\nfunction resolveNamedRoutePath(pathTemplate: string, params: RouteParams, routeName: string): NamedRoutePathResolveResult {\n const resolvedSegments: string[] = []\n const consumedKeys = new Set<string>()\n for (const rawSegment of pathTemplate.split('/')) {\n if (!rawSegment) {\n continue\n }\n\n const token = parsePathParamToken(rawSegment)\n if (!token) {\n resolvedSegments.push(rawSegment)\n continue\n }\n\n const values = normalizePathParamValues(params[token.key])\n if (token.modifier === '') {\n if (values.length !== 1) {\n throw new Error(`Missing required param \"${token.key}\" for named route \"${routeName}\"`)\n }\n consumedKeys.add(token.key)\n resolvedSegments.push(stringifyPathParamSegment(values[0]))\n continue\n }\n\n if (token.modifier === '?') {\n if (values.length === 0) {\n continue\n }\n if (values.length > 1) {\n throw new Error(`Param \"${token.key}\" for named route \"${routeName}\" must be a single value`)\n }\n consumedKeys.add(token.key)\n resolvedSegments.push(stringifyPathParamSegment(values[0]))\n continue\n }\n\n if (token.modifier === '+') {\n if (values.length === 0) {\n throw new Error(`Missing required repeatable param \"${token.key}\" for named route \"${routeName}\"`)\n }\n consumedKeys.add(token.key)\n for (const value of values) {\n resolvedSegments.push(stringifyPathParamSegment(value))\n }\n continue\n }\n\n if (values.length > 0) {\n consumedKeys.add(token.key)\n }\n for (const value of values) {\n resolvedSegments.push(stringifyPathParamSegment(value))\n }\n }\n\n return {\n path: resolvedSegments.join('/'),\n consumedKeys,\n }\n}\n\nfunction hasNonEmptyRouteParamValue(value: RouteParamValue | RouteParamValue[] | undefined): boolean {\n if (value === undefined) {\n return false\n }\n if (Array.isArray(value)) {\n return value.length > 0\n }\n return true\n}\n\nfunction assertNoUnexpectedNamedRouteParams(\n params: RouteParams,\n consumedKeys: ReadonlySet<string>,\n routeName: string,\n) {\n const unexpectedKeys = Object.keys(params)\n .filter(key => !consumedKeys.has(key))\n .filter(key => hasNonEmptyRouteParamValue(params[key]))\n\n if (unexpectedKeys.length === 0) {\n return\n }\n\n throw new Error(`Unexpected params for named route \"${routeName}\": ${unexpectedKeys.join(', ')}`)\n}\n\nexport function resolveNamedRouteLocation(\n to:
|
|
1
|
+
{"version":3,"file":"params.mjs","names":[],"sources":["../../../src/routerInternal/params.ts"],"sourcesContent":["import type {\n RouteLocationRaw,\n RouteParams,\n RouteParamsMode,\n RouteParamValue,\n} from '../router'\nimport type {\n NamedRouteLookup,\n NamedRoutePathResolveResult,\n PathParamToken,\n} from './types'\nimport { normalizeRouteParams } from './query'\n\nconst PATH_PARAM_TOKEN_RE = /^:(\\w+)(?:\\([^)]*\\))?([+*?])?$/\n\nexport function parsePathParamToken(segment: string): PathParamToken | undefined {\n const match = PATH_PARAM_TOKEN_RE.exec(segment)\n if (!match) {\n return undefined\n }\n\n return {\n key: match[1],\n modifier: (match[2] ?? '') as PathParamToken['modifier'],\n }\n}\n\nfunction normalizePathParamValues(value: RouteParamValue | RouteParamValue[] | undefined): RouteParamValue[] {\n if (value === undefined) {\n return []\n }\n if (Array.isArray(value)) {\n return value\n }\n return [value]\n}\n\nfunction stringifyPathParamSegment(value: RouteParamValue): string {\n return encodeURIComponent(value)\n}\n\nexport function decodeRouteParamSegment(value: string): string {\n try {\n return decodeURIComponent(value)\n }\n catch {\n return value\n }\n}\n\nfunction resolveNamedRoutePath(pathTemplate: string, params: RouteParams, routeName: string): NamedRoutePathResolveResult {\n const resolvedSegments: string[] = []\n const consumedKeys = new Set<string>()\n for (const rawSegment of pathTemplate.split('/')) {\n if (!rawSegment) {\n continue\n }\n\n const token = parsePathParamToken(rawSegment)\n if (!token) {\n resolvedSegments.push(rawSegment)\n continue\n }\n\n const values = normalizePathParamValues(params[token.key])\n if (token.modifier === '') {\n if (values.length !== 1) {\n throw new Error(`Missing required param \"${token.key}\" for named route \"${routeName}\"`)\n }\n consumedKeys.add(token.key)\n resolvedSegments.push(stringifyPathParamSegment(values[0]))\n continue\n }\n\n if (token.modifier === '?') {\n if (values.length === 0) {\n continue\n }\n if (values.length > 1) {\n throw new Error(`Param \"${token.key}\" for named route \"${routeName}\" must be a single value`)\n }\n consumedKeys.add(token.key)\n resolvedSegments.push(stringifyPathParamSegment(values[0]))\n continue\n }\n\n if (token.modifier === '+') {\n if (values.length === 0) {\n throw new Error(`Missing required repeatable param \"${token.key}\" for named route \"${routeName}\"`)\n }\n consumedKeys.add(token.key)\n for (const value of values) {\n resolvedSegments.push(stringifyPathParamSegment(value))\n }\n continue\n }\n\n if (values.length > 0) {\n consumedKeys.add(token.key)\n }\n for (const value of values) {\n resolvedSegments.push(stringifyPathParamSegment(value))\n }\n }\n\n return {\n path: resolvedSegments.join('/'),\n consumedKeys,\n }\n}\n\nfunction hasNonEmptyRouteParamValue(value: RouteParamValue | RouteParamValue[] | undefined): boolean {\n if (value === undefined) {\n return false\n }\n if (Array.isArray(value)) {\n return value.length > 0\n }\n return true\n}\n\nfunction assertNoUnexpectedNamedRouteParams(\n params: RouteParams,\n consumedKeys: ReadonlySet<string>,\n routeName: string,\n) {\n const unexpectedKeys = Object.keys(params)\n .filter(key => !consumedKeys.has(key))\n .filter(key => hasNonEmptyRouteParamValue(params[key]))\n\n if (unexpectedKeys.length === 0) {\n return\n }\n\n throw new Error(`Unexpected params for named route \"${routeName}\": ${unexpectedKeys.join(', ')}`)\n}\n\nexport function resolveNamedRouteLocation(\n to: Exclude<RouteLocationRaw, string>,\n lookup: NamedRouteLookup,\n paramsMode: RouteParamsMode,\n): Exclude<RouteLocationRaw, string> {\n const routeName = to.name\n if (typeof routeName !== 'string' || !routeName) {\n return to\n }\n if (to.path !== undefined || to.fullPath !== undefined) {\n return to\n }\n\n const routeRecord = lookup.recordByName.get(routeName)\n if (!routeRecord) {\n throw new Error(`Named route \"${routeName}\" is not defined in createRouter({ routes | namedRoutes })`)\n }\n\n const params = to.params\n ? normalizeRouteParams(to.params)\n : {}\n const resolvedResult = resolveNamedRoutePath(routeRecord.path, params, routeName)\n if (paramsMode === 'strict') {\n assertNoUnexpectedNamedRouteParams(params, resolvedResult.consumedKe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G,MAAM,IAC9B,CAAC;CACL,MAAM,iBAAiB,sBAAsB,YAAY,MAAM,QAAQ,SAAS;CAChF,IAAI,eAAe,UACjB,mCAAmC,QAAQ,eAAe,cAAc,SAAS;CAGnF,OAAO;EACL,GAAG;EACH,MAAM,eAAe,OAAO,IAAI,eAAe,SAAS;EACxD;CACF;AACF"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { RouteResolveCodec } from "./types.mjs";
|
|
2
|
+
import "./location.mjs";
|
|
3
|
+
import "./matching.mjs";
|
|
4
|
+
import "./params.mjs";
|
|
5
|
+
import { parseQuery, stringifyQuery } from "./query.mjs";
|
|
6
|
+
import "./records.mjs";
|
|
7
|
+
import "./recordsWarnings.mjs";
|
|
8
|
+
import "./snapshots.mjs";
|
|
9
|
+
export { type RouteResolveCodec, parseQuery, stringifyQuery };
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { getCurrentMiniProgramRuntimeCapabilities, getMiniProgramGlobalObject, supportsCurrentMiniProgramRuntimeCapability } from "../platform.mjs";
|
|
2
|
-
import { WEVU_HOOKS_KEY } from "@weapp-core/constants";
|
|
1
|
+
import { getCurrentMiniProgramRuntimeCapabilities, getMiniProgramGlobalObject, getMiniProgramRuntimeGlobalObject, supportsCurrentMiniProgramRuntimeCapability } from "../platform.mjs";
|
|
2
|
+
import { WEVU_CURRENT_SETUP_STATE_KEY, WEVU_HOOKS_KEY } from "@weapp-core/constants";
|
|
3
3
|
|
|
4
4
|
//#region src/runtime/hooks/base.ts
|
|
5
5
|
const currentSetupState = (() => {
|
|
6
|
-
var _host$
|
|
7
|
-
const host = globalThis;
|
|
8
|
-
return (_host$
|
|
6
|
+
var _host$WEVU_CURRENT_SE;
|
|
7
|
+
const host = typeof globalThis !== "undefined" ? globalThis : getMiniProgramRuntimeGlobalObject();
|
|
8
|
+
return host ? (_host$WEVU_CURRENT_SE = host[WEVU_CURRENT_SETUP_STATE_KEY]) !== null && _host$WEVU_CURRENT_SE !== void 0 ? _host$WEVU_CURRENT_SE : host[WEVU_CURRENT_SETUP_STATE_KEY] = {} : {};
|
|
9
9
|
})();
|
|
10
10
|
function getCurrentInstance() {
|
|
11
11
|
return currentSetupState.instance;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.mjs","names":[],"sources":["../../../../src/runtime/hooks/base.ts"],"sourcesContent":["import type { InternalRuntimeState } from '../types'\nimport { WEVU_HOOKS_KEY } from '@weapp-core/constants'\nimport { getCurrentMiniProgramRuntimeCapabilities, getMiniProgramGlobalObject, supportsCurrentMiniProgramRuntimeCapability } from '../platform'\n\n// 仅供同步 setup() 调用期间使用的当前实例引用。wevu 的根入口与\n// `wevu/router` 可能被打包成多个模块副本,必须通过宿主全局共享状态。\ninterface CurrentSetupState {\n instance?: InternalRuntimeState\n context?: any\n}\n\nconst currentSetupState: CurrentSetupState = (() => {\n const host = globalThis as typeof globalThis & { __wevuCurrentSetupState__?: CurrentSetupState }\n return host.__wevuCurrentSetupState__ ??= {}\n})()\n\nexport function getCurrentInstance<T extends InternalRuntimeState = InternalRuntimeState>(): T | undefined {\n return currentSetupState.instance as T | undefined\n}\n\n/**\n * 设置当前运行时实例(框架内部使用)。\n * @internal\n */\nexport function setCurrentInstance(inst: InternalRuntimeState | undefined) {\n currentSetupState.instance = inst\n}\n\nexport function getCurrentSetupContext<T = any>(): T | undefined {\n return currentSetupState.context as T | undefined\n}\n\n/**\n * 设置当前 setup 上下文(框架内部使用)。\n * @internal\n */\nexport function setCurrentSetupContext(ctx: any | undefined) {\n currentSetupState.context = ctx\n}\n\nexport function assertInSetup(name: string): InternalRuntimeState {\n if (!currentSetupState.instance) {\n throw new Error(`${name}() 必须在 setup() 的同步阶段调用`)\n }\n return currentSetupState.instance\n}\n\nfunction ensureHookBucket(target: InternalRuntimeState): Record<string, any> {\n if (!target[WEVU_HOOKS_KEY]) {\n target[WEVU_HOOKS_KEY] = Object.create(null)\n }\n return target[WEVU_HOOKS_KEY] as Record<string, any>\n}\n\ntype ShareMenuName = 'shareAppMessage' | 'shareTimeline'\n\nfunction buildShareMenus(\n enableOnShareAppMessage: boolean,\n enableOnShareTimeline: boolean,\n): ShareMenuName[] {\n const runtimeCapabilities = getCurrentMiniProgramRuntimeCapabilities()\n const shouldShowShareAppMessage = runtimeCapabilities.shareTimelineRequiresShareAppMessage\n ? (enableOnShareAppMessage || enableOnShareTimeline)\n : enableOnShareAppMessage\n\n const menus: ShareMenuName[] = []\n if (shouldShowShareAppMessage) {\n menus.push('shareAppMessage')\n }\n if (enableOnShareTimeline) {\n menus.push('shareTimeline')\n }\n return menus\n}\n\nfunction tryShowShareMenu(showShareMenu: (...args: any[]) => unknown, menus: ShareMenuName[]) {\n const payloads = [\n { withShareTicket: true, menus },\n { menus },\n menus.includes('shareTimeline') ? { withShareTicket: true } : undefined,\n menus.includes('shareTimeline') ? {} : undefined,\n undefined,\n ]\n\n for (const payload of payloads) {\n try {\n if (payload === undefined) {\n showShareMenu()\n }\n else {\n showShareMenu(payload as any)\n }\n return\n }\n catch {\n // 继续尝试更保守的 payload,兼容不同宿主的 showShareMenu 参数形态。\n }\n }\n}\n\nexport function pushHook(\n target: InternalRuntimeState,\n name: string,\n handler: (...args: any[]) => any,\n { single = false } = {},\n) {\n const bucket = ensureHookBucket(target)\n if (single) {\n bucket[name] = handler\n }\n else {\n const list: Array<(...args: any[]) => any> = bucket[name] ?? (bucket[name] = [])\n list.push(handler)\n }\n}\n\nexport function ensureSinglePageHookOnInstance(target: InternalRuntimeState, name: 'onShareAppMessage' | 'onShareTimeline' | 'onAddToFavorites') {\n const bridges = ((target as any).__wevuShareHookBridges ??= Object.create(null)) as Record<string, (...args: any[]) => any>\n if (typeof bridges[name] === 'function') {\n return\n }\n\n const original = (target as any)[name]\n const bridge = function onWevuShareHookBridge(this: InternalRuntimeState, ...args: any[]) {\n const hooks = this[WEVU_HOOKS_KEY] as Record<string, any> | undefined\n const entry = hooks?.[name]\n const runtime = this.__wevu\n const ctx = runtime?.proxy ?? this\n let ret: any\n\n if (typeof entry === 'function') {\n try {\n ret = entry.apply(ctx, args)\n }\n catch {\n ret = undefined\n }\n }\n else if (Array.isArray(entry)) {\n for (const fn of entry) {\n try {\n ret = fn.apply(ctx, args)\n }\n catch {\n // 忽略单个 hook 抛出的异常,继续执行后续 hook\n }\n }\n }\n\n if (ret !== undefined) {\n return ret\n }\n if (typeof original === 'function') {\n return original.apply(this, args)\n }\n return undefined\n }\n\n bridges[name] = bridge\n ;(target as any)[name] = bridge\n}\n\nexport function ensurePageShareMenusOnSetup(target: InternalRuntimeState) {\n if (!supportsCurrentMiniProgramRuntimeCapability('pageShareMenu')) {\n return\n }\n const miniProgramGlobal = getMiniProgramGlobalObject()\n if (!miniProgramGlobal || typeof miniProgramGlobal.showShareMenu !== 'function') {\n return\n }\n\n const hooks = (target[WEVU_HOOKS_KEY] ?? {}) as Record<string, any>\n const hasShareAppMessage = typeof hooks.onShareAppMessage === 'function'\n const hasShareTimeline = typeof hooks.onShareTimeline === 'function'\n\n if (!hasShareAppMessage && !hasShareTimeline) {\n return\n }\n\n const menus = buildShareMenus(hasShareAppMessage, hasShareTimeline)\n if (!menus.length) {\n return\n }\n\n tryShowShareMenu(miniProgramGlobal.showShareMenu.bind(miniProgramGlobal), menus)\n}\n\n/**\n * 调用批量 hook(框架内部调度入口)。\n * @internal\n */\nexport function callHookList(target: InternalRuntimeState, name: string, args: any[] = []) {\n const hooks = target[WEVU_HOOKS_KEY]\n if (!hooks) {\n return\n }\n const list = hooks[name]\n if (!list) {\n return\n }\n const runtime = target.__wevu\n const ctx = runtime?.proxy ?? target\n if (Array.isArray(list)) {\n for (const fn of list) {\n try {\n fn.apply(ctx, args)\n }\n catch {\n // 忽略单个 hook 抛出的异常,防止阻塞其他监听\n }\n }\n }\n else if (typeof list === 'function') {\n try {\n list.apply(ctx, args)\n }\n catch {\n // 忽略单个 hook 抛出的异常,防止阻塞其他监听\n }\n }\n}\n\nexport function ensurePageHookOnInstance(target: InternalRuntimeState, name: 'onPageScroll') {\n const bridges = ((target as any).__wevuPageHookBridges ??= Object.create(null)) as Record<string, (...args: any[]) => any>\n if (typeof bridges[name] === 'function') {\n return\n }\n\n const original = (target as any)[name]\n const bridge = function onWevuPageHookBridge(this: InternalRuntimeState, ...args: any[]) {\n callHookList(this, name, args)\n if (typeof original === 'function') {\n return original.apply(this, args)\n }\n return undefined\n }\n\n bridges[name] = bridge\n ;(target as any)[name] = bridge\n}\n\n/**\n * 调用返回值型 hook(框架内部调度入口)。\n * @internal\n */\nexport function callHookReturn(target: InternalRuntimeState, name: string, args: any[] = []) {\n const hooks = target[WEVU_HOOKS_KEY]\n if (!hooks) {\n return undefined\n }\n const entry = hooks[name]\n if (!entry) {\n return undefined\n }\n const runtime = target.__wevu\n const ctx = runtime?.proxy ?? target\n if (typeof entry === 'function') {\n try {\n return entry.apply(ctx, args)\n }\n catch {\n return undefined\n }\n }\n if (Array.isArray(entry)) {\n let out: any\n for (const fn of entry) {\n try {\n out = fn.apply(ctx, args)\n }\n catch {\n // 忽略单个 hook 抛出的异常,继续执行后续 hook\n }\n }\n return out\n }\n return undefined\n}\n"],"mappings":";;;;AAWA,MAAM,2BAA8C;;CAClD,MAAM,OAAO;CACb,gCAAO,KAAK,kGAAL,KAAK,4BAA8B,CAAC;AAC7C,EAAC,CAAE;AAEH,SAAgB,qBAA2F;CACzG,OAAO,kBAAkB;AAC3B;;;;;AAMA,SAAgB,mBAAmB,MAAwC;CACzE,kBAAkB,WAAW;AAC/B;AAEA,SAAgB,yBAAiD;CAC/D,OAAO,kBAAkB;AAC3B;;;;;AAMA,SAAgB,uBAAuB,KAAsB;CAC3D,kBAAkB,UAAU;AAC9B;AAEA,SAAgB,cAAc,MAAoC;CAChE,IAAI,CAAC,kBAAkB,UACrB,MAAM,IAAI,MAAM,GAAG,KAAK,uBAAuB;CAEjD,OAAO,kBAAkB;AAC3B;AAEA,SAAS,iBAAiB,QAAmD;CAC3E,IAAI,CAAC,OAAO,iBACV,OAAO,k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C7E,IAAI,OAAO,QAAQ,UAAU,YAC3B;CAGF,MAAM,WAAY,OAAe;CACjC,MAAM,SAAS,SAAS,qBAAiD,GAAG,MAAa;EACvF,aAAa,MAAM,MAAM,IAAI;EAC7B,IAAI,OAAO,aAAa,YACtB,OAAO,SAAS,MAAM,MAAM,IAAI;CAGpC;CAEA,QAAQ,QAAQ;CACf,AAAC,OAAe,QAAQ;AAC3B;;;;;AAMA,SAAgB,eAAe,QAA8B,MAAc,OAAc,CAAC,GAAG;;CAC3F,MAAM,QAAQ,OAAO;CACrB,IAAI,CAAC,OACH;CAEF,MAAM,QAAQ,MAAM;CACpB,IAAI,CAAC,OACH;CAEF,MAAM,UAAU,OAAO;CACvB,MAAM,2EAAM,QAAS,kEAAS;CAC9B,IAAI,OAAO,UAAU,YACnB,IAAI;EACF,OAAO,MAAM,MAAM,KAAK,IAAI;CAC9B,mBACM;EACJ;CACF;CAEF,IAAI,MAAM,QAAQ,KAAK,GAAG;EACxB,IAAI;EACJ,KAAK,MAAM,MAAM,OACf,IAAI;GACF,MAAM,GAAG,MAAM,KAAK,IAAI;EAC1B,mBACM,CAEN;EAEF,OAAO;CACT;AAEF"}
|
|
1
|
+
{"version":3,"file":"base.mjs","names":[],"sources":["../../../../src/runtime/hooks/base.ts"],"sourcesContent":["import type { InternalRuntimeState } from '../types'\nimport { WEVU_CURRENT_SETUP_STATE_KEY, WEVU_HOOKS_KEY } from '@weapp-core/constants'\nimport { getCurrentMiniProgramRuntimeCapabilities, getMiniProgramGlobalObject, getMiniProgramRuntimeGlobalObject, supportsCurrentMiniProgramRuntimeCapability } from '../platform'\n\n// 仅供同步 setup() 调用期间使用的当前实例引用。wevu 的根入口与\n// `wevu/router` 可能被打包成多个模块副本,必须通过宿主全局共享状态。\ninterface CurrentSetupState {\n instance?: InternalRuntimeState\n context?: any\n}\n\nconst currentSetupState: CurrentSetupState = (() => {\n // Web 会在模块加载后安装宿主 API;可用时优先使用稳定的执行域全局,\n // 防止不同入口因导入时机不同而持有两份 setup 状态。\n const host = typeof globalThis !== 'undefined'\n ? globalThis as Record<string, any>\n : getMiniProgramRuntimeGlobalObject()\n return host ? host[WEVU_CURRENT_SETUP_STATE_KEY] ??= {} : {}\n})()\n\nexport function getCurrentInstance<T extends InternalRuntimeState = InternalRuntimeState>(): T | undefined {\n return currentSetupState.instance as T | undefined\n}\n\n/**\n * 设置当前运行时实例(框架内部使用)。\n * @internal\n */\nexport function setCurrentInstance(inst: InternalRuntimeState | undefined) {\n currentSetupState.instance = inst\n}\n\nexport function getCurrentSetupContext<T = any>(): T | undefined {\n return currentSetupState.context as T | undefined\n}\n\n/**\n * 设置当前 setup 上下文(框架内部使用)。\n * @internal\n */\nexport function setCurrentSetupContext(ctx: any | undefined) {\n currentSetupState.context = ctx\n}\n\nexport function assertInSetup(name: string): InternalRuntimeState {\n if (!currentSetupState.instance) {\n throw new Error(`${name}() 必须在 setup() 的同步阶段调用`)\n }\n return currentSetupState.instance\n}\n\nfunction ensureHookBucket(target: InternalRuntimeState): Record<string, any> {\n if (!target[WEVU_HOOKS_KEY]) {\n target[WEVU_HOOKS_KEY] = Object.create(null)\n }\n return target[WEVU_HOOKS_KEY] as Record<string, any>\n}\n\ntype ShareMenuName = 'shareAppMessage' | 'shareTimeline'\n\nfunction buildShareMenus(\n enableOnShareAppMessage: boolean,\n enableOnShareTimeline: boolean,\n): ShareMenuName[] {\n const runtimeCapabilities = getCurrentMiniProgramRuntimeCapabilities()\n const shouldShowShareAppMessage = runtimeCapabilities.shareTimelineRequiresShareAppMessage\n ? (enableOnShareAppMessage || enableOnShareTimeline)\n : enableOnShareAppMessage\n\n const menus: ShareMenuName[] = []\n if (shouldShowShareAppMessage) {\n menus.push('shareAppMessage')\n }\n if (enableOnShareTimeline) {\n menus.push('shareTimeline')\n }\n return menus\n}\n\nfunction tryShowShareMenu(showShareMenu: (...args: any[]) => unknown, menus: ShareMenuName[]) {\n const payloads = [\n { withShareTicket: true, menus },\n { menus },\n menus.includes('shareTimeline') ? { withShareTicket: true } : undefined,\n menus.includes('shareTimeline') ? {} : undefined,\n undefined,\n ]\n\n for (const payload of payloads) {\n try {\n if (payload === undefined) {\n showShareMenu()\n }\n else {\n showShareMenu(payload as any)\n }\n return\n }\n catch {\n // 继续尝试更保守的 payload,兼容不同宿主的 showShareMenu 参数形态。\n }\n }\n}\n\nexport function pushHook(\n target: InternalRuntimeState,\n name: string,\n handler: (...args: any[]) => any,\n { single = false } = {},\n) {\n const bucket = ensureHookBucket(target)\n if (single) {\n bucket[name] = handler\n }\n else {\n const list: Array<(...args: any[]) => any> = bucket[name] ?? (bucket[name] = [])\n list.push(handler)\n }\n}\n\nexport function ensureSinglePageHookOnInstance(target: InternalRuntimeState, name: 'onShareAppMessage' | 'onShareTimeline' | 'onAddToFavorites') {\n const bridges = ((target as any).__wevuShareHookBridges ??= Object.create(null)) as Record<string, (...args: any[]) => any>\n if (typeof bridges[name] === 'function') {\n return\n }\n\n const original = (target as any)[name]\n const bridge = function onWevuShareHookBridge(this: InternalRuntimeState, ...args: any[]) {\n const hooks = this[WEVU_HOOKS_KEY] as Record<string, any> | undefined\n const entry = hooks?.[name]\n const runtime = this.__wevu\n const ctx = runtime?.proxy ?? this\n let ret: any\n\n if (typeof entry === 'function') {\n try {\n ret = entry.apply(ctx, args)\n }\n catch {\n ret = undefined\n }\n }\n else if (Array.isArray(entry)) {\n for (const fn of entry) {\n try {\n ret = fn.apply(ctx, args)\n }\n catch {\n // 忽略单个 hook 抛出的异常,继续执行后续 hook\n }\n }\n }\n\n if (ret !== undefined) {\n return ret\n }\n if (typeof original === 'function') {\n return original.apply(this, args)\n }\n return undefined\n }\n\n bridges[name] = bridge\n ;(target as any)[name] = bridge\n}\n\nexport function ensurePageShareMenusOnSetup(target: InternalRuntimeState) {\n if (!supportsCurrentMiniProgramRuntimeCapability('pageShareMenu')) {\n return\n }\n const miniProgramGlobal = getMiniProgramGlobalObject()\n if (!miniProgramGlobal || typeof miniProgramGlobal.showShareMenu !== 'function') {\n return\n }\n\n const hooks = (target[WEVU_HOOKS_KEY] ?? {}) as Record<string, any>\n const hasShareAppMessage = typeof hooks.onShareAppMessage === 'function'\n const hasShareTimeline = typeof hooks.onShareTimeline === 'function'\n\n if (!hasShareAppMessage && !hasShareTimeline) {\n return\n }\n\n const menus = buildShareMenus(hasShareAppMessage, hasShareTimeline)\n if (!menus.length) {\n return\n }\n\n tryShowShareMenu(miniProgramGlobal.showShareMenu.bind(miniProgramGlobal), menus)\n}\n\n/**\n * 调用批量 hook(框架内部调度入口)。\n * @internal\n */\nexport function callHookList(target: InternalRuntimeState, name: string, args: any[] = []) {\n const hooks = target[WEVU_HOOKS_KEY]\n if (!hooks) {\n return\n }\n const list = hooks[name]\n if (!list) {\n return\n }\n const runtime = target.__wevu\n const ctx = runtime?.proxy ?? target\n if (Array.isArray(list)) {\n for (const fn of list) {\n try {\n fn.apply(ctx, args)\n }\n catch {\n // 忽略单个 hook 抛出的异常,防止阻塞其他监听\n }\n }\n }\n else if (typeof list === 'function') {\n try {\n list.apply(ctx, args)\n }\n catch {\n // 忽略单个 hook 抛出的异常,防止阻塞其他监听\n }\n }\n}\n\nexport function ensurePageHookOnInstance(target: InternalRuntimeState, name: 'onPageScroll') {\n const bridges = ((target as any).__wevuPageHookBridges ??= Object.create(null)) as Record<string, (...args: any[]) => any>\n if (typeof bridges[name] === 'function') {\n return\n }\n\n const original = (target as any)[name]\n const bridge = function onWevuPageHookBridge(this: InternalRuntimeState, ...args: any[]) {\n callHookList(this, name, args)\n if (typeof original === 'function') {\n return original.apply(this, args)\n }\n return undefined\n }\n\n bridges[name] = bridge\n ;(target as any)[name] = bridge\n}\n\n/**\n * 调用返回值型 hook(框架内部调度入口)。\n * @internal\n */\nexport function callHookReturn(target: InternalRuntimeState, name: string, args: any[] = []) {\n const hooks = target[WEVU_HOOKS_KEY]\n if (!hooks) {\n return undefined\n }\n const entry = hooks[name]\n if (!entry) {\n return undefined\n }\n const runtime = target.__wevu\n const ctx = runtime?.proxy ?? target\n if (typeof entry === 'function') {\n try {\n return entry.apply(ctx, args)\n }\n catch {\n return undefined\n }\n }\n if (Array.isArray(entry)) {\n let out: any\n for (const fn of entry) {\n try {\n out = fn.apply(ctx, args)\n }\n catch {\n // 忽略单个 hook 抛出的异常,继续执行后续 hook\n }\n }\n return out\n }\n return undefined\n}\n"],"mappings":";;;;AAWA,MAAM,2BAA8C;;CAGlD,MAAM,OAAO,OAAO,eAAe,cAC/B,aACA,kCAAkC;CACtC,OAAO,gCAAO,KAAK,sGAAL,KAAK,gCAAkC,CAAC,IAAI,CAAC;AAC7D,EAAC,CAAE;AAEH,SAAgB,qBAA2F;CACzG,OAAO,kBAAkB;AAC3B;;;;;AAMA,SAAgB,mBAAmB,MAAwC;CACzE,kBAAkB,WAAW;AAC/B;AAEA,SAAgB,yBAAiD;CAC/D,OAAO,kBAAkB;AAC3B;;;;;AAMA,SAAgB,uBAAuB,KAAsB;CAC3D,kBAAkB,UAAU;AAC9B;AAEA,SAAgB,cAAc,MAAoC;CAChE,IAAI,CAAC,kBAAkB,UACrB,MAAM,IAAI,MAAM,GAAG,KAAK,uBAAuB;CAEjD,OAAO,kBAAkB;AAC3B;AAEA,SAAS,iBAAiB,QAAmD;CAC3E,IAAI,CAAC,OAAO,iBACV,OAAO,kBAAkB,OAAO,OAAO,IAAI;CAE7C,OAAO,OAAO;AAChB;AAIA,SAAS,gBACP,yBACA,uBACiB;CAEjB,MAAM,4BADsB,yCACwB,CAAC,CAAC,uCACjD,2BAA2B,wBAC5B;CAEJ,MAAM,QAAyB,CAAC;CAChC,IAAI,2BACF,MAAM,KAAK,iBAAiB;CAE9B,IAAI,uBACF,MAAM,KAAK,eAAe;CAE5B,OAAO;AACT;AAEA,SAAS,iBAAiB,eAA4C,OAAwB;CAC5F,MAAM,WAAW;EACf;GAAE,iBAAiB;GAAM;EAAM;EAC/B,EAAE,MAAM;EACR,MAAM,SAAS,eAAe,IAAI,EAAE,iBAAiB,KAAK,IAAI;EAC9D,M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CACvB,MAAM,2EAAM,QAAS,kEAAS;CAC9B,IAAI,OAAO,UAAU,YACnB,IAAI;EACF,OAAO,MAAM,MAAM,KAAK,IAAI;CAC9B,mBACM;EACJ;CACF;CAEF,IAAI,MAAM,QAAQ,KAAK,GAAG;EACxB,IAAI;EACJ,KAAK,MAAM,MAAM,OACf,IAAI;GACF,MAAM,GAAG,MAAM,KAAK,IAAI;EAC1B,mBACM,CAEN;EAEF,OAAO;CACT;AAEF"}
|
|
@@ -12,16 +12,26 @@ function getGlobalRuntime() {
|
|
|
12
12
|
if (typeof globalThis === "undefined") return;
|
|
13
13
|
return globalThis;
|
|
14
14
|
}
|
|
15
|
-
function getStaticMiniProgramGlobalObject() {
|
|
16
|
-
|
|
15
|
+
function getStaticMiniProgramGlobalObject(globalKey) {
|
|
16
|
+
switch (globalKey) {
|
|
17
|
+
case "wx": return typeof wx !== "undefined" ? wx : void 0;
|
|
18
|
+
case "my": return typeof my !== "undefined" ? my : void 0;
|
|
19
|
+
case "tt": return typeof tt !== "undefined" ? tt : void 0;
|
|
20
|
+
case "swan": return typeof swan !== "undefined" ? swan : void 0;
|
|
21
|
+
case "jd": return typeof jd !== "undefined" ? jd : void 0;
|
|
22
|
+
case "xhs": return typeof xhs !== "undefined" ? xhs : void 0;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function resolveRuntimeGlobalObject(globalKey) {
|
|
26
|
+
var _getGlobalRuntime$glo, _getGlobalRuntime;
|
|
27
|
+
return (_getGlobalRuntime$glo = (_getGlobalRuntime = getGlobalRuntime()) === null || _getGlobalRuntime === void 0 ? void 0 : _getGlobalRuntime[globalKey]) !== null && _getGlobalRuntime$glo !== void 0 ? _getGlobalRuntime$glo : getStaticMiniProgramGlobalObject(globalKey);
|
|
17
28
|
}
|
|
18
29
|
function resolveCurrentMiniProgramPlatform() {
|
|
19
30
|
var _env;
|
|
20
|
-
const globalRuntime = getGlobalRuntime();
|
|
21
31
|
const compiledPlatform = (_env = import.meta.env) === null || _env === void 0 ? void 0 : _env.PLATFORM;
|
|
22
32
|
const resolvedCompiledPlatform = resolveMiniProgramPlatform(compiledPlatform);
|
|
23
33
|
if (resolvedCompiledPlatform) return resolvedCompiledPlatform;
|
|
24
|
-
for (const globalKey of getMiniProgramRuntimeGlobalKeys()) if (
|
|
34
|
+
for (const globalKey of getMiniProgramRuntimeGlobalKeys()) if (resolveRuntimeGlobalObject(globalKey)) return getMiniProgramPlatformByRuntimeGlobalKey(globalKey);
|
|
25
35
|
}
|
|
26
36
|
function getCurrentMiniProgramRuntimeCapabilities() {
|
|
27
37
|
return getMiniProgramRuntimeCapabilities(resolveCurrentMiniProgramPlatform());
|
|
@@ -29,16 +39,28 @@ function getCurrentMiniProgramRuntimeCapabilities() {
|
|
|
29
39
|
function supportsCurrentMiniProgramRuntimeCapability(capabilityName) {
|
|
30
40
|
return supportsMiniProgramRuntimeCapability(resolveCurrentMiniProgramPlatform(), capabilityName);
|
|
31
41
|
}
|
|
42
|
+
function getMiniProgramGlobalObject(platformInput) {
|
|
43
|
+
var _env2;
|
|
44
|
+
const compiledPlatform = platformInput !== null && platformInput !== void 0 ? platformInput : (_env2 = import.meta.env) === null || _env2 === void 0 ? void 0 : _env2.PLATFORM;
|
|
45
|
+
const resolvedCompiledPlatform = resolveMiniProgramPlatform(compiledPlatform);
|
|
46
|
+
if (resolvedCompiledPlatform) {
|
|
47
|
+
var _resolveRuntimeGlobal;
|
|
48
|
+
return (_resolveRuntimeGlobal = resolveRuntimeGlobalObject(getMiniProgramRuntimeGlobalKey(resolvedCompiledPlatform))) !== null && _resolveRuntimeGlobal !== void 0 ? _resolveRuntimeGlobal : resolvedCompiledPlatform === "tt" ? resolveRuntimeGlobalObject("wx") : void 0;
|
|
49
|
+
}
|
|
50
|
+
for (const globalKey of getMiniProgramRuntimeGlobalKeys()) {
|
|
51
|
+
const candidate = resolveRuntimeGlobalObject(globalKey);
|
|
52
|
+
if (candidate) return candidate;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
32
55
|
function getCurrentMiniProgramPages() {
|
|
33
|
-
var _ref,
|
|
56
|
+
var _ref, _miniProgramGlobal$ge;
|
|
34
57
|
if (!supportsCurrentMiniProgramRuntimeCapability("globalPageStack")) return [];
|
|
35
58
|
const globalRuntime = getGlobalRuntime();
|
|
36
|
-
const
|
|
37
|
-
const
|
|
38
|
-
const getCurrentPagesFn = (_ref = (_ref2 = runtimeGlobalKey ? globalRuntime === null || globalRuntime === void 0 || (_globalRuntime$runtim = globalRuntime[runtimeGlobalKey]) === null || _globalRuntime$runtim === void 0 ? void 0 : _globalRuntime$runtim.getCurrentPages : void 0) !== null && _ref2 !== void 0 ? _ref2 : (_getStaticMiniProgram = getStaticMiniProgramGlobalObject()) === null || _getStaticMiniProgram === void 0 ? void 0 : _getStaticMiniProgram.getCurrentPages) !== null && _ref !== void 0 ? _ref : globalRuntime === null || globalRuntime === void 0 ? void 0 : globalRuntime.getCurrentPages;
|
|
59
|
+
const miniProgramGlobal = getMiniProgramGlobalObject();
|
|
60
|
+
const getCurrentPagesFn = (_ref = (_miniProgramGlobal$ge = miniProgramGlobal === null || miniProgramGlobal === void 0 ? void 0 : miniProgramGlobal.getCurrentPages) !== null && _miniProgramGlobal$ge !== void 0 ? _miniProgramGlobal$ge : globalRuntime === null || globalRuntime === void 0 ? void 0 : globalRuntime.getCurrentPages) !== null && _ref !== void 0 ? _ref : typeof getCurrentPages !== "undefined" ? getCurrentPages : void 0;
|
|
39
61
|
if (typeof getCurrentPagesFn !== "function") return [];
|
|
40
62
|
try {
|
|
41
|
-
const pages = getCurrentPagesFn();
|
|
63
|
+
const pages = getCurrentPagesFn.call(miniProgramGlobal);
|
|
42
64
|
return Array.isArray(pages) ? pages : [];
|
|
43
65
|
} catch (_unused) {
|
|
44
66
|
return [];
|
|
@@ -50,21 +72,6 @@ function getCurrentMiniProgramHostConfig() {
|
|
|
50
72
|
const hostConfig = globalRuntime === null || globalRuntime === void 0 ? void 0 : globalRuntime[hostConfigKey];
|
|
51
73
|
return hostConfig && typeof hostConfig === "object" ? hostConfig : void 0;
|
|
52
74
|
}
|
|
53
|
-
function getMiniProgramGlobalObject(platformInput) {
|
|
54
|
-
var _env2;
|
|
55
|
-
const globalRuntime = getGlobalRuntime();
|
|
56
|
-
const compiledPlatform = platformInput !== null && platformInput !== void 0 ? platformInput : (_env2 = import.meta.env) === null || _env2 === void 0 ? void 0 : _env2.PLATFORM;
|
|
57
|
-
const resolvedCompiledPlatform = resolveMiniProgramPlatform(compiledPlatform);
|
|
58
|
-
if (resolvedCompiledPlatform) {
|
|
59
|
-
var _ref3;
|
|
60
|
-
const globalKey = getMiniProgramRuntimeGlobalKey(resolvedCompiledPlatform);
|
|
61
|
-
return (_ref3 = globalRuntime === null || globalRuntime === void 0 ? void 0 : globalRuntime[globalKey]) !== null && _ref3 !== void 0 ? _ref3 : resolvedCompiledPlatform === "alipay" ? getStaticMiniProgramGlobalObject() : void 0;
|
|
62
|
-
}
|
|
63
|
-
for (const globalKey of getMiniProgramRuntimeGlobalKeys()) {
|
|
64
|
-
const candidate = globalRuntime === null || globalRuntime === void 0 ? void 0 : globalRuntime[globalKey];
|
|
65
|
-
if (candidate) return candidate;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
75
|
function getMiniProgramRuntimeGlobalObject() {
|
|
69
76
|
var _getMiniProgramGlobal;
|
|
70
77
|
return (_getMiniProgramGlobal = getMiniProgramGlobalObject()) !== null && _getMiniProgramGlobal !== void 0 ? _getMiniProgramGlobal : getGlobalRuntime();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"platform.mjs","names":[],"sources":["../../../src/runtime/platform.ts"],"sourcesContent":["import type { MiniProgramRuntimeCapabilities, MiniProgramRuntimeCapabilityName } from '@weapp-core/shared/platforms'\nimport {\n getMiniProgramPlatformByRuntimeGlobalKey,\n getMiniProgramRuntimeCapabilities,\n getMiniProgramRuntimeGlobalKey,\n getMiniProgramRuntimeGlobalKeys,\n getMiniProgramRuntimeHostConfigKey,\n resolveMiniProgramPlatform,\n supportsMiniProgramRuntimeCapability,\n} from '@weapp-core/shared/platforms'\n\ntype MiniProgramGlobal = Record<string, any>\ntype MiniProgramHostConfig = Record<string, any>\ntype MiniProgramGlobalRouterMethodName = 'switchTab' | 'reLaunch' | 'redirectTo' | 'navigateTo' | 'navigateBack'\ntype MiniProgramGlobalRouter = Record<MiniProgramGlobalRouterMethodName, (...args: any[]) => any>\ntype ImportMetaWithEnv = ImportMeta & {\n env?: {\n PLATFORM?: string\n }\n}\nconst MINI_PROGRAM_GLOBAL_ROUTER_METHODS: readonly MiniProgramGlobalRouterMethodName[] = [\n 'switchTab',\n 'reLaunch',\n 'redirectTo',\n 'navigateTo',\n 'navigateBack',\n]\n\nfunction getGlobalRuntime() {\n if (typeof globalThis === 'undefined') {\n return undefined\n }\n return globalThis as MiniProgramGlobal\n}\n\nfunction getStaticMiniProgramGlobalObject(): MiniProgramGlobal | undefined {\n
|
|
1
|
+
{"version":3,"file":"platform.mjs","names":[],"sources":["../../../src/runtime/platform.ts"],"sourcesContent":["import type { MiniProgramRuntimeCapabilities, MiniProgramRuntimeCapabilityName } from '@weapp-core/shared/platforms'\nimport {\n getMiniProgramPlatformByRuntimeGlobalKey,\n getMiniProgramRuntimeCapabilities,\n getMiniProgramRuntimeGlobalKey,\n getMiniProgramRuntimeGlobalKeys,\n getMiniProgramRuntimeHostConfigKey,\n resolveMiniProgramPlatform,\n supportsMiniProgramRuntimeCapability,\n} from '@weapp-core/shared/platforms'\n\ntype MiniProgramGlobal = Record<string, any>\ndeclare const tt: MiniProgramGlobal | undefined\ndeclare const swan: MiniProgramGlobal | undefined\ndeclare const jd: MiniProgramGlobal | undefined\ndeclare const xhs: MiniProgramGlobal | undefined\ntype MiniProgramHostConfig = Record<string, any>\ntype MiniProgramGlobalRouterMethodName = 'switchTab' | 'reLaunch' | 'redirectTo' | 'navigateTo' | 'navigateBack'\ntype MiniProgramGlobalRouter = Record<MiniProgramGlobalRouterMethodName, (...args: any[]) => any>\ntype ImportMetaWithEnv = ImportMeta & {\n env?: {\n PLATFORM?: string\n }\n}\nconst MINI_PROGRAM_GLOBAL_ROUTER_METHODS: readonly MiniProgramGlobalRouterMethodName[] = [\n 'switchTab',\n 'reLaunch',\n 'redirectTo',\n 'navigateTo',\n 'navigateBack',\n]\n\nfunction getGlobalRuntime() {\n if (typeof globalThis === 'undefined') {\n return undefined\n }\n return globalThis as MiniProgramGlobal\n}\n\nfunction getStaticMiniProgramGlobalObject(globalKey: string): MiniProgramGlobal | undefined {\n switch (globalKey) {\n case 'wx':\n return typeof wx !== 'undefined' ? wx as MiniProgramGlobal : undefined\n case 'my':\n return typeof my !== 'undefined' ? my as MiniProgramGlobal : undefined\n case 'tt':\n return typeof tt !== 'undefined' ? tt : undefined\n case 'swan':\n return typeof swan !== 'undefined' ? swan : undefined\n case 'jd':\n return typeof jd !== 'undefined' ? jd : undefined\n case 'xhs':\n return typeof xhs !== 'undefined' ? xhs : undefined\n }\n return undefined\n}\n\nfunction resolveRuntimeGlobalObject(globalKey: string): MiniProgramGlobal | undefined {\n return getGlobalRuntime()?.[globalKey] ?? getStaticMiniProgramGlobalObject(globalKey)\n}\n\nexport function resolveCurrentMiniProgramPlatform() {\n const compiledPlatform = (import.meta as ImportMetaWithEnv).env?.PLATFORM\n\n // 优先命中编译期平台分支,便于构建阶段做 dead-code elimination。\n const resolvedCompiledPlatform = resolveMiniProgramPlatform(compiledPlatform)\n if (resolvedCompiledPlatform) {\n return resolvedCompiledPlatform\n }\n\n for (const globalKey of getMiniProgramRuntimeGlobalKeys()) {\n if (resolveRuntimeGlobalObject(globalKey)) {\n return getMiniProgramPlatformByRuntimeGlobalKey(globalKey)\n }\n }\n\n return undefined\n}\n\nexport function getCurrentMiniProgramRuntimeCapabilities(): MiniProgramRuntimeCapabilities {\n return getMiniProgramRuntimeCapabilities(resolveCurrentMiniProgramPlatform())\n}\n\nexport function supportsCurrentMiniProgramRuntimeCapability(capabilityName: MiniProgramRuntimeCapabilityName): boolean {\n return supportsMiniProgramRuntimeCapability(resolveCurrentMiniProgramPlatform(), capabilityName)\n}\n\nexport function getMiniProgramGlobalObject(platformInput?: string): MiniProgramGlobal | undefined {\n const compiledPlatform = platformInput ?? (import.meta as ImportMetaWithEnv).env?.PLATFORM\n const resolvedCompiledPlatform = resolveMiniProgramPlatform(compiledPlatform)\n\n if (resolvedCompiledPlatform) {\n const globalKey = getMiniProgramRuntimeGlobalKey(resolvedCompiledPlatform)\n return resolveRuntimeGlobalObject(globalKey)\n ?? (resolvedCompiledPlatform === 'tt' ? resolveRuntimeGlobalObject('wx') : undefined)\n }\n\n for (const globalKey of getMiniProgramRuntimeGlobalKeys()) {\n const candidate = resolveRuntimeGlobalObject(globalKey)\n if (candidate) {\n return candidate as MiniProgramGlobal\n }\n }\n return undefined\n}\n\nexport function getCurrentMiniProgramPages(): Array<Record<string, any>> {\n if (!supportsCurrentMiniProgramRuntimeCapability('globalPageStack')) {\n return []\n }\n const globalRuntime = getGlobalRuntime()\n const miniProgramGlobal = getMiniProgramGlobalObject()\n const getCurrentPagesFn = miniProgramGlobal?.getCurrentPages\n ?? globalRuntime?.getCurrentPages\n ?? (typeof getCurrentPages !== 'undefined' ? getCurrentPages : undefined)\n if (typeof getCurrentPagesFn !== 'function') {\n return []\n }\n try {\n const pages = getCurrentPagesFn.call(miniProgramGlobal)\n return Array.isArray(pages) ? pages as Array<Record<string, any>> : []\n }\n catch {\n return []\n }\n}\n\nexport function getCurrentMiniProgramHostConfig(): MiniProgramHostConfig | undefined {\n const globalRuntime = getGlobalRuntime()\n const hostConfigKey = getMiniProgramRuntimeHostConfigKey(resolveCurrentMiniProgramPlatform())\n const hostConfig = globalRuntime?.[hostConfigKey]\n return hostConfig && typeof hostConfig === 'object' ? hostConfig as MiniProgramHostConfig : undefined\n}\n\nexport function getMiniProgramRuntimeGlobalObject(): MiniProgramGlobal | undefined {\n return getMiniProgramGlobalObject() ?? getGlobalRuntime()\n}\n\nexport function getMiniProgramRuntimeConsoleWarn(): ((message: string) => void) | undefined {\n return getMiniProgramRuntimeGlobalObject()?.console?.warn\n}\n\nexport function getCurrentMiniProgramGlobalRouter(): MiniProgramGlobalRouter | undefined {\n if (!supportsCurrentMiniProgramRuntimeCapability('globalRouterApi')) {\n return undefined\n }\n const miniProgramGlobal = getMiniProgramGlobalObject()\n if (!miniProgramGlobal) {\n return undefined\n }\n const routerMethods = Object.create(null) as Partial<MiniProgramGlobalRouter>\n for (const methodName of MINI_PROGRAM_GLOBAL_ROUTER_METHODS) {\n const handler = miniProgramGlobal[methodName]\n if (typeof handler !== 'function') {\n return undefined\n }\n routerMethods[methodName] = (...args: unknown[]) => handler.apply(miniProgramGlobal, args)\n }\n return routerMethods as MiniProgramGlobalRouter\n}\n\n/**\n * @description 读取宿主 app 配置中的 tabBar 页面路径(未带前导 `/`)。\n */\nexport function getCurrentMiniProgramTabBarPagePaths(): string[] {\n const hostConfig = getCurrentMiniProgramHostConfig()\n const tabBar = hostConfig?.tabBar\n if (!tabBar || typeof tabBar !== 'object') {\n return []\n }\n if (!('list' in tabBar) || !Array.isArray(tabBar.list)) {\n return []\n }\n const paths: string[] = []\n for (const item of tabBar.list) {\n if (!item || typeof item !== 'object' || !('pagePath' in item)) {\n continue\n }\n const pagePath = item.pagePath\n if (typeof pagePath !== 'string' || !pagePath) {\n continue\n }\n // 微信开发者工具可能把宿主配置中的页面路径输出为 `.html` 形式,\n // 路由层使用的是不带扩展名的页面路径,读取边界统一归一化。\n paths.push(pagePath.replace(/\\.html$/, ''))\n }\n return paths\n}\n\nexport function getScopedSlotHostGlobalObject(): MiniProgramGlobal | undefined {\n return getMiniProgramGlobalObject() ?? getGlobalRuntime()\n}\n"],"mappings":";;;AAwBA,MAAM,qCAAmF;CACvF;CACA;CACA;CACA;CACA;AACF;AAEA,SAAS,mBAAmB;CAC1B,IAAI,OAAO,eAAe,aACxB;CAEF,OAAO;AACT;AAEA,SAAS,iCAAiC,WAAkD;CAC1F,QAAQ,WA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,KAAK;EACtB,IAAI,OAAO,aAAa,YAAY,CAAC,UACnC;EAIF,MAAM,KAAK,SAAS,QAAQ,WAAW,EAAE,CAAC;CAC5C;CACA,OAAO;AACT;AAEA,SAAgB,gCAA+D;;CAC7E,iCAAO,2BAA2B,4EAAK,iBAAiB;AAC1D"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
//#region src/runtime/register/component/alipay.ts
|
|
2
|
+
/** 支付宝通过函数属性派发自定义事件,补齐模板分派器需要的事件与数据集。 */
|
|
3
|
+
function triggerAlipayEvent(eventName, detail) {
|
|
4
|
+
const callbackName = `on${eventName.replace(/(^|-)([a-z0-9])/g, (_match, _separator, character) => character.toUpperCase())}`;
|
|
5
|
+
const callback = this.props[callbackName];
|
|
6
|
+
if (typeof callback !== "function") return;
|
|
7
|
+
const dataset = {};
|
|
8
|
+
for (const [key, value] of Object.entries(this.props)) if (key.startsWith("data-")) dataset[key.slice(5)] = value;
|
|
9
|
+
const target = {
|
|
10
|
+
id: this.props.id,
|
|
11
|
+
dataset
|
|
12
|
+
};
|
|
13
|
+
return callback({
|
|
14
|
+
type: eventName,
|
|
15
|
+
detail,
|
|
16
|
+
target,
|
|
17
|
+
currentTarget: target
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
/** 将宿主生命周期和 props 统一到现有组件运行时,避免维护第二套响应式挂载流程。 */
|
|
21
|
+
function createAlipayComponentDefinition(definition) {
|
|
22
|
+
const { lifetimes = {}, properties = {}, observers = {}, pageLifetimes = {}, ...rest } = definition;
|
|
23
|
+
const props = {};
|
|
24
|
+
for (const [key, property] of Object.entries(properties)) props[key] = property && typeof property === "object" && "value" in property ? property.value : null;
|
|
25
|
+
return {
|
|
26
|
+
...rest,
|
|
27
|
+
props,
|
|
28
|
+
methods: {
|
|
29
|
+
triggerEvent: triggerAlipayEvent,
|
|
30
|
+
...rest.methods
|
|
31
|
+
},
|
|
32
|
+
onInit() {
|
|
33
|
+
var _lifetimes$created;
|
|
34
|
+
this.properties = this.props;
|
|
35
|
+
(_lifetimes$created = lifetimes.created) === null || _lifetimes$created === void 0 || _lifetimes$created.call(this);
|
|
36
|
+
},
|
|
37
|
+
didMount() {
|
|
38
|
+
var _lifetimes$attached, _lifetimes$ready;
|
|
39
|
+
this.properties = this.props;
|
|
40
|
+
(_lifetimes$attached = lifetimes.attached) === null || _lifetimes$attached === void 0 || _lifetimes$attached.call(this);
|
|
41
|
+
(_lifetimes$ready = lifetimes.ready) === null || _lifetimes$ready === void 0 || _lifetimes$ready.call(this);
|
|
42
|
+
},
|
|
43
|
+
deriveDataFromProps(nextProps) {
|
|
44
|
+
var _this$properties, _observers$;
|
|
45
|
+
const previous = (_this$properties = this.properties) !== null && _this$properties !== void 0 ? _this$properties : this.props;
|
|
46
|
+
this.properties = nextProps;
|
|
47
|
+
for (const key of Object.keys(properties)) if (!Object.is(previous === null || previous === void 0 ? void 0 : previous[key], nextProps[key])) {
|
|
48
|
+
var _observers$key;
|
|
49
|
+
(_observers$key = observers[key]) === null || _observers$key === void 0 || _observers$key.call(this, nextProps[key], previous === null || previous === void 0 ? void 0 : previous[key]);
|
|
50
|
+
}
|
|
51
|
+
(_observers$ = observers["**"]) === null || _observers$ === void 0 || _observers$.call(this, nextProps);
|
|
52
|
+
},
|
|
53
|
+
didUnmount() {
|
|
54
|
+
var _lifetimes$detached;
|
|
55
|
+
(_lifetimes$detached = lifetimes.detached) === null || _lifetimes$detached === void 0 || _lifetimes$detached.call(this);
|
|
56
|
+
},
|
|
57
|
+
pageEvents: {
|
|
58
|
+
onShow() {
|
|
59
|
+
var _pageLifetimes$show;
|
|
60
|
+
(_pageLifetimes$show = pageLifetimes.show) === null || _pageLifetimes$show === void 0 || _pageLifetimes$show.call(this);
|
|
61
|
+
},
|
|
62
|
+
onHide() {
|
|
63
|
+
var _pageLifetimes$hide;
|
|
64
|
+
(_pageLifetimes$hide = pageLifetimes.hide) === null || _pageLifetimes$hide === void 0 || _pageLifetimes$hide.call(this);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
//#endregion
|
|
71
|
+
export { createAlipayComponentDefinition };
|
|
72
|
+
//# sourceMappingURL=alipay.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"alipay.mjs","names":[],"sources":["../../../../../src/runtime/register/component/alipay.ts"],"sourcesContent":["import type { InternalRuntimeState } from '../../types'\n\ntype AlipayComponentInstance = InternalRuntimeState & {\n props: Record<string, any>\n properties: Record<string, any>\n}\n\n/** 支付宝通过函数属性派发自定义事件,补齐模板分派器需要的事件与数据集。 */\nfunction triggerAlipayEvent(this: AlipayComponentInstance, eventName: string, detail: unknown) {\n const callbackName = `on${eventName.replace(/(^|-)([a-z0-9])/g, (_match, _separator, character: string) => character.toUpperCase())}`\n const callback = this.props[callbackName]\n if (typeof callback !== 'function') {\n return\n }\n const dataset: Record<string, unknown> = {}\n for (const [key, value] of Object.entries(this.props)) {\n if (key.startsWith('data-')) {\n dataset[key.slice(5)] = value\n }\n }\n const target = { id: this.props.id, dataset }\n return callback({ type: eventName, detail, target, currentTarget: target })\n}\n\n/** 将宿主生命周期和 props 统一到现有组件运行时,避免维护第二套响应式挂载流程。 */\nexport function createAlipayComponentDefinition(definition: Record<string, any>) {\n const { lifetimes = {}, properties = {}, observers = {}, pageLifetimes = {}, ...rest } = definition\n const props: Record<string, unknown> = {}\n for (const [key, property] of Object.entries(properties)) {\n props[key] = property && typeof property === 'object' && 'value' in property ? property.value : null\n }\n\n return {\n ...rest,\n props,\n methods: {\n triggerEvent: triggerAlipayEvent,\n ...rest.methods,\n },\n onInit(this: AlipayComponentInstance) {\n this.properties = this.props\n lifetimes.created?.call(this)\n },\n didMount(this: AlipayComponentInstance) {\n this.properties = this.props\n lifetimes.attached?.call(this)\n lifetimes.ready?.call(this)\n },\n deriveDataFromProps(this: AlipayComponentInstance, nextProps: Record<string, any>) {\n const previous = this.properties ?? this.props\n // 支付宝此时的 this.props 仍是旧值,以回调参数作为唯一更新来源。\n this.properties = nextProps\n for (const key of Object.keys(properties)) {\n if (!Object.is(previous?.[key], nextProps[key])) {\n observers[key]?.call(this, nextProps[key], previous?.[key])\n }\n }\n observers['**']?.call(this, nextProps)\n },\n didUnmount(this: AlipayComponentInstance) {\n lifetimes.detached?.call(this)\n },\n pageEvents: {\n onShow(this: AlipayComponentInstance) {\n pageLifetimes.show?.call(this)\n },\n onHide(this: AlipayComponentInstance) {\n pageLifetimes.hide?.call(this)\n },\n },\n }\n}\n"],"mappings":";;AAQA,SAAS,mBAAkD,WAAmB,QAAiB;CAC7F,MAAM,eAAe,KAAK,UAAU,QAAQ,qBAAqB,QAAQ,YAAY,cAAsB,UAAU,YAAY,CAAC;CAClI,MAAM,WAAW,KAAK,MAAM;CAC5B,IAAI,OAAO,aAAa,YACtB;CAEF,MAAM,UAAmC,CAAC;CAC1C,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,KAAK,KAAK,GAClD,IAAI,IAAI,WAAW,OAAO,GACxB,QAAQ,IAAI,MAAM,CAAC,KAAK;CAG5B,MAAM,SAAS;EAAE,IAAI,KAAK,MAAM;EAAI;CAAQ;CAC5C,OAAO,SAAS;EAAE,MAAM;EAAW;EAAQ;EAAQ,eAAe;CAAO,CAAC;AAC5E;;AAGA,SAAgB,gCAAgC,YAAiC;CAC/E,MAAM,EAAE,YAAY,CAAC,GAAG,aAAa,CAAC,GAAG,YAAY,CAAC,GAAG,gBAAgB,CAAC,GAAG,GAAG,SAAS;CACzF,MAAM,QAAiC,CAAC;CACxC,KAAK,MAAM,CAAC,KAAK,aAAa,OAAO,QAAQ,UAAU,GACrD,MAAM,OAAO,YAAY,OAAO,aAAa,YAAY,WAAW,WAAW,SAAS,QAAQ;CAGlG,OAAO;EACL,GAAG;EACH;EACA,SAAS;GACP,cAAc;GACd,GAAG,KAAK;EACV;EACA,SAAsC;;GACpC,KAAK,aAAa,KAAK;GACvB,gCAAU,yEAAS,KAAK,IAAI;EAC9B;EACA,WAAwC;;GACtC,KAAK,aAAa,KAAK;GACvB,iCAAU,4EAAU,KAAK,IAAI;GAC7B,8BAAU,mEAAO,KAAK,IAAI;EAC5B;EACA,oBAAmD,WAAgC;;GACjF,MAAM,+BAAW,KAAK,yEAAc,KAAK;GAEzC,KAAK,aAAa;GAClB,KAAK,MAAM,OAAO,OAAO,KAAK,UAAU,GACtC,IAAI,CAAC,OAAO,uDAAG,SAAW,MAAM,UAAU,IAAI,GAAG;;IAC/C,4BAAU,8DAAM,KAAK,MAAM,UAAU,0DAAM,SAAW,IAAI;GAC5D;GAEF,yBAAU,yDAAO,KAAK,MAAM,SAAS;EACvC;EACA,aAA0C;;GACxC,iCAAU,4EAAU,KAAK,IAAI;EAC/B;EACA,YAAY;GACV,SAAsC;;IACpC,qCAAc,wEAAM,KAAK,IAAI;GAC/B;GACA,SAAsC;;IACpC,qCAAc,wEAAM,KAAK,IAAI;GAC/B;EACF;CACF;AACF"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { getMiniProgramRuntimeGlobalObject, resolveCurrentMiniProgramPlatform } from "../../platform.mjs";
|
|
2
|
+
import { createAlipayComponentDefinition } from "./alipay.mjs";
|
|
2
3
|
import { WEAPP_VITE_STATEFUL_HMR_BRIDGE_KEY } from "@weapp-core/constants";
|
|
3
4
|
|
|
4
5
|
//#region src/runtime/register/component/registerNativeDefinition.ts
|
|
@@ -10,6 +11,7 @@ function createAlipayPageDefinition(componentDefinition) {
|
|
|
10
11
|
...methods,
|
|
11
12
|
onLoad(...args) {
|
|
12
13
|
var _lifetimes$created, _lifetimes$attached;
|
|
14
|
+
this.options = args[0] && typeof args[0] === "object" ? args[0] : {};
|
|
13
15
|
(_lifetimes$created = lifetimes.created) === null || _lifetimes$created === void 0 || _lifetimes$created.apply(this, args);
|
|
14
16
|
const result = pageOnLoad === null || pageOnLoad === void 0 ? void 0 : pageOnLoad.apply(this, args);
|
|
15
17
|
(_lifetimes$attached = lifetimes.attached) === null || _lifetimes$attached === void 0 || _lifetimes$attached.apply(this, args);
|
|
@@ -57,11 +59,12 @@ function registerNativeComponentDefinition(componentDefinition, isPage) {
|
|
|
57
59
|
Page(pageDefinition);
|
|
58
60
|
return;
|
|
59
61
|
}
|
|
62
|
+
const nativeDefinition = resolveCurrentMiniProgramPlatform() === "alipay" ? createAlipayComponentDefinition(componentDefinition) : componentDefinition;
|
|
60
63
|
if (typeof (statefulHmrBridge === null || statefulHmrBridge === void 0 ? void 0 : statefulHmrBridge.Component) === "function") {
|
|
61
|
-
statefulHmrBridge.Component(
|
|
64
|
+
statefulHmrBridge.Component(nativeDefinition);
|
|
62
65
|
return;
|
|
63
66
|
}
|
|
64
|
-
Component(
|
|
67
|
+
Component(nativeDefinition);
|
|
65
68
|
}
|
|
66
69
|
|
|
67
70
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registerNativeDefinition.mjs","names":[],"sources":["../../../../../src/runtime/register/component/registerNativeDefinition.ts"],"sourcesContent":["import type { InternalRuntimeState } from '../../types'\nimport { WEAPP_VITE_STATEFUL_HMR_BRIDGE_KEY } from '@weapp-core/constants'\nimport { getMiniProgramRuntimeGlobalObject, resolveCurrentMiniProgramPlatform } from '../../platform'\n\nfunction createAlipayPageDefinition(componentDefinition: Record<string, any>) {\n const {\n lifetimes = {},\n methods = {},\n observers: _observers,\n options: _options,\n pageLifetimes = {},\n properties: _properties,\n ...pageDefinition\n } = componentDefinition\n\n const pageOnLoad = pageDefinition.onLoad\n\n return {\n ...pageDefinition,\n ...methods,\n onLoad(this: InternalRuntimeState, ...args: any[]) {\n lifetimes.created?.apply(this, args)\n const result = pageOnLoad?.apply(this, args)\n lifetimes.attached?.apply(this, args)\n return result\n },\n onShow(this: InternalRuntimeState, ...args: any[]) {\n return pageLifetimes.show?.apply(this, args)\n },\n onReady(this: InternalRuntimeState, ...args: any[]) {\n return lifetimes.ready?.apply(this, args)\n },\n onHide(this: InternalRuntimeState, ...args: any[]) {\n return pageLifetimes.hide?.apply(this, args)\n },\n onResize(this: InternalRuntimeState, ...args: any[]) {\n return pageLifetimes.resize?.apply(this, args)\n },\n onUnload(this: InternalRuntimeState, ...args: any[]) {\n return lifetimes.detached?.apply(this, args)\n },\n onError(this: InternalRuntimeState, ...args: any[]) {\n return lifetimes.error?.apply(this, args)\n },\n }\n}\n\n/**\n * 根据当前宿主注册 wevu 原生定义。\n * 支付宝不支持使用 Component() 注册普通页面,需要转换为 Page() 契约。\n */\nexport function registerNativeComponentDefinition(\n componentDefinition: Record<string, any>,\n isPage: boolean,\n) {\n const statefulHmrBridge = getMiniProgramRuntimeGlobalObject()?.[WEAPP_VITE_STATEFUL_HMR_BRIDGE_KEY]\n if (isPage && resolveCurrentMiniProgramPlatform() === 'alipay') {\n const pageDefinition = createAlipayPageDefinition(componentDefinition)\n if (typeof statefulHmrBridge?.Page === 'function') {\n statefulHmrBridge.Page(pageDefinition)\n return\n }\n Page(pageDefinition)\n return\n }\n if (typeof statefulHmrBridge?.Component === 'function') {\n statefulHmrBridge.Component(
|
|
1
|
+
{"version":3,"file":"registerNativeDefinition.mjs","names":[],"sources":["../../../../../src/runtime/register/component/registerNativeDefinition.ts"],"sourcesContent":["import type { InternalRuntimeState } from '../../types'\nimport { WEAPP_VITE_STATEFUL_HMR_BRIDGE_KEY } from '@weapp-core/constants'\nimport { getMiniProgramRuntimeGlobalObject, resolveCurrentMiniProgramPlatform } from '../../platform'\nimport { createAlipayComponentDefinition } from './alipay'\n\nfunction createAlipayPageDefinition(componentDefinition: Record<string, any>) {\n const {\n lifetimes = {},\n methods = {},\n observers: _observers,\n options: _options,\n pageLifetimes = {},\n properties: _properties,\n ...pageDefinition\n } = componentDefinition\n\n const pageOnLoad = pageDefinition.onLoad\n\n return {\n ...pageDefinition,\n ...methods,\n onLoad(this: InternalRuntimeState, ...args: any[]) {\n // 支付宝 Page 不提供微信的 options 字段,在挂载前统一页面参数契约,\n // 避免 setup 读不到 query 或后续 onShow/onReady 将其清空。\n ;(this as Record<string, any>).options = args[0] && typeof args[0] === 'object' ? args[0] : {}\n lifetimes.created?.apply(this, args)\n const result = pageOnLoad?.apply(this, args)\n lifetimes.attached?.apply(this, args)\n return result\n },\n onShow(this: InternalRuntimeState, ...args: any[]) {\n return pageLifetimes.show?.apply(this, args)\n },\n onReady(this: InternalRuntimeState, ...args: any[]) {\n return lifetimes.ready?.apply(this, args)\n },\n onHide(this: InternalRuntimeState, ...args: any[]) {\n return pageLifetimes.hide?.apply(this, args)\n },\n onResize(this: InternalRuntimeState, ...args: any[]) {\n return pageLifetimes.resize?.apply(this, args)\n },\n onUnload(this: InternalRuntimeState, ...args: any[]) {\n return lifetimes.detached?.apply(this, args)\n },\n onError(this: InternalRuntimeState, ...args: any[]) {\n return lifetimes.error?.apply(this, args)\n },\n }\n}\n\n/**\n * 根据当前宿主注册 wevu 原生定义。\n * 支付宝不支持使用 Component() 注册普通页面,需要转换为 Page() 契约。\n */\nexport function registerNativeComponentDefinition(\n componentDefinition: Record<string, any>,\n isPage: boolean,\n) {\n const statefulHmrBridge = getMiniProgramRuntimeGlobalObject()?.[WEAPP_VITE_STATEFUL_HMR_BRIDGE_KEY]\n if (isPage && resolveCurrentMiniProgramPlatform() === 'alipay') {\n const pageDefinition = createAlipayPageDefinition(componentDefinition)\n if (typeof statefulHmrBridge?.Page === 'function') {\n statefulHmrBridge.Page(pageDefinition)\n return\n }\n Page(pageDefinition)\n return\n }\n const nativeDefinition = resolveCurrentMiniProgramPlatform() === 'alipay'\n ? createAlipayComponentDefinition(componentDefinition)\n : componentDefinition\n if (typeof statefulHmrBridge?.Component === 'function') {\n statefulHmrBridge.Component(nativeDefinition)\n return\n }\n Component(nativeDefinition)\n}\n"],"mappings":";;;;;AAKA,SAAS,2BAA2B,qBAA0C;CAC5E,MAAM,EACJ,YAAY,CAAC,GACb,UAAU,CAAC,GACX,WAAW,YACX,SAAS,UACT,gBAAgB,CAAC,GACjB,YAAY,aACZ,GAAG,m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|
|
|
1
|
+
import { setActivePinia } from "./manager.mjs";
|
|
2
|
+
|
|
1
3
|
//#region src/store/actions.ts
|
|
2
|
-
|
|
4
|
+
/** Action 的结果回调属于已开始的调用,不随后续退订取消。 */
|
|
5
|
+
function wrapAction(store, name, action, subscriptions, pinia) {
|
|
3
6
|
return function wrapped(...args) {
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
onError
|
|
16
|
-
});
|
|
17
|
-
} catch (_unused) {}
|
|
18
|
-
});
|
|
19
|
-
let res;
|
|
7
|
+
setActivePinia(pinia);
|
|
8
|
+
const afterCallbacks = /* @__PURE__ */ new Set();
|
|
9
|
+
const errorCallbacks = /* @__PURE__ */ new Set();
|
|
10
|
+
subscriptions.forEach((callback) => callback({
|
|
11
|
+
name,
|
|
12
|
+
store,
|
|
13
|
+
args,
|
|
14
|
+
after: (callback) => afterCallbacks.add(callback),
|
|
15
|
+
onError: (callback) => errorCallbacks.add(callback)
|
|
16
|
+
}));
|
|
17
|
+
let result;
|
|
20
18
|
try {
|
|
21
|
-
|
|
22
|
-
} catch (
|
|
23
|
-
|
|
24
|
-
throw
|
|
19
|
+
result = action.apply(this && this.$id === store.$id ? this : store, args);
|
|
20
|
+
} catch (error) {
|
|
21
|
+
errorCallbacks.forEach((callback) => callback(error));
|
|
22
|
+
throw error;
|
|
25
23
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
return Promise.reject(e);
|
|
24
|
+
if (result instanceof Promise) return result.then((value) => {
|
|
25
|
+
afterCallbacks.forEach((callback) => callback(value));
|
|
26
|
+
return value;
|
|
27
|
+
}).catch((error) => {
|
|
28
|
+
errorCallbacks.forEach((callback) => callback(error));
|
|
29
|
+
return Promise.reject(error);
|
|
33
30
|
});
|
|
34
|
-
|
|
31
|
+
afterCallbacks.forEach((callback) => callback(result));
|
|
32
|
+
return result;
|
|
35
33
|
};
|
|
36
34
|
}
|
|
37
35
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"actions.mjs","names":[],"sources":["../../../src/store/actions.ts"],"sourcesContent":["import type { ActionSubscriber } from './types'\n\nexport function wrapAction
|
|
1
|
+
{"version":3,"file":"actions.mjs","names":[],"sources":["../../../src/store/actions.ts"],"sourcesContent":["import type { ActionSubscriber, Pinia } from './types'\nimport { setActivePinia } from './manager'\n\n/** Action 的结果回调属于已开始的调用,不随后续退订取消。 */\nexport function wrapAction(\n store: Record<string, any>,\n name: string,\n action: (...args: any[]) => any,\n subscriptions: Set<ActionSubscriber>,\n pinia: Pinia,\n) {\n return function wrapped(this: any, ...args: any[]) {\n setActivePinia(pinia)\n const afterCallbacks = new Set<(result: any) => any>()\n const errorCallbacks = new Set<(error: any) => any>()\n subscriptions.forEach(callback => callback({\n name,\n store,\n args,\n after: callback => afterCallbacks.add(callback),\n onError: callback => errorCallbacks.add(callback),\n }))\n let result: any\n try {\n result = action.apply(this && this.$id === store.$id ? this : store, args)\n }\n catch (error) {\n errorCallbacks.forEach(callback => callback(error))\n throw error\n }\n if (result instanceof Promise) {\n return result.then((value: any) => {\n afterCallbacks.forEach(callback => callback(value))\n return value\n }).catch((error: any) => {\n errorCallbacks.forEach(callback => callback(error))\n return Promise.reject(error)\n })\n }\n afterCallbacks.forEach(callback => callback(result))\n return result\n }\n}\n"],"mappings":";;;;AAIA,SAAgB,WACd,OACA,MACA,QACA,eACA,OACA;CACA,OAAO,SAAS,QAAmB,GAAG,MAAa;EACjD,eAAe,KAAK;EACpB,MAAM,iCAAiB,IAAI,IAA0B;EACrD,MAAM,iCAAiB,IAAI,IAAyB;EACpD,cAAc,SAAQ,aAAY,SAAS;GACzC;GACA;GACA;GACA,QAAO,aAAY,eAAe,IAAI,QAAQ;GAC9C,UAAS,aAAY,eAAe,IAAI,QAAQ;EAClD,CAAC,CAAC;EACF,IAAI;EACJ,IAAI;GACF,SAAS,OAAO,MAAM,QAAQ,KAAK,QAAQ,MAAM,MAAM,OAAO,OAAO,IAAI;EAC3E,SACO,OAAO;GACZ,eAAe,SAAQ,aAAY,SAAS,KAAK,CAAC;GAClD,MAAM;EACR;EACA,IAAI,kBAAkB,SACpB,OAAO,OAAO,MAAM,UAAe;GACjC,eAAe,SAAQ,aAAY,SAAS,KAAK,CAAC;GAClD,OAAO;EACT,CAAC,CAAC,CAAC,OAAO,UAAe;GACvB,eAAe,SAAQ,aAAY,SAAS,KAAK,CAAC;GAClD,OAAO,QAAQ,OAAO,KAAK;EAC7B,CAAC;EAEH,eAAe,SAAQ,aAAY,SAAS,MAAM,CAAC;EACnD,OAAO;CACT;AACF"}
|