@weapp-vite/web 1.6.0 → 2.0.1
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 +22 -0
- package/dist/compiler/wxml/compile.mjs +9 -33
- package/dist/compiler/wxml/compile.mjs.map +1 -1
- package/dist/compiler/wxml/dependency.mjs +9 -1
- package/dist/compiler/wxml/dependency.mjs.map +1 -1
- package/dist/compiler/wxml/prepare.mjs +43 -0
- package/dist/compiler/wxml/prepare.mjs.map +1 -0
- package/dist/css/wxss.mjs +2 -1
- package/dist/css/wxss.mjs.map +1 -1
- package/dist/plugin/assets.d.mts +1 -0
- package/dist/plugin/constants.mjs +4 -2
- package/dist/plugin/constants.mjs.map +1 -1
- package/dist/plugin/hostTypes.d.mts +75 -0
- package/dist/plugin/index.d.mts +2 -74
- package/dist/plugin/index.mjs +28 -16
- package/dist/plugin/index.mjs.map +1 -1
- package/dist/plugin/sfcHmr.mjs +38 -0
- package/dist/plugin/sfcHmr.mjs.map +1 -0
- package/dist/plugin/vueSfc.mjs +12 -9
- package/dist/plugin/vueSfc.mjs.map +1 -1
- package/dist/runtime/appStyle.mjs +25 -0
- package/dist/runtime/appStyle.mjs.map +1 -0
- package/dist/runtime/component/element.mjs +39 -19
- package/dist/runtime/component/element.mjs.map +1 -1
- package/dist/runtime/component/events.mjs +34 -3
- package/dist/runtime/component/events.mjs.map +1 -1
- package/dist/runtime/component/publicInstance.mjs +7 -3
- package/dist/runtime/component/publicInstance.mjs.map +1 -1
- package/dist/runtime/component/state.mjs +7 -0
- package/dist/runtime/component/state.mjs.map +1 -1
- package/dist/runtime/component/types.d.mts +2 -0
- package/dist/runtime/component/utils.mjs +23 -3
- package/dist/runtime/component/utils.mjs.map +1 -1
- package/dist/runtime/componentEvents.mjs +37 -0
- package/dist/runtime/componentEvents.mjs.map +1 -0
- package/dist/runtime/eventBinding.d.mts +1 -0
- package/dist/runtime/eventBinding.mjs +5 -2
- package/dist/runtime/eventBinding.mjs.map +1 -1
- package/dist/runtime/hostGlobals.d.mts +1 -0
- package/dist/runtime/legacyTemplate/dom.mjs +2 -7
- package/dist/runtime/legacyTemplate/dom.mjs.map +1 -1
- package/dist/runtime/nativeComponents/canvas/index.mjs +12 -3
- package/dist/runtime/nativeComponents/canvas/index.mjs.map +1 -1
- package/dist/runtime/nativeComponents/index.mjs +0 -1
- package/dist/runtime/nativeComponents/index.mjs.map +1 -1
- package/dist/runtime/nativeComponents/richText/index.mjs +2 -2
- package/dist/runtime/nativeComponents/richText/index.mjs.map +1 -1
- package/dist/runtime/pageLayout.d.mts +1 -0
- package/dist/runtime/polyfill/index.mjs +1 -1
- package/dist/runtime/polyfill/routeRuntime/options.d.mts +1 -0
- package/dist/runtime/polyfill/routeRuntime.d.mts +1 -1
- package/dist/runtime/polyfill/routeRuntime.mjs +5 -1
- package/dist/runtime/polyfill/routeRuntime.mjs.map +1 -1
- package/dist/runtime/renderContext.mjs +3 -2
- package/dist/runtime/renderContext.mjs.map +1 -1
- package/dist/runtime/wevu.d.mts +1 -0
- package/dist/runtime/wevu.mjs +2 -0
- package/dist/runtime/wevu.mjs.map +1 -1
- package/dist/shared/wxml.mjs +5 -1
- package/dist/shared/wxml.mjs.map +1 -1
- package/package.json +15 -13
- package/dist/runtime/nativeComponents/richText/helpers.mjs +0 -230
- package/dist/runtime/nativeComponents/richText/helpers.mjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"element.mjs","names":[],"sources":["../../../src/runtime/component/element.ts"],"sourcesContent":["import type {\n CreateComponentElementClassOptions,\n WeappComponentInstance,\n} from './elementTypes'\nimport type {\n ComponentOptions,\n ComponentPublicInstance,\n DataRecord,\n PageLifeTimeHooks,\n TriggerEventOptions,\n} from './types'\nimport type { ClassAttributeElement } from './virtualHost'\nimport { WEVU_HOST_COMMIT_PROMISE_KEY } from '@weapp-core/constants'\nimport { html } from 'lit'\nimport { unsafeHTML } from 'lit/directives/unsafe-html.js'\nimport { createIntersectionObserverBridge } from '../polyfill/intersectionObserver'\nimport { createRenderContext } from '../renderContext'\nimport { hasOwn } from '../utils/object'\nimport { supportsLit } from './constants'\nimport {\n createScopedSelectorQuery,\n resolveRenderRoot,\n selectRuntimeComponent,\n selectRuntimeComponents,\n} from './dom'\nimport { bindRuntimeEvents } from './events'\nimport { runComponentObservers } from './observers'\nimport { createComponentPublicInstance } from './publicInstance'\nimport { resolveRelationNodes } from './relations'\nimport { createWebSlotsProxy } from './slots'\nimport { assignDataPath, cloneValue, coerceValue, parseDataPath, resolveDataPath, toCamelCase } from './utils'\nimport {\n clearVirtualHostClasses,\n clearVirtualHostParts,\n syncVirtualHostClasses,\n syncVirtualHostParts,\n} from './virtualHost'\n\nexport type { WeappComponentInstance } from './elementTypes'\nexport type WeappComponentElementClass = typeof HTMLElement & {\n new (): WeappComponentInstance\n}\n\nfunction resolveComposedParent(node: Node): Node | undefined {\n const assignedSlot = (node as Element).assignedSlot\n if (assignedSlot) {\n return assignedSlot\n }\n if (node.parentNode) {\n return node.parentNode\n }\n const root = node.getRootNode?.()\n return root instanceof ShadowRoot ? root.host : undefined\n}\n\nfunction isWeappComponentInstance(value: unknown): value is WeappComponentInstance {\n return Boolean(\n value\n && typeof value === 'object'\n && typeof (value as WeappComponentInstance).__weappSync === 'function',\n )\n}\n\nexport function createComponentElementClass({\n BaseElement,\n runtimeState,\n instances,\n}: CreateComponentElementClassOptions): WeappComponentElementClass {\n const RuntimeBaseElement = BaseElement as typeof HTMLElement & {\n readonly observedAttributes?: string[]\n }\n class WeappWebComponent extends RuntimeBaseElement implements WeappComponentInstance {\n static get observedAttributes() {\n const inherited = super.observedAttributes ?? []\n return Array.from(new Set([...inherited, ...runtimeState.observedAttributes]))\n }\n\n #state: DataRecord\n #properties: DataRecord\n #methods: Record<string, (event: any) => any> = {}\n #publicInstance: ComponentPublicInstance\n #exposedMethodNames = new Set<string>()\n #isMounted = false\n #renderContext = createRenderContext(this, {})\n #usesLegacyTemplate = false\n #readyFired = false\n #observerInitDone = false\n #observedKeys = new Set<string>()\n #virtualHostClassTokens = new Set<string>()\n #virtualHostPartTokens = new Set<string>()\n #virtualHostRootElement: ClassAttributeElement | undefined\n #needsSetDataRecovery = false\n #hostCommitPromise: Promise<void> | undefined\n #hostCommitUpdate: Promise<boolean> | undefined\n readonly data!: DataRecord\n readonly properties!: DataRecord\n\n constructor() {\n super()\n const dataOption = runtimeState.componentRef.data ?? {}\n this.#properties = { ...runtimeState.defaultPropertyValues }\n this.#state = { ...cloneValue(this.#properties), ...cloneValue(dataOption) }\n Object.defineProperty(this.#state, '$slots', {\n configurable: true,\n enumerable: true,\n value: createWebSlotsProxy(() => this.#state.vueSlots),\n })\n Object.defineProperties(this, {\n data: {\n configurable: true,\n enumerable: true,\n get: () => this.#state,\n },\n properties: {\n configurable: true,\n enumerable: true,\n get: () => this.#properties,\n },\n })\n this.#publicInstance = createComponentPublicInstance(\n this,\n WeappWebComponent.prototype,\n key => typeof key === 'string' ? this.#methods[key] : undefined,\n )\n for (const [propName] of runtimeState.propertyEntries) {\n Object.defineProperty(this, propName, {\n configurable: true,\n enumerable: true,\n get: () => this.#state[propName],\n set: value => this.#setProperty(propName, value),\n })\n }\n this.#syncMethods(runtimeState.componentRef.methods ?? {})\n if (!supportsLit) {\n const host = this as unknown as HTMLElement\n if (!host.shadowRoot && typeof host.attachShadow === 'function') {\n host.attachShadow({ mode: 'open' })\n }\n ;(this as any).renderRoot = host.shadowRoot ?? host\n }\n instances.add(this)\n runtimeState.lifetimes.created?.call(this.#publicInstance)\n }\n\n get [WEVU_HOST_COMMIT_PROMISE_KEY]() {\n // 回调异常属于当前提交;后续属性更新或 HMR 必须等待自己的 Lit 提交。\n if (!supportsLit) {\n return undefined\n }\n // 动态 Lit 基类不会在静态声明中暴露 updateComplete。\n const litElement = this as unknown as { updateComplete: Promise<boolean> }\n const update = litElement.updateComplete\n return this.#hostCommitUpdate === update ? this.#hostCommitPromise : update\n }\n\n setData(patch: DataRecord, callback?: () => void) {\n const changed = this.#applyDataPatch(patch)\n if (supportsLit && (changed || this.#needsSetDataRecovery)) {\n if (!changed) {\n this.requestUpdate()\n }\n // 动态 Lit 基类不会在静态声明中暴露 updateComplete。\n const litElement = this as unknown as { updateComplete: Promise<boolean> }\n const update = litElement.updateComplete\n const commitPromise = update.then(\n () => {\n this.#needsSetDataRecovery = false\n callback?.()\n },\n (cause) => {\n this.#needsSetDataRecovery = true\n throw cause\n },\n )\n this.#hostCommitPromise = commitPromise\n this.#hostCommitUpdate = update\n return commitPromise\n }\n callback?.()\n }\n\n triggerEvent(name: string, detail?: any, options: TriggerEventOptions = {}) {\n this.dispatchEvent(new CustomEvent(name, {\n detail,\n bubbles: options.bubbles ?? false,\n composed: options.composed ?? false,\n }))\n }\n\n createSelectorQuery() {\n return createScopedSelectorQuery(this)\n }\n\n createIntersectionObserver(options?: {\n initialRatio?: number\n observeAll?: boolean\n thresholds?: number[]\n }) {\n return createIntersectionObserverBridge(this, options)\n }\n\n selectComponent(selector: string) {\n return selectRuntimeComponent(this, selector)\n }\n\n selectAllComponents(selector: string) {\n return selectRuntimeComponents(this, selector)\n }\n\n getRelationNodes(relationPath: string) {\n const relation = runtimeState.componentRef.relations?.[relationPath]\n return relation\n ? resolveRelationNodes(this, runtimeState.id, relationPath, relation.type)\n : []\n }\n\n selectOwnerComponent() {\n let current = resolveComposedParent(this)\n while (current) {\n if (isWeappComponentInstance(current)) {\n return current\n }\n current = resolveComposedParent(current)\n }\n return undefined\n }\n\n connectedCallback() {\n const superConnected = (BaseElement.prototype as { connectedCallback?: () => void }).connectedCallback\n if (supportsLit && typeof superConnected === 'function') {\n superConnected.call(this)\n }\n this.#applyAttributes()\n if (runtimeState.observerInitEnabled) {\n this.#runInitialObservers()\n }\n runtimeState.lifetimes.attached?.call(this.#publicInstance)\n this.#isMounted = true\n if (!supportsLit) {\n this.#renderLegacy()\n }\n }\n\n disconnectedCallback() {\n const superDisconnected = (BaseElement.prototype as { disconnectedCallback?: () => void }).disconnectedCallback\n if (supportsLit && typeof superDisconnected === 'function') {\n superDisconnected.call(this)\n }\n this.#isMounted = false\n instances.delete(this)\n runtimeState.lifetimes.detached?.call(this.#publicInstance)\n }\n\n attributeChangedCallback(attrName: string, oldValue: string | null, newValue: string | null) {\n const superAttributeChanged = (BaseElement.prototype as {\n attributeChangedCallback?: (name: string, oldValue: string | null, newValue: string | null) => void\n }).attributeChangedCallback\n if (supportsLit && typeof superAttributeChanged === 'function') {\n superAttributeChanged.call(this, attrName, oldValue, newValue)\n }\n const propName = toCamelCase(attrName)\n if (!hasOwn(this.#properties, propName)) {\n return\n }\n const propOption = runtimeState.componentRef.properties?.[propName]\n this.#setProperty(propName, coerceValue(newValue, propOption?.type))\n }\n\n firstUpdated() {\n runtimeState.lifetimes.ready?.call(this.#publicInstance)\n this.#readyFired = true\n }\n\n updated() {\n this.#syncVirtualHostClasses()\n if (this.#usesLegacyTemplate) {\n bindRuntimeEvents(resolveRenderRoot(this), this.#methods, this)\n }\n }\n\n render() {\n const result = runtimeState.templateRef(this.#state, this.#renderContext)\n const styleMarkup = runtimeState.styleRef\n ? html`<style>${runtimeState.styleRef}</style>`\n : null\n if (typeof result === 'string') {\n this.#usesLegacyTemplate = true\n return html`${styleMarkup}${unsafeHTML(result)}`\n }\n this.#usesLegacyTemplate = false\n if (styleMarkup) {\n return html`${styleMarkup}${result as any}`\n }\n return result\n }\n\n requestUpdate(name?: PropertyKey, oldValue?: unknown, options?: unknown) {\n const superRequestUpdate = (BaseElement.prototype as any).requestUpdate\n if (supportsLit && typeof superRequestUpdate === 'function') {\n return superRequestUpdate.call(this, name, oldValue, options)\n }\n if (this.#isMounted) {\n this.#renderLegacy()\n }\n return undefined\n }\n\n #applyAttributes() {\n if (!this.attributes || typeof this.attributes[Symbol.iterator] !== 'function') {\n return\n }\n for (const attr of this.attributes) {\n this.attributeChangedCallback(attr.name, null, attr.value)\n }\n }\n\n #applyDataPatch(patch: DataRecord) {\n if (!patch || typeof patch !== 'object') {\n return false\n }\n let changed = false\n const changedKeys: string[] = []\n const previousProperties: DataRecord = {}\n for (const [path, value] of Object.entries(patch)) {\n const segments = parseDataPath(path)\n const topKey = segments[0]\n if (!topKey || topKey === '$slots' || Object.is(resolveDataPath(this.#state, segments), value)) {\n continue\n }\n if (hasOwn(this.#properties, topKey) && !hasOwn(previousProperties, topKey)) {\n previousProperties[topKey] = this.#properties[topKey]\n }\n assignDataPath(this.#state, segments, value)\n if (hasOwn(this.#properties, topKey)) {\n this.#properties[topKey] = this.#state[topKey]\n }\n changedKeys.push(path)\n changed = true\n }\n if (changed) {\n this.requestUpdate()\n runComponentObservers(runtimeState.componentRef, this.#publicInstance, changedKeys, previousProperties)\n for (const key of changedKeys) {\n if (runtimeState.componentRef.properties?.[key]?.observer) {\n this.#observedKeys.add(key)\n }\n }\n }\n return changed\n }\n\n #setProperty(name: string, value: any) {\n const propOption = runtimeState.componentRef.properties?.[name]\n const coerced = coerceValue(value, propOption?.type)\n const oldValue = this.#properties[name]\n if (oldValue === coerced) {\n return\n }\n this.#properties[name] = coerced\n this.#state[name] = coerced\n if (this.#isMounted) {\n this.requestUpdate()\n }\n runComponentObservers(runtimeState.componentRef, this.#publicInstance, [name], { [name]: oldValue })\n if (propOption?.observer) {\n this.#observedKeys.add(name)\n }\n }\n\n #runInitialObservers() {\n if (this.#observerInitDone) {\n return\n }\n this.#observerInitDone = true\n for (const [propName, propOption] of runtimeState.propertyEntries) {\n if (!propOption.observer || this.#observedKeys.has(propName)) {\n continue\n }\n const value = this.#state[propName]\n propOption.observer.call(this.#publicInstance, value, undefined)\n this.#observedKeys.add(propName)\n }\n }\n\n #syncMethods(nextMethods: ComponentOptions['methods']) {\n const resolved = nextMethods ?? {}\n const bound: Record<string, (event: any) => any> = {}\n for (const [name, fn] of Object.entries(resolved)) {\n if (typeof fn === 'function') {\n bound[name] = fn.bind(this.#publicInstance)\n }\n }\n for (const name of this.#exposedMethodNames) {\n if (name in bound) {\n continue\n }\n const descriptor = Object.getOwnPropertyDescriptor(this, name)\n if (descriptor?.configurable && descriptor.value === this.#methods[name]) {\n delete (this as unknown as Record<string, unknown>)[name]\n }\n this.#exposedMethodNames.delete(name)\n }\n for (const key of Object.keys(this.#methods)) {\n if (!(key in bound)) {\n delete this.#methods[key]\n }\n }\n for (const [key, fn] of Object.entries(bound)) {\n this.#methods[key] = fn\n if (!this.#exposedMethodNames.has(key) && key in this) {\n continue\n }\n Object.defineProperty(this, key, {\n configurable: true,\n enumerable: false,\n writable: true,\n value: fn,\n })\n this.#exposedMethodNames.add(key)\n }\n this.#renderContext = createRenderContext(this, this.#methods)\n }\n\n __weappSync(nextMethods: ComponentOptions['methods']) {\n this.#syncMethods(nextMethods)\n this.requestUpdate()\n }\n\n __weappInvokePageLifetime(type: keyof PageLifeTimeHooks) {\n const hook = runtimeState.pageLifetimes[type]\n if (typeof hook === 'function') {\n hook.call(this.#publicInstance)\n }\n }\n\n #renderLegacy() {\n const result = runtimeState.templateRef(this.#state, this.#renderContext)\n const root = resolveRenderRoot(this)\n const styleMarkup = runtimeState.styleRef ? `<style>${runtimeState.styleRef}</style>` : ''\n if (typeof result === 'string') {\n root.innerHTML = `${styleMarkup}${result}`\n bindRuntimeEvents(root as ShadowRoot, this.#methods, this)\n }\n else if (result == null) {\n root.innerHTML = styleMarkup\n }\n else {\n root.innerHTML = `${styleMarkup}${String(result)}`\n }\n this.#syncVirtualHostClasses()\n if (!this.#readyFired) {\n runtimeState.lifetimes.ready?.call(this.#publicInstance)\n this.#readyFired = true\n }\n }\n\n #syncVirtualHostClasses() {\n const host = this as unknown as ClassAttributeElement\n if (!runtimeState.componentRef.options?.virtualHost) {\n clearVirtualHostClasses(host, this.#virtualHostClassTokens)\n clearVirtualHostParts(this.#virtualHostRootElement, this.#virtualHostPartTokens)\n this.#virtualHostRootElement = undefined\n return\n }\n const root = resolveRenderRoot(this)\n syncVirtualHostClasses(host, root, this.#virtualHostClassTokens)\n this.#virtualHostRootElement = syncVirtualHostParts(\n root,\n this.#virtualHostRootElement,\n this.#virtualHostPartTokens,\n )\n }\n }\n\n return WeappWebComponent as WeappComponentElementClass\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AA2CA,SAAS,sBAAsB,MAA8B;CAC3D,MAAM,eAAgB,KAAiB;CACvC,IAAI,cACF,OAAO;CAET,IAAI,KAAK,YACP,OAAO,KAAK;CAEd,MAAM,OAAO,KAAK,cAAc;CAChC,OAAO,gBAAgB,aAAa,KAAK,OAAO;AAClD;AAEA,SAAS,yBAAyB,OAAiD;CACjF,OAAO,QACL,SACG,OAAO,UAAU,YACjB,OAAQ,MAAiC,gBAAgB,UAC9D;AACF;AAEA,SAAgB,4BAA4B,EAC1C,aACA,cACA,aACiE;CACjE,MAAM,qBAAqB;CAG3B,MAAM,0BAA0B,mBAAqD;EACnF,WAAW,qBAAqB;GAC9B,MAAM,YAAY,MAAM,sBAAsB,CAAC;GAC/C,OAAO,MAAM,qBAAK,IAAI,IAAI,CAAC,GAAG,WAAW,GAAG,aAAa,kBAAkB,CAAC,CAAC;EAC/E;EAEA;EACA;EACA,WAAgD,CAAC;EACjD;EACA,sCAAsB,IAAI,IAAY;EACtC,aAAa;EACb,iBAAiB,oBAAoB,MAAM,CAAC,CAAC;EAC7C,sBAAsB;EACtB,cAAc;EACd,oBAAoB;EACpB,gCAAgB,IAAI,IAAY;EAChC,0CAA0B,IAAI,IAAY;EAC1C,yCAAyB,IAAI,IAAY;EACzC;EACA,wBAAwB;EACxB;EACA;EACA,AAAS;EACT,AAAS;EAET,cAAc;GACZ,MAAM;GACN,MAAM,aAAa,aAAa,aAAa,QAAQ,CAAC;GACtD,KAAK,cAAc,EAAE,GAAG,aAAa,sBAAsB;GAC3D,KAAK,SAAS;IAAE,GAAG,WAAW,KAAK,WAAW;IAAG,GAAG,WAAW,UAAU;GAAE;GAC3E,OAAO,eAAe,KAAK,QAAQ,UAAU;IAC3C,cAAc;IACd,YAAY;IACZ,OAAO,0BAA0B,KAAK,OAAO,QAAQ;G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AAI;GACnC,MAAM,cAAc,aAAa,WAAW,UAAU,aAAa,SAAS,YAAY;GACxF,IAAI,OAAO,WAAW,UAAU;IAC9B,KAAK,YAAY,GAAG,cAAc;IAClC,kBAAkB,MAAoB,KAAK,UAAU,IAAI;GAC3D,OACK,IAAI,UAAU,MACjB,KAAK,YAAY;QAGjB,KAAK,YAAY,GAAG,cAAc,OAAO,MAAM;GAEjD,KAAK,wBAAwB;GAC7B,IAAI,CAAC,KAAK,aAAa;IACrB,aAAa,UAAU,OAAO,KAAK,KAAK,eAAe;IACvD,KAAK,cAAc;GACrB;EACF;EAEA,0BAA0B;GACxB,MAAM,OAAO;GACb,IAAI,CAAC,aAAa,aAAa,SAAS,aAAa;IACnD,wBAAwB,MAAM,KAAK,uBAAuB;IAC1D,sBAAsB,KAAK,yBAAyB,KAAK,sBAAsB;IAC/E,KAAK,0BAA0B;IAC/B;GACF;GACA,MAAM,OAAO,kBAAkB,IAAI;GACnC,uBAAuB,MAAM,MAAM,KAAK,uBAAuB;GAC/D,KAAK,0BAA0B,qBAC7B,MACA,KAAK,yBACL,KAAK,sBACP;EACF;CACF;CAEA,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"element.mjs","names":[],"sources":["../../../src/runtime/component/element.ts"],"sourcesContent":["import type {\n CreateComponentElementClassOptions,\n WeappComponentInstance,\n} from './elementTypes'\nimport type {\n ComponentOptions,\n ComponentPublicInstance,\n DataRecord,\n PageLifeTimeHooks,\n TriggerEventOptions,\n} from './types'\nimport type { ClassAttributeElement } from './virtualHost'\nimport { WEVU_HOST_COMMIT_PROMISE_KEY, WEVU_HOST_INSTALL_METHOD_KEY } from '@weapp-core/constants'\nimport { html } from 'lit'\nimport { unsafeHTML } from 'lit/directives/unsafe-html.js'\nimport { getAppStyle, trackAppStyle } from '../appStyle'\nimport { markComponentEvent, registerComponentEventTarget } from '../componentEvents'\nimport { createIntersectionObserverBridge } from '../polyfill/intersectionObserver'\nimport { createRenderContext } from '../renderContext'\nimport { hasOwn } from '../utils/object'\nimport { supportsLit } from './constants'\nimport {\n createScopedSelectorQuery,\n resolveRenderRoot,\n selectRuntimeComponent,\n selectRuntimeComponents,\n} from './dom'\nimport { bindRuntimeEvents } from './events'\nimport { runComponentObservers } from './observers'\nimport { createComponentPublicInstance } from './publicInstance'\nimport { resolveRelationNodes } from './relations'\nimport { createWebSlotsProxy } from './slots'\nimport { assignDataPath, cloneCommittedValue, cloneValue, coerceValue, parseDataPath, resolveDataPath, toCamelCase } from './utils'\nimport {\n clearVirtualHostClasses,\n clearVirtualHostParts,\n syncVirtualHostClasses,\n syncVirtualHostParts,\n} from './virtualHost'\n\nexport type { WeappComponentInstance } from './elementTypes'\nexport type WeappComponentElementClass = typeof HTMLElement & {\n new (): WeappComponentInstance\n}\n\nfunction resolveComposedParent(node: Node): Node | undefined {\n const assignedSlot = (node as Element).assignedSlot\n if (assignedSlot) {\n return assignedSlot\n }\n if (node.parentNode) {\n return node.parentNode\n }\n const root = node.getRootNode?.()\n return root instanceof ShadowRoot ? root.host : undefined\n}\n\nfunction isWeappComponentInstance(value: unknown): value is WeappComponentInstance {\n return Boolean(\n value\n && typeof value === 'object'\n && typeof (value as WeappComponentInstance).__weappSync === 'function',\n )\n}\n\nexport function createComponentElementClass({\n BaseElement,\n runtimeState,\n instances,\n}: CreateComponentElementClassOptions): WeappComponentElementClass {\n const RuntimeBaseElement = BaseElement as typeof HTMLElement & {\n readonly observedAttributes?: string[]\n }\n class WeappWebComponent extends RuntimeBaseElement implements WeappComponentInstance {\n static get observedAttributes() {\n const inherited = super.observedAttributes ?? []\n return Array.from(new Set([...inherited, ...runtimeState.observedAttributes]))\n }\n\n #state: DataRecord\n #properties: DataRecord\n #methods: Record<string, (event: any) => any> = {}\n #setupMethods: Record<string, (...args: any[]) => any> = {}\n #publicInstance: ComponentPublicInstance\n #exposedMethodNames = new Set<string>()\n #isMounted = false\n #renderContext = createRenderContext(this, {})\n #usesLegacyTemplate = false\n #readyFired = false\n #observerInitDone = false\n #observedKeys = new Set<string>()\n #virtualHostClassTokens = new Set<string>()\n #virtualHostPartTokens = new Set<string>()\n #virtualHostRootElement: ClassAttributeElement | undefined\n #needsSetDataRecovery = false\n #hostCommitPromise: Promise<void> | undefined\n #hostCommitUpdate: Promise<boolean> | undefined\n readonly data!: DataRecord\n readonly properties!: DataRecord\n\n constructor() {\n super()\n registerComponentEventTarget(this)\n const dataOption = runtimeState.componentRef.data ?? {}\n this.#properties = { ...runtimeState.defaultPropertyValues }\n this.#state = { ...cloneValue(this.#properties), ...cloneValue(dataOption) }\n Object.defineProperty(this.#state, '$slots', {\n configurable: true,\n enumerable: true,\n value: createWebSlotsProxy(() => this.#state.vueSlots),\n })\n Object.defineProperties(this, {\n data: {\n configurable: true,\n enumerable: true,\n get: () => this.#state,\n },\n properties: {\n configurable: true,\n enumerable: true,\n get: () => this.#properties,\n },\n })\n this.#publicInstance = createComponentPublicInstance(\n this,\n WeappWebComponent.prototype,\n key => typeof key === 'string' ? this.#methods[key] : undefined,\n this.#properties,\n )\n for (const [propName] of runtimeState.propertyEntries) {\n Object.defineProperty(this, propName, {\n configurable: true,\n enumerable: true,\n get: () => this.#state[propName],\n set: value => this.#setProperty(propName, value),\n })\n }\n this.#syncMethods(runtimeState.componentRef.methods ?? {})\n if (!supportsLit) {\n const host = this as unknown as HTMLElement\n if (!host.shadowRoot && typeof host.attachShadow === 'function') {\n host.attachShadow({ mode: 'open' })\n }\n ;(this as any).renderRoot = host.shadowRoot ?? host\n }\n instances.add(this)\n runtimeState.lifetimes.created?.call(this.#publicInstance)\n }\n\n get [WEVU_HOST_COMMIT_PROMISE_KEY]() {\n // 回调异常属于当前提交;后续属性更新或 HMR 必须等待自己的 Lit 提交。\n if (!supportsLit) {\n return undefined\n }\n // 动态 Lit 基类不会在静态声明中暴露 updateComplete。\n const litElement = this as unknown as { updateComplete: Promise<boolean> }\n const update = litElement.updateComplete\n return this.#hostCommitUpdate === update ? this.#hostCommitPromise : update\n }\n\n setData(patch: DataRecord, callback?: () => void) {\n const changed = this.#applyDataPatch(patch)\n if (supportsLit && (changed || this.#needsSetDataRecovery)) {\n if (!changed) {\n this.requestUpdate()\n }\n // 动态 Lit 基类不会在静态声明中暴露 updateComplete。\n const litElement = this as unknown as { updateComplete: Promise<boolean> }\n const update = litElement.updateComplete\n const commitPromise = update.then(\n () => {\n this.#needsSetDataRecovery = false\n callback?.()\n },\n (cause) => {\n this.#needsSetDataRecovery = true\n throw cause\n },\n )\n this.#hostCommitPromise = commitPromise\n this.#hostCommitUpdate = update\n return commitPromise\n }\n callback?.()\n }\n\n triggerEvent(name: string, detail?: any, options: TriggerEventOptions = {}) {\n this.dispatchEvent(markComponentEvent(new CustomEvent(name, {\n detail,\n bubbles: options.bubbles ?? false,\n composed: options.composed ?? false,\n })))\n }\n\n [WEVU_HOST_INSTALL_METHOD_KEY](methods: Readonly<Record<string, (...args: any[]) => any>>) {\n const bound: Record<string, (...args: any[]) => any> = {}\n for (const [name, method] of Object.entries(methods)) {\n bound[name] = method.bind(this.#publicInstance)\n }\n this.#setupMethods = bound\n this.#syncMethods(runtimeState.componentRef.methods)\n this.requestUpdate()\n }\n\n createSelectorQuery() {\n return createScopedSelectorQuery(this)\n }\n\n createIntersectionObserver(options?: {\n initialRatio?: number\n observeAll?: boolean\n thresholds?: number[]\n }) {\n return createIntersectionObserverBridge(this, options)\n }\n\n selectComponent(selector: string) {\n return selectRuntimeComponent(this, selector)\n }\n\n selectAllComponents(selector: string) {\n return selectRuntimeComponents(this, selector)\n }\n\n getRelationNodes(relationPath: string) {\n const relation = runtimeState.componentRef.relations?.[relationPath]\n return relation\n ? resolveRelationNodes(this, runtimeState.id, relationPath, relation.type)\n : []\n }\n\n selectOwnerComponent() {\n let current = resolveComposedParent(this)\n while (current) {\n if (isWeappComponentInstance(current)) {\n return current\n }\n current = resolveComposedParent(current)\n }\n return undefined\n }\n\n connectedCallback() {\n instances.add(this)\n const superConnected = (BaseElement.prototype as { connectedCallback?: () => void }).connectedCallback\n if (supportsLit && typeof superConnected === 'function') {\n superConnected.call(this)\n }\n this.#applyAttributes()\n if (runtimeState.observerInitEnabled) {\n this.#runInitialObservers()\n }\n runtimeState.lifetimes.attached?.call(this.#publicInstance)\n this.#isMounted = true\n trackAppStyle(this, runtimeState.inheritAppStyle)\n this.requestUpdate()\n }\n\n disconnectedCallback() {\n const superDisconnected = (BaseElement.prototype as { disconnectedCallback?: () => void }).disconnectedCallback\n if (supportsLit && typeof superDisconnected === 'function') {\n superDisconnected.call(this)\n }\n this.#isMounted = false\n trackAppStyle(this, false)\n instances.delete(this)\n runtimeState.lifetimes.detached?.call(this.#publicInstance)\n }\n\n attributeChangedCallback(attrName: string, oldValue: string | null, newValue: string | null) {\n const superAttributeChanged = (BaseElement.prototype as {\n attributeChangedCallback?: (name: string, oldValue: string | null, newValue: string | null) => void\n }).attributeChangedCallback\n if (supportsLit && typeof superAttributeChanged === 'function') {\n superAttributeChanged.call(this, attrName, oldValue, newValue)\n }\n const propName = toCamelCase(attrName)\n if (!hasOwn(this.#properties, propName)) {\n return\n }\n const propOption = runtimeState.componentRef.properties?.[propName]\n this.#setProperty(propName, coerceValue(newValue, propOption?.type))\n }\n\n firstUpdated() {\n runtimeState.lifetimes.ready?.call(this.#publicInstance)\n this.#readyFired = true\n }\n\n updated() {\n this.#syncVirtualHostClasses()\n if (this.#usesLegacyTemplate) {\n bindRuntimeEvents(resolveRenderRoot(this), this.#methods, this)\n }\n }\n\n render() {\n const result = runtimeState.templateRef(this.#state, this.#renderContext)\n const appStyle = runtimeState.inheritAppStyle ? getAppStyle() : ''\n this.#usesLegacyTemplate = typeof result === 'string'\n return html`<style>${appStyle}</style><style>${runtimeState.styleRef}</style>${typeof result === 'string' ? unsafeHTML(result) : result}`\n }\n\n requestUpdate(name?: PropertyKey, oldValue?: unknown, options?: unknown) {\n const superRequestUpdate = (BaseElement.prototype as any).requestUpdate\n if (supportsLit && typeof superRequestUpdate === 'function') {\n return superRequestUpdate.call(this, name, oldValue, options)\n }\n if (this.#isMounted) {\n this.#renderLegacy()\n }\n return undefined\n }\n\n #applyAttributes() {\n if (!this.attributes || typeof this.attributes[Symbol.iterator] !== 'function') {\n return\n }\n for (const attr of this.attributes) {\n this.attributeChangedCallback(attr.name, null, attr.value)\n }\n }\n\n #applyDataPatch(patch: DataRecord) {\n if (!patch || typeof patch !== 'object') {\n return false\n }\n let changed = false\n const changedKeys: string[] = []\n const previousProperties: DataRecord = {}\n let copiedContainers: WeakSet<object> | undefined\n for (const [path, value] of Object.entries(patch)) {\n const segments = parseDataPath(path)\n const topKey = segments[0]\n if (!topKey || topKey === '$slots') {\n continue\n }\n let nextValue = value\n if (value !== null && typeof value === 'object') {\n // 整体提交需刷新整个子树,新的外层对象也可能复用已原地修改的后代。\n // 快照可保留内部别名,路径更新仍需按分支取得写入所有权。\n nextValue = cloneCommittedValue(value)\n }\n else if (Object.is(resolveDataPath(this.#state, segments), value)) {\n continue\n }\n if (hasOwn(this.#properties, topKey) && !hasOwn(previousProperties, topKey)) {\n previousProperties[topKey] = this.#properties[topKey]\n }\n if (segments.length > 1) {\n copiedContainers ??= new WeakSet<object>()\n }\n assignDataPath(this.#state, segments, nextValue, copiedContainers)\n if (hasOwn(this.#properties, topKey)) {\n this.#properties[topKey] = this.#state[topKey]\n }\n changedKeys.push(path)\n changed = true\n }\n if (changed) {\n this.requestUpdate()\n runComponentObservers(runtimeState.componentRef, this.#publicInstance, changedKeys, previousProperties)\n for (const key of changedKeys) {\n if (runtimeState.componentRef.properties?.[key]?.observer) {\n this.#observedKeys.add(key)\n }\n }\n }\n return changed\n }\n\n #setProperty(name: string, value: any) {\n const propOption = runtimeState.componentRef.properties?.[name]\n const coerced = coerceValue(value, propOption?.type)\n const oldValue = this.#properties[name]\n if (oldValue === coerced) {\n return\n }\n this.#properties[name] = coerced\n this.#state[name] = coerced\n if (this.#isMounted) {\n this.requestUpdate()\n }\n runComponentObservers(runtimeState.componentRef, this.#publicInstance, [name], { [name]: oldValue })\n if (propOption?.observer) {\n this.#observedKeys.add(name)\n }\n }\n\n #runInitialObservers() {\n if (this.#observerInitDone) {\n return\n }\n this.#observerInitDone = true\n for (const [propName, propOption] of runtimeState.propertyEntries) {\n if (!propOption.observer || this.#observedKeys.has(propName)) {\n continue\n }\n const value = this.#state[propName]\n propOption.observer.call(this.#publicInstance, value, undefined)\n this.#observedKeys.add(propName)\n }\n }\n\n #syncMethods(nextMethods: ComponentOptions['methods']) {\n const resolved = nextMethods ?? {}\n const bound: Record<string, (event: any) => any> = {}\n for (const [name, fn] of Object.entries(resolved)) {\n if (typeof fn === 'function') {\n bound[name] = fn.bind(this.#publicInstance)\n }\n }\n Object.assign(bound, this.#setupMethods)\n for (const name of this.#exposedMethodNames) {\n if (name in bound) {\n continue\n }\n const descriptor = Object.getOwnPropertyDescriptor(this, name)\n if (descriptor?.configurable && descriptor.value === this.#methods[name]) {\n delete (this as unknown as Record<string, unknown>)[name]\n }\n this.#exposedMethodNames.delete(name)\n }\n for (const key of Object.keys(this.#methods)) {\n if (!(key in bound)) {\n delete this.#methods[key]\n }\n }\n for (const [key, fn] of Object.entries(bound)) {\n const previous = this.#methods[key]\n this.#methods[key] = fn\n if (this.#exposedMethodNames.has(key)) {\n const descriptor = Object.getOwnPropertyDescriptor(this, key)\n if (!descriptor?.configurable || descriptor.value !== previous) {\n continue\n }\n }\n else if (key in this) {\n continue\n }\n Object.defineProperty(this, key, {\n configurable: true,\n enumerable: false,\n writable: true,\n value: fn,\n })\n this.#exposedMethodNames.add(key)\n }\n this.#renderContext = createRenderContext(this, this.#methods)\n }\n\n __weappSync(nextMethods: ComponentOptions['methods']) {\n this.#syncMethods(nextMethods)\n trackAppStyle(this, this.#isMounted && runtimeState.inheritAppStyle)\n this.requestUpdate()\n }\n\n __weappInvokePageLifetime(type: keyof PageLifeTimeHooks) {\n const hook = runtimeState.pageLifetimes[type]\n if (typeof hook === 'function') {\n hook.call(this.#publicInstance)\n }\n }\n\n #renderLegacy() {\n const result = runtimeState.templateRef(this.#state, this.#renderContext)\n const root = resolveRenderRoot(this)\n const appStyle = runtimeState.inheritAppStyle ? getAppStyle() : ''\n const styleMarkup = `<style>${appStyle}</style><style>${runtimeState.styleRef}</style>`\n if (typeof result === 'string') {\n root.innerHTML = `${styleMarkup}${result}`\n bindRuntimeEvents(root as ShadowRoot, this.#methods, this)\n }\n else if (result == null) {\n root.innerHTML = styleMarkup\n }\n else {\n root.innerHTML = `${styleMarkup}${String(result)}`\n }\n this.#syncVirtualHostClasses()\n if (!this.#readyFired) {\n runtimeState.lifetimes.ready?.call(this.#publicInstance)\n this.#readyFired = true\n }\n }\n\n #syncVirtualHostClasses() {\n const host = this as unknown as ClassAttributeElement\n if (!runtimeState.componentRef.options?.virtualHost) {\n clearVirtualHostClasses(host, this.#virtualHostClassTokens)\n clearVirtualHostParts(this.#virtualHostRootElement, this.#virtualHostPartTokens)\n this.#virtualHostRootElement = undefined\n return\n }\n const root = resolveRenderRoot(this)\n syncVirtualHostClasses(host, root, this.#virtualHostClassTokens)\n this.#virtualHostRootElement = syncVirtualHostParts(\n root,\n this.#virtualHostRootElement,\n this.#virtualHostPartTokens,\n )\n }\n }\n\n return WeappWebComponent as WeappComponentElementClass\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA6CA,SAAS,sBAAsB,MAA8B;CAC3D,MAAM,eAAgB,KAAiB;CACvC,IAAI,cACF,OAAO;CAET,IAAI,KAAK,YACP,OAAO,KAAK;CAEd,MAAM,OAAO,KAAK,cAAc;CAChC,OAAO,gBAAgB,aAAa,KAAK,OAAO;AAClD;AAEA,SAAS,yBAAyB,OAAiD;CACjF,OAAO,QACL,SACG,OAAO,UAAU,YACjB,OAAQ,MAAiC,gBAAgB,UAC9D;AACF;AAEA,SAAgB,4BAA4B,EAC1C,aACA,cACA,aACiE;CACjE,MAAM,qBAAqB;CAG3B,MAAM,0BAA0B,mBAAqD;EACnF,WAAW,qBAAqB;GAC9B,MAAM,YAAY,MAAM,sBAAsB,CAAC;GAC/C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AAK,eAAe;EAElC;EAEA,gBAAgB;GACd,MAAM,SAAS,aAAa,YAAY,KAAK,QAAQ,KAAK,cAAc;GACxE,MAAM,OAAO,kBAAkB,IAAI;GAEnC,MAAM,cAAc,UADH,aAAa,kBAAkB,YAAY,IAAI,GACzB,iBAAiB,aAAa,SAAS;GAC9E,IAAI,OAAO,WAAW,UAAU;IAC9B,KAAK,YAAY,GAAG,cAAc;IAClC,kBAAkB,MAAoB,KAAK,UAAU,IAAI;GAC3D,OACK,IAAI,UAAU,MACjB,KAAK,YAAY;QAGjB,KAAK,YAAY,GAAG,cAAc,OAAO,MAAM;GAEjD,KAAK,wBAAwB;GAC7B,IAAI,CAAC,KAAK,aAAa;IACrB,aAAa,UAAU,OAAO,KAAK,KAAK,eAAe;IACvD,KAAK,cAAc;GACrB;EACF;EAEA,0BAA0B;GACxB,MAAM,OAAO;GACb,IAAI,CAAC,aAAa,aAAa,SAAS,aAAa;IACnD,wBAAwB,MAAM,KAAK,uBAAuB;IAC1D,sBAAsB,KAAK,yBAAyB,KAAK,sBAAsB;IAC/E,KAAK,0BAA0B;IAC/B;GACF;GACA,MAAM,OAAO,kBAAkB,IAAI;GACnC,uBAAuB,MAAM,MAAM,KAAK,uBAAuB;GAC/D,KAAK,0BAA0B,qBAC7B,MACA,KAAK,yBACL,KAAK,sBACP;EACF;CACF;CAEA,OAAO;AACT"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { EVENT_ATTRIBUTE_PREFIXES, EVENT_FLAG_ATTRIBUTE_PREFIXES, decodeEventAttributeName } from "./constants.mjs";
|
|
2
|
+
import { listenRuntimeEvent, nameRuntimeEventHandler } from "../componentEvents.mjs";
|
|
2
3
|
import { invokeMiniProgramEventHandler } from "../inputHandlerResult.mjs";
|
|
3
4
|
|
|
4
5
|
//#region src/runtime/component/events.ts
|
|
@@ -14,12 +15,28 @@ function parseEventFlags(value) {
|
|
|
14
15
|
capture: tokenSet.has("capture")
|
|
15
16
|
};
|
|
16
17
|
}
|
|
18
|
+
const runtimeEventBindings = /* @__PURE__ */ new WeakMap();
|
|
19
|
+
function getEventFlagAttributeValue(element, encodedEventName) {
|
|
20
|
+
for (const prefix of EVENT_FLAG_ATTRIBUTE_PREFIXES) {
|
|
21
|
+
const value = element.getAttribute(`${prefix}${encodedEventName}`);
|
|
22
|
+
if (value !== null) return value;
|
|
23
|
+
}
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
17
26
|
function bindRuntimeEvents(root, methods, instance) {
|
|
18
27
|
if (typeof document === "undefined") return;
|
|
19
28
|
const walker = document.createTreeWalker(root, NodeFilter.SHOW_ELEMENT);
|
|
20
29
|
while (walker.nextNode()) {
|
|
21
30
|
const element = walker.currentNode;
|
|
31
|
+
let bindings = runtimeEventBindings.get(element);
|
|
32
|
+
if (bindings) for (const [attribute, binding] of bindings) {
|
|
33
|
+
const handlerName = element.getAttribute(attribute);
|
|
34
|
+
if (handlerName && methods[handlerName] === binding.handler && instance === binding.instance && getEventFlagAttributeValue(element, binding.encodedEventName) === binding.flagAttributeValue) continue;
|
|
35
|
+
binding.dispose();
|
|
36
|
+
bindings.delete(attribute);
|
|
37
|
+
}
|
|
22
38
|
for (const attribute of element.getAttributeNames()) {
|
|
39
|
+
if (bindings?.has(attribute)) continue;
|
|
23
40
|
const matchedPrefix = EVENT_ATTRIBUTE_PREFIXES.find((prefix) => attribute.startsWith(prefix));
|
|
24
41
|
if (!matchedPrefix || EVENT_FLAG_ATTRIBUTE_PREFIXES.some((prefix) => attribute.startsWith(prefix))) continue;
|
|
25
42
|
const handlerName = element.getAttribute(attribute);
|
|
@@ -28,8 +45,9 @@ function bindRuntimeEvents(root, methods, instance) {
|
|
|
28
45
|
if (!handler) continue;
|
|
29
46
|
const encodedEventName = attribute.slice(matchedPrefix.length);
|
|
30
47
|
const eventName = decodeEventAttributeName(encodedEventName);
|
|
31
|
-
const
|
|
32
|
-
|
|
48
|
+
const flagAttributeValue = getEventFlagAttributeValue(element, encodedEventName);
|
|
49
|
+
const flags = parseEventFlags(flagAttributeValue);
|
|
50
|
+
const listener = nameRuntimeEventHandler((nativeEvent) => {
|
|
33
51
|
if (flags.catch) nativeEvent.stopPropagation();
|
|
34
52
|
const dataset = { ...element.dataset };
|
|
35
53
|
const syntheticEvent = {
|
|
@@ -41,8 +59,21 @@ function bindRuntimeEvents(root, methods, instance) {
|
|
|
41
59
|
originalEvent: nativeEvent
|
|
42
60
|
};
|
|
43
61
|
invokeMiniProgramEventHandler(handler, instance, syntheticEvent, nativeEvent);
|
|
44
|
-
},
|
|
62
|
+
}, eventName);
|
|
63
|
+
const dispose = listenRuntimeEvent(element, eventName, listener, flags.capture);
|
|
64
|
+
if (!bindings) {
|
|
65
|
+
bindings = /* @__PURE__ */ new Map();
|
|
66
|
+
runtimeEventBindings.set(element, bindings);
|
|
67
|
+
}
|
|
68
|
+
bindings.set(attribute, {
|
|
69
|
+
encodedEventName,
|
|
70
|
+
flagAttributeValue,
|
|
71
|
+
handler,
|
|
72
|
+
instance,
|
|
73
|
+
dispose
|
|
74
|
+
});
|
|
45
75
|
}
|
|
76
|
+
if (bindings?.size === 0) runtimeEventBindings.delete(element);
|
|
46
77
|
}
|
|
47
78
|
}
|
|
48
79
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"events.mjs","names":[],"sources":["../../../src/runtime/component/events.ts"],"sourcesContent":["import type { ComponentPublicInstance } from './types'\nimport { invokeMiniProgramEventHandler } from '../inputHandlerResult'\nimport {\n decodeEventAttributeName,\n EVENT_ATTRIBUTE_PREFIXES,\n EVENT_FLAG_ATTRIBUTE_PREFIXES,\n} from './constants'\n\nfunction parseEventFlags(value: string | null) {\n if (!value) {\n return { catch: false, capture: false }\n }\n const tokens = value.split(',').map(token => token.trim()).filter(Boolean)\n const tokenSet = new Set(tokens)\n return {\n catch: tokenSet.has('catch'),\n capture: tokenSet.has('capture'),\n }\n}\n\nexport function bindRuntimeEvents(\n root: HTMLElement | ShadowRoot,\n methods: Record<string, (event: any) => any>,\n instance: ComponentPublicInstance,\n) {\n if (typeof document === 'undefined') {\n return\n }\n const walker = document.createTreeWalker(root, NodeFilter.SHOW_ELEMENT)\n while (walker.nextNode()) {\n const element = walker.currentNode as HTMLElement\n for (const attribute of element.getAttributeNames()) {\n const matchedPrefix = EVENT_ATTRIBUTE_PREFIXES.find(prefix => attribute.startsWith(prefix))\n if (!matchedPrefix || EVENT_FLAG_ATTRIBUTE_PREFIXES.some(prefix => attribute.startsWith(prefix))) {\n continue\n }\n const handlerName = element.getAttribute(attribute)\n if (!handlerName) {\n continue\n }\n const handler = methods[handlerName]\n if (!handler) {\n continue\n }\n const encodedEventName = attribute.slice(matchedPrefix.length)\n const eventName = decodeEventAttributeName(encodedEventName)\n const flagAttributeValue =
|
|
1
|
+
{"version":3,"file":"events.mjs","names":[],"sources":["../../../src/runtime/component/events.ts"],"sourcesContent":["import type { ComponentPublicInstance } from './types'\nimport { listenRuntimeEvent, nameRuntimeEventHandler } from '../componentEvents'\nimport { invokeMiniProgramEventHandler } from '../inputHandlerResult'\nimport {\n decodeEventAttributeName,\n EVENT_ATTRIBUTE_PREFIXES,\n EVENT_FLAG_ATTRIBUTE_PREFIXES,\n} from './constants'\n\ninterface RuntimeEventFlags {\n catch: boolean\n capture: boolean\n}\n\nfunction parseEventFlags(value: string | null): RuntimeEventFlags {\n if (!value) {\n return { catch: false, capture: false }\n }\n const tokens = value.split(',').map(token => token.trim()).filter(Boolean)\n const tokenSet = new Set(tokens)\n return {\n catch: tokenSet.has('catch'),\n capture: tokenSet.has('capture'),\n }\n}\n\ninterface RuntimeEventBinding {\n encodedEventName: string\n flagAttributeValue: string | null\n handler: (event: unknown) => unknown\n instance: ComponentPublicInstance\n dispose: () => void\n}\n\nconst runtimeEventBindings = new WeakMap<HTMLElement, Map<string, RuntimeEventBinding>>()\n\nfunction getEventFlagAttributeValue(element: HTMLElement, encodedEventName: string) {\n for (const prefix of EVENT_FLAG_ATTRIBUTE_PREFIXES) {\n const value = element.getAttribute(`${prefix}${encodedEventName}`)\n if (value !== null) {\n return value\n }\n }\n return null\n}\n\nexport function bindRuntimeEvents(\n root: HTMLElement | ShadowRoot,\n methods: Record<string, (event: any) => any>,\n instance: ComponentPublicInstance,\n) {\n if (typeof document === 'undefined') {\n return\n }\n const walker = document.createTreeWalker(root, NodeFilter.SHOW_ELEMENT)\n while (walker.nextNode()) {\n const element = walker.currentNode as HTMLElement\n let bindings = runtimeEventBindings.get(element)\n if (bindings) {\n for (const [attribute, binding] of bindings) {\n const handlerName = element.getAttribute(attribute)\n if (\n handlerName\n && methods[handlerName] === binding.handler\n && instance === binding.instance\n && getEventFlagAttributeValue(element, binding.encodedEventName) === binding.flagAttributeValue\n ) {\n continue\n }\n binding.dispose()\n bindings.delete(attribute)\n }\n }\n for (const attribute of element.getAttributeNames()) {\n if (bindings?.has(attribute)) {\n continue\n }\n const matchedPrefix = EVENT_ATTRIBUTE_PREFIXES.find(prefix => attribute.startsWith(prefix))\n if (!matchedPrefix || EVENT_FLAG_ATTRIBUTE_PREFIXES.some(prefix => attribute.startsWith(prefix))) {\n continue\n }\n const handlerName = element.getAttribute(attribute)\n if (!handlerName) {\n continue\n }\n const handler = methods[handlerName]\n if (!handler) {\n continue\n }\n const encodedEventName = attribute.slice(matchedPrefix.length)\n const eventName = decodeEventAttributeName(encodedEventName)\n const flagAttributeValue = getEventFlagAttributeValue(element, encodedEventName)\n const flags = parseEventFlags(flagAttributeValue)\n const listener = nameRuntimeEventHandler((nativeEvent) => {\n if (flags.catch) {\n nativeEvent.stopPropagation()\n }\n const dataset = { ...element.dataset }\n const syntheticEvent = {\n type: eventName,\n timeStamp: nativeEvent.timeStamp,\n detail: (nativeEvent as CustomEvent).detail ?? (nativeEvent as InputEvent).data ?? undefined,\n target: {\n dataset,\n },\n currentTarget: {\n dataset,\n },\n originalEvent: nativeEvent,\n }\n invokeMiniProgramEventHandler(handler, instance, syntheticEvent, nativeEvent)\n }, eventName)\n const dispose = listenRuntimeEvent(element, eventName, listener, flags.capture)\n if (!bindings) {\n bindings = new Map()\n runtimeEventBindings.set(element, bindings)\n }\n bindings.set(attribute, { encodedEventName, flagAttributeValue, handler, instance, dispose })\n }\n if (bindings?.size === 0) {\n runtimeEventBindings.delete(element)\n }\n }\n}\n"],"mappings":";;;;;AAcA,SAAS,gBAAgB,OAAyC;CAChE,IAAI,CAAC,OACH,OAAO;EAAE,OAAO;EAAO,SAAS;CAAM;CAExC,MAAM,SAAS,MAAM,MAAM,GAAG,CAAC,CAAC,KAAI,UAAS,MAAM,KAAK,CAAC,CAAC,CAAC,OAAO,OAAO;CACzE,MAAM,WAAW,IAAI,IAAI,MAAM;CAC/B,OAAO;EACL,OAAO,SAAS,IAAI,OAAO;EAC3B,SAAS,SAAS,IAAI,SAAS;CACjC;AACF;AAUA,MAAM,uCAAuB,IAAI,QAAuD;AAExF,SAAS,2BAA2B,SAAsB,kBAA0B;CAClF,KAAK,MAAM,UAAU,+BAA+B;EAClD,MAAM,QAAQ,QAAQ,aAAa,GAAG,SAAS,kBAAkB;EACjE,IAAI,UAAU,MACZ,OAAO;CAEX;CACA,OAAO;AACT;AAEA,SAAgB,kBACd,MACA,SACA,UACA;CACA,IAAI,OAAO,aAAa,aACtB;CAEF,MAAM,SAAS,SAAS,iBAAiB,MAAM,WAAW,YAAY;CACtE,OAAO,OAAO,SAAS,GAAG;EACxB,MAAM,UAAU,OAAO;EACvB,IAAI,WAAW,qBAAqB,IAAI,OAAO;EAC/C,IAAI,UACF,KAAK,MAAM,CAAC,WAAW,YAAY,UAAU;GAC3C,MAAM,cAAc,QAAQ,aAAa,SAAS;GAClD,IACE,eACG,QAAQ,iBAAiB,QAAQ,WACjC,aAAa,QAAQ,YACrB,2BAA2B,SAAS,QAAQ,gBAAgB,MAAM,QAAQ,oBAE7E;GAEF,QAAQ,QAAQ;GAChB,SAAS,OAAO,SAAS;EAC3B;EAEF,KAAK,MAAM,aAAa,QAAQ,kBAAkB,GAAG;GACnD,IAAI,UAAU,IAAI,SAAS,GACzB;GAEF,MAAM,gBAAgB,yBAAyB,MAAK,WAAU,UAAU,WAAW,MAAM,CAAC;GAC1F,IAAI,CAAC,iBAAiB,8BAA8B,MAAK,WAAU,UAAU,WAAW,MAAM,CAAC,GAC7F;GAEF,MAAM,cAAc,QAAQ,aAAa,SAAS;GAClD,IAAI,CAAC,aACH;GAEF,MAAM,UAAU,QAAQ;GACxB,IAAI,CAAC,SACH;GAEF,MAAM,mBAAmB,UAAU,MAAM,cAAc,MAAM;GAC7D,MAAM,YAAY,yBAAyB,gBAAgB;GAC3D,MAAM,qBAAqB,2BAA2B,SAAS,gBAAgB;GAC/E,MAAM,QAAQ,gBAAgB,kBAAkB;GAChD,MAAM,WAAW,yBAAyB,gBAAgB;IACxD,IAAI,MAAM,OACR,YAAY,gBAAgB;IAE9B,MAAM,UAAU,EAAE,GAAG,QAAQ,QAAQ;IACrC,MAAM,iBAAiB;KACrB,MAAM;KACN,WAAW,YAAY;KACvB,QAAS,YAA4B,UAAW,YAA2B,QAAQ;KACnF,QAAQ,EACN,QACF;KACA,eAAe,EACb,QACF;KACA,eAAe;IACjB;IACA,8BAA8B,SAAS,UAAU,gBAAgB,WAAW;GAC9E,GAAG,SAAS;GACZ,MAAM,UAAU,mBAAmB,SAAS,WAAW,UAAU,MAAM,OAAO;GAC9E,IAAI,CAAC,UAAU;IACb,2BAAW,IAAI,IAAI;IACnB,qBAAqB,IAAI,SAAS,QAAQ;GAC5C;GACA,SAAS,IAAI,WAAW;IAAE;IAAkB;IAAoB;IAAS;IAAU;GAAQ,CAAC;EAC9F;EACA,IAAI,UAAU,SAAS,GACrB,qBAAqB,OAAO,OAAO;CAEvC;AACF"}
|
|
@@ -1,15 +1,18 @@
|
|
|
1
|
+
import { hasOwn } from "../utils/object.mjs";
|
|
2
|
+
|
|
1
3
|
//#region src/runtime/component/publicInstance.ts
|
|
2
4
|
const componentPublicInstanceTargets = /* @__PURE__ */ new WeakMap();
|
|
3
5
|
function resolveComponentPublicInstanceTarget(value) {
|
|
4
6
|
if (!value || typeof value !== "object") return;
|
|
5
7
|
return componentPublicInstanceTargets.get(value);
|
|
6
8
|
}
|
|
7
|
-
function createComponentPublicInstance(target, runtimePrototype, resolveComponentMethod) {
|
|
9
|
+
function createComponentPublicInstance(target, runtimePrototype, resolveComponentMethod, componentProperties) {
|
|
8
10
|
const runtimeMethods = /* @__PURE__ */ new Map();
|
|
9
11
|
const publicInstance = new Proxy(target, {
|
|
10
12
|
get(instance, key) {
|
|
11
|
-
|
|
12
|
-
if (
|
|
13
|
+
const ownDescriptor = Reflect.getOwnPropertyDescriptor(instance, key);
|
|
14
|
+
if (ownDescriptor && (!ownDescriptor.configurable || !componentProperties || !hasOwn(componentProperties, key))) return Reflect.get(instance, key, instance);
|
|
15
|
+
if (Reflect.getOwnPropertyDescriptor(runtimePrototype, key) && !ownDescriptor) {
|
|
13
16
|
const value = Reflect.get(instance, key, instance);
|
|
14
17
|
if (typeof value !== "function") return value;
|
|
15
18
|
const cached = runtimeMethods.get(key);
|
|
@@ -23,6 +26,7 @@ function createComponentPublicInstance(target, runtimePrototype, resolveComponen
|
|
|
23
26
|
}
|
|
24
27
|
const componentMethod = resolveComponentMethod?.(key);
|
|
25
28
|
if (typeof componentMethod === "function") return componentMethod;
|
|
29
|
+
if (ownDescriptor) return Reflect.get(instance, key, instance);
|
|
26
30
|
return typeof key === "symbol" ? Reflect.get(instance, key, instance) : void 0;
|
|
27
31
|
},
|
|
28
32
|
set(instance, key, value) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"publicInstance.mjs","names":[],"sources":["../../../src/runtime/component/publicInstance.ts"],"sourcesContent":["import type { ComponentPublicInstance } from './types'\n\nconst componentPublicInstanceTargets = new WeakMap<object, ComponentPublicInstance>()\n\nexport function resolveComponentPublicInstanceTarget(value: unknown) {\n if (!value || typeof value !== 'object') {\n return undefined\n }\n return componentPublicInstanceTargets.get(value)\n}\n\nexport function createComponentPublicInstance(\n target: ComponentPublicInstance,\n runtimePrototype: object,\n resolveComponentMethod?: (key: PropertyKey) => unknown,\n): ComponentPublicInstance {\n type RuntimeMethod = (...args: any[]) => unknown\n const runtimeMethods = new Map<PropertyKey, { source: RuntimeMethod, bound: RuntimeMethod }>()\n\n const publicInstance = new Proxy(target, {\n get(instance, key) {\n const ownDescriptor = Reflect.getOwnPropertyDescriptor(instance, key)\n if (ownDescriptor) {\n return Reflect.get(instance, key, instance)\n }\n const runtimeDescriptor = Reflect.getOwnPropertyDescriptor(runtimePrototype, key)\n if (runtimeDescriptor) {\n const value = Reflect.get(instance, key, instance)\n if (typeof value !== 'function') {\n return value\n }\n const cached = runtimeMethods.get(key)\n if (cached && cached.source === value) {\n return cached.bound\n }\n const bound = value.bind(instance)\n runtimeMethods.set(key, { source: value, bound })\n return bound\n }\n const componentMethod = resolveComponentMethod?.(key)\n if (typeof componentMethod === 'function') {\n return componentMethod\n }\n return typeof key === 'symbol' ? Reflect.get(instance, key, instance) : undefined\n },\n set(instance, key, value) {\n if (Reflect.getOwnPropertyDescriptor(instance, key) || typeof key === 'symbol') {\n return Reflect.set(instance, key, value, instance)\n }\n Reflect.defineProperty(instance, key, {\n configurable: true,\n enumerable: true,\n writable: true,\n value,\n })\n return true\n },\n has(instance, key) {\n return Reflect.getOwnPropertyDescriptor(instance, key) !== undefined\n || Reflect.getOwnPropertyDescriptor(runtimePrototype, key) !== undefined\n || typeof resolveComponentMethod?.(key) === 'function'\n || (typeof key === 'symbol' && Reflect.has(instance, key))\n },\n })\n componentPublicInstanceTargets.set(publicInstance, target)\n return publicInstance\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"publicInstance.mjs","names":[],"sources":["../../../src/runtime/component/publicInstance.ts"],"sourcesContent":["import type { ComponentPublicInstance } from './types'\nimport { hasOwn } from '../utils/object'\n\nconst componentPublicInstanceTargets = new WeakMap<object, ComponentPublicInstance>()\n\nexport function resolveComponentPublicInstanceTarget(value: unknown) {\n if (!value || typeof value !== 'object') {\n return undefined\n }\n return componentPublicInstanceTargets.get(value)\n}\n\nexport function createComponentPublicInstance(\n target: ComponentPublicInstance,\n runtimePrototype: object,\n resolveComponentMethod?: (key: PropertyKey) => unknown,\n componentProperties?: Readonly<Record<string, unknown>>,\n): ComponentPublicInstance {\n type RuntimeMethod = (...args: any[]) => unknown\n const runtimeMethods = new Map<PropertyKey, { source: RuntimeMethod, bound: RuntimeMethod }>()\n\n const publicInstance = new Proxy(target, {\n get(instance, key) {\n const ownDescriptor = Reflect.getOwnPropertyDescriptor(instance, key)\n // 只有声明的 prop 冲突才优先方法表;普通自有字段与不可配置属性保持宿主语义。\n if (ownDescriptor && (!ownDescriptor.configurable || !componentProperties || !hasOwn(componentProperties, key))) {\n return Reflect.get(instance, key, instance)\n }\n const runtimeDescriptor = Reflect.getOwnPropertyDescriptor(runtimePrototype, key)\n if (runtimeDescriptor && !ownDescriptor) {\n const value = Reflect.get(instance, key, instance)\n if (typeof value !== 'function') {\n return value\n }\n const cached = runtimeMethods.get(key)\n if (cached && cached.source === value) {\n return cached.bound\n }\n const bound = value.bind(instance)\n runtimeMethods.set(key, { source: value, bound })\n return bound\n }\n // 公共实例解析方法;DOM 同名属性仍由父级输入驱动。\n const componentMethod = resolveComponentMethod?.(key)\n if (typeof componentMethod === 'function') {\n return componentMethod\n }\n if (ownDescriptor) {\n return Reflect.get(instance, key, instance)\n }\n return typeof key === 'symbol' ? Reflect.get(instance, key, instance) : undefined\n },\n set(instance, key, value) {\n if (Reflect.getOwnPropertyDescriptor(instance, key) || typeof key === 'symbol') {\n return Reflect.set(instance, key, value, instance)\n }\n Reflect.defineProperty(instance, key, {\n configurable: true,\n enumerable: true,\n writable: true,\n value,\n })\n return true\n },\n has(instance, key) {\n return Reflect.getOwnPropertyDescriptor(instance, key) !== undefined\n || Reflect.getOwnPropertyDescriptor(runtimePrototype, key) !== undefined\n || typeof resolveComponentMethod?.(key) === 'function'\n || (typeof key === 'symbol' && Reflect.has(instance, key))\n },\n })\n componentPublicInstan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AK;IACpC,cAAc;IACd,YAAY;IACZ,UAAU;IACV;GACF,CAAC;GACD,OAAO;EACT;EACA,IAAI,UAAU,KAAK;GACjB,OAAO,QAAQ,yBAAyB,UAAU,GAAG,MAAM,UACtD,QAAQ,yBAAyB,kBAAkB,GAAG,MAAM,UAC5D,OAAO,yBAAyB,GAAG,MAAM,cACxC,OAAO,QAAQ,YAAY,QAAQ,IAAI,UAAU,GAAG;EAC5D;CACF,CAAC;CACD,+BAA+B,IAAI,gBAAgB,MAAM;CACzD,OAAO;AACT"}
|
|
@@ -31,6 +31,11 @@ function createPropertyEntries(component) {
|
|
|
31
31
|
function createObservedAttributes(propertyEntries) {
|
|
32
32
|
return propertyEntries.map(([name]) => hyphenate(name));
|
|
33
33
|
}
|
|
34
|
+
function inheritsAppStyle(kind, component) {
|
|
35
|
+
if (kind === "page") return true;
|
|
36
|
+
const { styleIsolation, addGlobalClass } = component.options ?? {};
|
|
37
|
+
return styleIsolation === void 0 ? Boolean(addGlobalClass) : styleIsolation !== "isolated";
|
|
38
|
+
}
|
|
34
39
|
function createComponentRuntimeState(options) {
|
|
35
40
|
const { component, warnings } = resolveNormalizedComponent(options.component ?? {});
|
|
36
41
|
const propertyEntries = createPropertyEntries(component);
|
|
@@ -39,6 +44,7 @@ function createComponentRuntimeState(options) {
|
|
|
39
44
|
id: options.id,
|
|
40
45
|
templateRef: options.template,
|
|
41
46
|
styleRef: options.style ?? "",
|
|
47
|
+
inheritAppStyle: inheritsAppStyle(options.kind, component),
|
|
42
48
|
componentRef: component,
|
|
43
49
|
observerInitEnabled: Boolean(options.observerInit),
|
|
44
50
|
propertyEntries,
|
|
@@ -56,6 +62,7 @@ function updateComponentRuntimeState(state, options) {
|
|
|
56
62
|
state.templateRef = options.template;
|
|
57
63
|
state.id = options.id;
|
|
58
64
|
state.styleRef = options.style ?? "";
|
|
65
|
+
state.inheritAppStyle = inheritsAppStyle(options.kind, component);
|
|
59
66
|
state.componentRef = component;
|
|
60
67
|
state.observerInitEnabled = Boolean(options.observerInit);
|
|
61
68
|
state.lifetimes = component.lifetimes ?? {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state.mjs","names":[],"sources":["../../../src/runtime/component/state.ts"],"sourcesContent":["import type {\n ComponentOptions,\n DataRecord,\n DefineComponentOptions,\n LifeTimeHooks,\n NormalizedComponentOptions,\n PageLifeTimeHooks,\n PropertyDeclaration,\n PropertyOption,\n} from './types'\nimport { hasOwn } from '../utils/object'\nimport { normalizeBehaviors } from './behavior'\nimport { cloneValue, hyphenate } from './utils'\n\ntype PropertyEntry = [string, PropertyOption]\n\nexport interface ComponentRuntimeState {\n id?: string\n templateRef: DefineComponentOptions['template']\n styleRef: string\n componentRef: NormalizedComponentOptions\n observerInitEnabled: boolean\n propertyEntries: PropertyEntry[]\n observedAttributes: string[]\n defaultPropertyValues: DataRecord\n lifetimes: LifeTimeHooks\n pageLifetimes: PageLifeTimeHooks\n}\n\nfunction normalizePropertyDeclaration(declaration: PropertyDeclaration): PropertyOption {\n if (declaration === null || typeof declaration === 'function') {\n return { type: declaration }\n }\n return declaration\n}\n\nfunction resolveNormalizedComponent(component: ComponentOptions) {\n const normalized = normalizeBehaviors(component)\n const resolved = normalized.component!\n return {\n warnings: normalized.warnings,\n component: {\n ...resolved,\n properties: Object.fromEntries(\n Object.entries(resolved.properties ?? {}).map(([name, declaration]) => [\n name,\n normalizePropertyDeclaration(declaration),\n ]),\n ),\n } satisfies NormalizedComponentOptions,\n }\n}\n\nfunction createDefaultPropertyValues(propertyEntries: PropertyEntry[]) {\n return propertyEntries.reduce<DataRecord>((acc, [name, prop]) => {\n if (prop !== null && typeof prop === 'object' && hasOwn(prop, 'value')) {\n acc[name] = cloneValue(prop.value)\n }\n else {\n acc[name] = undefined\n }\n return acc\n }, {})\n}\n\nfunction createPropertyEntries(component: NormalizedComponentOptions): PropertyEntry[] {\n return Object.entries(component.properties)\n}\n\nfunction createObservedAttributes(propertyEntries: PropertyEntry[]) {\n return propertyEntries.map(([name]) => hyphenate(name))\n}\n\nexport function createComponentRuntimeState(options: DefineComponentOptions) {\n const { component, warnings } = resolveNormalizedComponent(options.component ?? {})\n const propertyEntries = createPropertyEntries(component)\n const state: ComponentRuntimeState = {\n id: options.id,\n templateRef: options.template,\n styleRef: options.style ?? '',\n componentRef: component,\n observerInitEnabled: Boolean(options.observerInit),\n propertyEntries,\n observedAttributes: createObservedAttributes(propertyEntries),\n defaultPropertyValues: createDefaultPropertyValues(propertyEntries),\n lifetimes: component.lifetimes ?? {},\n pageLifetimes: component.pageLifetimes ?? {},\n }\n return {\n state,\n warnings,\n }\n}\n\nexport function updateComponentRuntimeState(state: ComponentRuntimeState, options: DefineComponentOptions) {\n const { component, warnings } = resolveNormalizedComponent(options.component ?? {})\n const propertyEntries = createPropertyEntries(component)\n state.templateRef = options.template\n state.id = options.id\n state.styleRef = options.style ?? ''\n state.componentRef = component\n state.observerInitEnabled = Boolean(options.observerInit)\n state.lifetimes = component.lifetimes ?? {}\n state.pageLifetimes = component.pageLifetimes ?? {}\n state.propertyEntries = propertyEntries\n state.observedAttributes = createObservedAttributes(propertyEntries)\n state.defaultPropertyValues = createDefaultPropertyValues(propertyEntries)\n return {\n warnings,\n nextMethods: component.methods ?? {},\n }\n}\n"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"state.mjs","names":[],"sources":["../../../src/runtime/component/state.ts"],"sourcesContent":["import type {\n ComponentOptions,\n DataRecord,\n DefineComponentOptions,\n LifeTimeHooks,\n NormalizedComponentOptions,\n PageLifeTimeHooks,\n PropertyDeclaration,\n PropertyOption,\n} from './types'\nimport { hasOwn } from '../utils/object'\nimport { normalizeBehaviors } from './behavior'\nimport { cloneValue, hyphenate } from './utils'\n\ntype PropertyEntry = [string, PropertyOption]\n\nexport interface ComponentRuntimeState {\n id?: string\n templateRef: DefineComponentOptions['template']\n styleRef: string\n inheritAppStyle: boolean\n componentRef: NormalizedComponentOptions\n observerInitEnabled: boolean\n propertyEntries: PropertyEntry[]\n observedAttributes: string[]\n defaultPropertyValues: DataRecord\n lifetimes: LifeTimeHooks\n pageLifetimes: PageLifeTimeHooks\n}\n\nfunction normalizePropertyDeclaration(declaration: PropertyDeclaration): PropertyOption {\n if (declaration === null || typeof declaration === 'function') {\n return { type: declaration }\n }\n return declaration\n}\n\nfunction resolveNormalizedComponent(component: ComponentOptions) {\n const normalized = normalizeBehaviors(component)\n const resolved = normalized.component!\n return {\n warnings: normalized.warnings,\n component: {\n ...resolved,\n properties: Object.fromEntries(\n Object.entries(resolved.properties ?? {}).map(([name, declaration]) => [\n name,\n normalizePropertyDeclaration(declaration),\n ]),\n ),\n } satisfies NormalizedComponentOptions,\n }\n}\n\nfunction createDefaultPropertyValues(propertyEntries: PropertyEntry[]) {\n return propertyEntries.reduce<DataRecord>((acc, [name, prop]) => {\n if (prop !== null && typeof prop === 'object' && hasOwn(prop, 'value')) {\n acc[name] = cloneValue(prop.value)\n }\n else {\n acc[name] = undefined\n }\n return acc\n }, {})\n}\n\nfunction createPropertyEntries(component: NormalizedComponentOptions): PropertyEntry[] {\n return Object.entries(component.properties)\n}\n\nfunction createObservedAttributes(propertyEntries: PropertyEntry[]) {\n return propertyEntries.map(([name]) => hyphenate(name))\n}\n\nfunction inheritsAppStyle(kind: DefineComponentOptions['kind'], component: NormalizedComponentOptions) {\n if (kind === 'page') {\n return true\n }\n const { styleIsolation, addGlobalClass } = component.options ?? {}\n return styleIsolation === undefined ? Boolean(addGlobalClass) : styleIsolation !== 'isolated'\n}\n\nexport function createComponentRuntimeState(options: DefineComponentOptions) {\n const { component, warnings } = resolveNormalizedComponent(options.component ?? {})\n const propertyEntries = createPropertyEntries(component)\n const state: ComponentRuntimeState = {\n id: options.id,\n templateRef: options.template,\n styleRef: options.style ?? '',\n inheritAppStyle: inheritsAppStyle(options.kind, component),\n componentRef: component,\n observerInitEnabled: Boolean(options.observerInit),\n propertyEntries,\n observedAttributes: createObservedAttributes(propertyEntries),\n defaultPropertyValues: createDefaultPropertyValues(propertyEntries),\n lifetimes: component.lifetimes ?? {},\n pageLifetimes: component.pageLifetimes ?? {},\n }\n return {\n state,\n warnings,\n }\n}\n\nexport function updateComponentRuntimeState(state: ComponentRuntimeState, options: DefineComponentOptions) {\n const { component, warnings } = resolveNormalizedComponent(options.component ?? {})\n const propertyEntries = createPropertyEntries(component)\n state.templateRef = options.template\n state.id = options.id\n state.styleRef = options.style ?? ''\n state.inheritAppStyle = inheritsAppStyle(options.kind, component)\n state.componentRef = component\n state.observerInitEnabled = Boolean(options.observerInit)\n state.lifetimes = component.lifetimes ?? {}\n state.pageLifetimes = component.pageLifetimes ?? {}\n state.propertyEntries = propertyEntries\n state.observedAttributes = createObservedAttributes(propertyEntries)\n state.defaultPropertyValues = createDefaultPropertyValues(propertyEntries)\n return {\n warnings,\n nextMethods: component.methods ?? {},\n }\n}\n"],"mappings":";;;;;AA8BA,SAAS,6BAA6B,aAAkD;CACtF,IAAI,gBAAgB,QAAQ,OAAO,gBAAgB,YACjD,OAAO,EAAE,MAAM,YAAY;CAE7B,OAAO;AACT;AAEA,SAAS,2BAA2B,WAA6B;CAC/D,MAAM,aAAa,mBAAmB,SAAS;CAC/C,MAAM,WAAW,WAAW;CAC5B,OAAO;EACL,UAAU,WAAW;EACrB,WAAW;GACT,GAAG;GACH,YAAY,OAAO,YACjB,OAAO,QAAQ,SAAS,cAAc,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,iBAAiB,CACrE,MACA,6BAA6B,WAAW,CAC1C,CAAC,CACH;EACF;CACF;AACF;AAEA,SAAS,4BAA4B,iBAAkC;CACrE,OAAO,gBAAgB,QAAoB,KAAK,CAAC,MAAM,UAAU;EAC/D,IAAI,SAAS,QAAQ,OAAO,SAAS,YAAY,OAAO,MAAM,OAAO,GACnE,IAAI,QAAQ,WAAW,KAAK,KAAK;OAGjC,IAAI,QAAQ;EAEd,OAAO;CACT,GAAG,CAAC,CAAC;AACP;AAEA,SAAS,sBAAsB,WAAwD;CACrF,O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4BAA4B,eAAe;CACzE,OAAO;EACL;EACA,aAAa,UAAU,WAAW,CAAC;CACrC;AACF"}
|
|
@@ -45,6 +45,8 @@ export interface ComponentOptions {
|
|
|
45
45
|
}
|
|
46
46
|
export interface DefineComponentOptions {
|
|
47
47
|
id?: string;
|
|
48
|
+
/** 注册层提供的样式域;组件仍按 styleIsolation 决定是否接收应用样式。 */
|
|
49
|
+
kind?: 'page' | 'component';
|
|
48
50
|
template: TemplateRenderer;
|
|
49
51
|
style?: string;
|
|
50
52
|
component?: ComponentOptions;
|
|
@@ -17,6 +17,19 @@ function cloneValue(value) {
|
|
|
17
17
|
if (value && typeof value === "object") return { ...value };
|
|
18
18
|
return value;
|
|
19
19
|
}
|
|
20
|
+
function cloneCommittedValue(value, snapshots = /* @__PURE__ */ new WeakMap()) {
|
|
21
|
+
if (value === null || typeof value !== "object") return value;
|
|
22
|
+
if (!Array.isArray(value)) {
|
|
23
|
+
const prototype = Object.getPrototypeOf(value);
|
|
24
|
+
if (prototype !== Object.prototype && prototype !== null) return value;
|
|
25
|
+
}
|
|
26
|
+
const existing = snapshots.get(value);
|
|
27
|
+
if (existing) return existing;
|
|
28
|
+
const snapshot = cloneValue(value);
|
|
29
|
+
snapshots.set(value, snapshot);
|
|
30
|
+
for (const key of Object.keys(snapshot)) snapshot[key] = cloneCommittedValue(snapshot[key], snapshots);
|
|
31
|
+
return snapshot;
|
|
32
|
+
}
|
|
20
33
|
function parseDataPath(path) {
|
|
21
34
|
return path.replace(ARRAY_INDEX_PATH_RE, ".$1").split(".").map((segment) => segment.trim()).filter((segment) => segment && !UNSAFE_PATH_SEGMENTS.has(segment));
|
|
22
35
|
}
|
|
@@ -34,13 +47,20 @@ function resolveDataPath(target, segments) {
|
|
|
34
47
|
}
|
|
35
48
|
return current;
|
|
36
49
|
}
|
|
37
|
-
function assignDataPath(target, segments, value) {
|
|
50
|
+
function assignDataPath(target, segments, value, copiedContainers) {
|
|
38
51
|
if (!segments.length) return;
|
|
39
52
|
let current = target;
|
|
40
53
|
for (let index = 0; index < segments.length - 1; index += 1) {
|
|
41
54
|
const segment = normalizePathSegment(segments[index]);
|
|
42
55
|
const nextSegment = segments[index + 1];
|
|
43
|
-
|
|
56
|
+
const next = current[segment];
|
|
57
|
+
if (next == null || typeof next !== "object") {
|
|
58
|
+
current[segment] = createPathContainer(nextSegment);
|
|
59
|
+
copiedContainers?.add(current[segment]);
|
|
60
|
+
} else if (!copiedContainers?.has(next)) {
|
|
61
|
+
current[segment] = cloneValue(next);
|
|
62
|
+
copiedContainers?.add(current[segment]);
|
|
63
|
+
}
|
|
44
64
|
current = current[segment];
|
|
45
65
|
}
|
|
46
66
|
current[normalizePathSegment(segments[segments.length - 1])] = value;
|
|
@@ -70,5 +90,5 @@ function coerceValue(value, type) {
|
|
|
70
90
|
}
|
|
71
91
|
|
|
72
92
|
//#endregion
|
|
73
|
-
export { assignDataPath, cloneValue, coerceValue, hyphenate, parseDataPath, resolveDataPath, toCamelCase };
|
|
93
|
+
export { assignDataPath, cloneCommittedValue, cloneValue, coerceValue, hyphenate, parseDataPath, resolveDataPath, toCamelCase };
|
|
74
94
|
//# sourceMappingURL=utils.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.mjs","names":[],"sources":["../../../src/runtime/component/utils.ts"],"sourcesContent":["import type { PropertyOption } from './types'\n\nconst ARRAY_INDEX_PATH_RE = /\\[(\\d+)\\]/g\nconst ARRAY_INDEX_SEGMENT_RE = /^\\d+$/\nconst UNSAFE_PATH_SEGMENTS = new Set(['__proto__', 'constructor', 'prototype'])\n\nexport function hyphenate(name: string) {\n return name.replace(/([A-Z])/g, (_, char: string) => `-${char.toLowerCase()}`)\n}\n\nexport function toCamelCase(name: string) {\n return name.replace(/-([a-z])/g, (_, char: string) => char.toUpperCase())\n}\n\nexport function cloneValue(value: any) {\n if (Array.isArray(value)) {\n return value.slice()\n }\n if (value && typeof value === 'object') {\n return { ...value }\n }\n return value\n}\n\nexport function parseDataPath(path: string) {\n return path\n .replace(ARRAY_INDEX_PATH_RE, '.$1')\n .split('.')\n .map(segment => segment.trim())\n .filter(segment => segment && !UNSAFE_PATH_SEGMENTS.has(segment))\n}\n\nfunction normalizePathSegment(segment: string) {\n return ARRAY_INDEX_SEGMENT_RE.test(segment) ? Number(segment) : segment\n}\n\nfunction createPathContainer(nextSegment: string | undefined) {\n return nextSegment && ARRAY_INDEX_SEGMENT_RE.test(nextSegment) ? [] : {}\n}\n\nexport function resolveDataPath(target: Record<string, any>, segments: string[]) {\n let current: any = target\n for (const segment of segments) {\n if (current == null) {\n return undefined\n }\n current = current[normalizePathSegment(segment)]\n }\n return current\n}\n\nexport function assignDataPath(target: Record<string, any>, segments: string[], value: unknown) {\n if (!segments.length) {\n return\n }\n let current: any = target\n for (let index = 0; index < segments.length - 1; index += 1) {\n const segment = normalizePathSegment(segments[index]!)\n const nextSegment = segments[index + 1]\n
|
|
1
|
+
{"version":3,"file":"utils.mjs","names":[],"sources":["../../../src/runtime/component/utils.ts"],"sourcesContent":["import type { PropertyOption } from './types'\n\nconst ARRAY_INDEX_PATH_RE = /\\[(\\d+)\\]/g\nconst ARRAY_INDEX_SEGMENT_RE = /^\\d+$/\nconst UNSAFE_PATH_SEGMENTS = new Set(['__proto__', 'constructor', 'prototype'])\n\nexport function hyphenate(name: string) {\n return name.replace(/([A-Z])/g, (_, char: string) => `-${char.toLowerCase()}`)\n}\n\nexport function toCamelCase(name: string) {\n return name.replace(/-([a-z])/g, (_, char: string) => char.toUpperCase())\n}\n\nexport function cloneValue(value: any) {\n if (Array.isArray(value)) {\n return value.slice()\n }\n if (value && typeof value === 'object') {\n return { ...value }\n }\n return value\n}\n\nexport function cloneCommittedValue(value: unknown, snapshots = new WeakMap<object, Record<string, unknown>>()): unknown {\n if (value === null || typeof value !== 'object') {\n return value\n }\n if (!Array.isArray(value)) {\n const prototype = Object.getPrototypeOf(value)\n if (prototype !== Object.prototype && prototype !== null) {\n return value\n }\n }\n const existing = snapshots.get(value)\n if (existing) {\n return existing\n }\n const snapshot: Record<string, unknown> = cloneValue(value)\n snapshots.set(value, snapshot)\n for (const key of Object.keys(snapshot)) {\n snapshot[key] = cloneCommittedValue(snapshot[key], snapshots)\n }\n return snapshot\n}\n\nexport function parseDataPath(path: string) {\n return path\n .replace(ARRAY_INDEX_PATH_RE, '.$1')\n .split('.')\n .map(segment => segment.trim())\n .filter(segment => segment && !UNSAFE_PATH_SEGMENTS.has(segment))\n}\n\nfunction normalizePathSegment(segment: string) {\n return ARRAY_INDEX_SEGMENT_RE.test(segment) ? Number(segment) : segment\n}\n\nfunction createPathContainer(nextSegment: string | undefined) {\n return nextSegment && ARRAY_INDEX_SEGMENT_RE.test(nextSegment) ? [] : {}\n}\n\nexport function resolveDataPath(target: Record<string, any>, segments: string[]) {\n let current: any = target\n for (const segment of segments) {\n if (current == null) {\n return undefined\n }\n current = current[normalizePathSegment(segment)]\n }\n return current\n}\n\nexport function assignDataPath(target: Record<string, any>, segments: string[], value: unknown, copiedContainers?: WeakSet<object>) {\n if (!segments.length) {\n return\n }\n let current: any = target\n for (let index = 0; index < segments.length - 1; index += 1) {\n const segment = normalizePathSegment(segments[index]!)\n const nextSegment = segments[index + 1]\n const next = current[segment]\n if (next == null || typeof next !== 'object') {\n current[segment] = createPathContainer(nextSegment)\n copiedContainers?.add(current[segment])\n }\n else if (!copiedContainers?.has(next)) {\n // 保留已传给子组件的输入快照,每批只复制一次变更路径上的容器。\n current[segment] = cloneValue(next)\n copiedContainers?.add(current[segment])\n }\n current = current[segment]\n }\n current[normalizePathSegment(segments[segments.length - 1]!)] = value\n}\n\nexport function coerceValue(value: any, type?: PropertyOption['type']) {\n if (type === Boolean) {\n if (value === '' || value === true) {\n return true\n }\n if (value === undefined || value === null || value === false) {\n return false\n }\n if (typeof value === 'string') {\n return value !== 'false'\n }\n return Boolean(value)\n }\n\n if (type === Number) {\n if (value === undefined || value === null) {\n return value\n }\n const numeric = Number(value)\n return Number.isNaN(numeric) ? value : numeric\n }\n\n if (type === Object || type === Array) {\n if (value === undefined || value === null) {\n return value\n }\n if (typeof value === 'string') {\n try {\n return JSON.parse(value)\n }\n catch {\n return value\n }\n }\n return value\n }\n\n return value\n}\n"],"mappings":";AAEA,MAAM,sBAAsB;AAC5B,MAAM,yBAAyB;AAC/B,MAAM,uCAAuB,IAAI,IAAI;CAAC;CAAa;CAAe;AAAW,CAAC;AAE9E,SAAgB,UAAU,MAAc;CACtC,OAAO,KAAK,QAAQ,aAAa,GAAG,SAAiB,IAAI,KAAK,YAAY,GAAG;AAC/E;AAEA,SAAgB,YAAY,MAAc;CACxC,OAAO,KAAK,QAAQ,cAAc,GAAG,SAAiB,KAAK,YAAY,CAAC;AAC1E;AAEA,SAAgB,WAAW,OAAY;CACrC,IAAI,MAAM,QAAQ,KAAK,GACrB,OAAO,MAAM,MAAM;CAErB,IAAI,SAAS,OAAO,UAAU,UAC5B,OAAO,EAAE,GAAG,MAAM;CAEpB,OAAO;AACT;AAEA,SAAgB,oBAAoB,OAAgB,4BAAY,IAAI,QAAyC,GAAY;CACvH,IAAI,UAAU,QAAQ,OAAO,UAAU,UACrC,OAAO;CAET,IAAI,CAAC,MAAM,QAAQ,KAAK,GAAG;EACzB,MAAM,YAAY,OAAO,eAAe,KAAK;EAC7C,IAAI,cAAc,OAAO,aAAa,cAAc,MAClD,OAAO;CAEX;CACA,MAAM,WAAW,UAAU,IAAI,KAAK;CACpC,IAAI,UACF,OAAO;CAET,MAAM,WAAoC,WAAW,KAAK;CAC1D,UAAU,IAAI,OAAO,QAAQ;CAC7B,KAAK,MAAM,OAAO,OAAO,KAAK,QAAQ,GACpC,SAAS,OAAO,oBAAoB,SAAS,MAAM,SAAS;CAE9D,OAAO;AACT;AAEA,SAAgB,cAAc,MAAc;CAC1C,OAAO,KACJ,QAAQ,qBAAqB,KAAK,CAAC,CACnC,MAAM,GAAG,CAAC,CACV,KAAI,YAAW,QAAQ,KAAK,CAAC,CAAC,CAC9B,QAAO,YAAW,W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B,IAAI,UAAU,UAAa,UAAU,MACnC,OAAO;EAET,MAAM,UAAU,OAAO,KAAK;EAC5B,OAAO,OAAO,MAAM,OAAO,IAAI,QAAQ;CACzC;CAEA,IAAI,SAAS,UAAU,SAAS,OAAO;EACrC,IAAI,UAAU,UAAa,UAAU,MACnC,OAAO;EAET,IAAI,OAAO,UAAU,UACnB,IAAI;GACF,OAAO,KAAK,MAAM,KAAK;EACzB,QACM;GACJ,OAAO;EACT;EAEF,OAAO;CACT;CAEA,OAAO;AACT"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { EVENT_KIND_ALIAS } from "../shared/wxml.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/runtime/componentEvents.ts
|
|
4
|
+
const componentElements = /* @__PURE__ */ new WeakSet();
|
|
5
|
+
const componentEvents = /* @__PURE__ */ new WeakSet();
|
|
6
|
+
const handlerNames = /* @__PURE__ */ new WeakMap();
|
|
7
|
+
function registerComponentEventTarget(element) {
|
|
8
|
+
componentElements.add(element);
|
|
9
|
+
}
|
|
10
|
+
function markComponentEvent(event) {
|
|
11
|
+
componentEvents.add(event);
|
|
12
|
+
return event;
|
|
13
|
+
}
|
|
14
|
+
function nameRuntimeEventHandler(listener, name) {
|
|
15
|
+
handlerNames.set(listener, name);
|
|
16
|
+
return listener;
|
|
17
|
+
}
|
|
18
|
+
/** 保留 DOM 事件的冒泡行为,仅在框架监听入口区分组件 emit 与浏览器原生事件。 */
|
|
19
|
+
function listenRuntimeEvent(element, name, listener, capture = false) {
|
|
20
|
+
const logicalName = handlerNames.get(listener) ?? name;
|
|
21
|
+
const nativeAlias = EVENT_KIND_ALIAS[logicalName];
|
|
22
|
+
const eventNames = /* @__PURE__ */ new Set([nativeAlias ?? name, logicalName]);
|
|
23
|
+
const dispatch = (event) => {
|
|
24
|
+
if (componentEvents.has(event)) {
|
|
25
|
+
if (event.type !== logicalName) return;
|
|
26
|
+
} else if (componentElements.has(element) && !nativeAlias) return;
|
|
27
|
+
listener.call(element, event);
|
|
28
|
+
};
|
|
29
|
+
for (const eventName of eventNames) element.addEventListener(eventName, dispatch, capture);
|
|
30
|
+
return () => {
|
|
31
|
+
for (const eventName of eventNames) element.removeEventListener(eventName, dispatch, capture);
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
//#endregion
|
|
36
|
+
export { listenRuntimeEvent, markComponentEvent, nameRuntimeEventHandler, registerComponentEventTarget };
|
|
37
|
+
//# sourceMappingURL=componentEvents.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"componentEvents.mjs","names":[],"sources":["../../src/runtime/componentEvents.ts"],"sourcesContent":["import { EVENT_KIND_ALIAS } from '../shared/wxml'\n\nconst componentElements = new WeakSet<Element>()\nconst componentEvents = new WeakSet<Event>()\nconst handlerNames = new WeakMap<EventListener, string>()\n\nexport function registerComponentEventTarget(element: Element) {\n componentElements.add(element)\n}\n\nexport function markComponentEvent<T extends Event>(event: T): T {\n componentEvents.add(event)\n return event\n}\n\nexport function nameRuntimeEventHandler(listener: EventListener, name: string) {\n handlerNames.set(listener, name)\n return listener\n}\n\n/** 保留 DOM 事件的冒泡行为,仅在框架监听入口区分组件 emit 与浏览器原生事件。 */\nexport function listenRuntimeEvent(element: Element, name: string, listener: EventListener, capture = false) {\n const logicalName = handlerNames.get(listener) ?? name\n const nativeAlias = EVENT_KIND_ALIAS[logicalName]\n const eventNames = new Set([nativeAlias ?? name, logicalName])\n const dispatch: EventListener = (event) => {\n if (componentEvents.has(event)) {\n if (event.type !== logicalName) {\n return\n }\n }\n else if (componentElements.has(element) && !nativeAlias) {\n return\n }\n listener.call(element, event)\n }\n for (const eventName of eventNames) {\n element.addEventListener(eventName, dispatch, capture)\n }\n return () => {\n for (const eventName of eventNames) {\n element.removeEventListener(eventName, dispatch, capture)\n }\n }\n}\n"],"mappings":";;;AAEA,MAAM,oCAAoB,IAAI,QAAiB;AAC/C,MAAM,kCAAkB,IAAI,QAAe;AAC3C,MAAM,+BAAe,IAAI,QAA+B;AAExD,SAAgB,6BAA6B,SAAkB;CAC7D,kBAAkB,IAAI,OAAO;AAC/B;AAEA,SAAgB,mBAAoC,OAAa;CAC/D,gBAAgB,IAAI,KAAK;CACzB,OAAO;AACT;AAEA,SAAgB,wBAAwB,UAAyB,MAAc;CAC7E,aAAa,IAAI,UAAU,IAAI;CAC/B,OAAO;AACT;;AAGA,SAAgB,mBAAmB,SAAkB,MAAc,UAAyB,UAAU,OAAO;CAC3G,MAAM,cAAc,aAAa,IAAI,QAAQ,KAAK;CAClD,MAAM,cAAc,iBAAiB;CACrC,MAAM,6BAAa,IAAI,IAAI,CAAC,eAAe,MAAM,WAAW,CAAC;CAC7D,MAAM,YAA2B,UAAU;EACzC,IAAI,gBAAgB,IAAI,KAAK,GAC3B;OAAI,MAAM,SAAS,aACjB;EACF,OAEG,IAAI,kBAAkB,IAAI,OAAO,KAAK,CAAC,aAC1C;EAEF,SAAS,KAAK,SAAS,KAAK;CAC9B;CACA,KAAK,MAAM,aAAa,YACtB,QAAQ,iBAAiB,WAAW,UAAU,OAAO;CAEvD,aAAa;EACX,KAAK,MAAM,aAAa,YACtB,QAAQ,oBAAoB,WAAW,UAAU,OAAO;CAE5D;AACF"}
|
|
@@ -13,4 +13,5 @@ declare class RuntimeEventBindingDirective extends AsyncDirective {
|
|
|
13
13
|
}
|
|
14
14
|
export declare const bindRuntimeEvent: (_eventName: string, _listener: EventListener, _flags?: RuntimeEventFlags | undefined) => import("lit/async-directive.js").DirectiveResult<typeof RuntimeEventBindingDirective>;
|
|
15
15
|
//#endregion
|
|
16
|
+
export {};
|
|
16
17
|
//# sourceMappingURL=eventBinding.d.mts.map
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { listenRuntimeEvent } from "./componentEvents.mjs";
|
|
1
2
|
import { nothing } from "lit";
|
|
2
3
|
import { AsyncDirective, PartType, directive } from "lit/async-directive.js";
|
|
3
4
|
|
|
@@ -8,6 +9,7 @@ var RuntimeEventBindingDirective = class extends AsyncDirective {
|
|
|
8
9
|
#eventName;
|
|
9
10
|
#listener;
|
|
10
11
|
#listening = false;
|
|
12
|
+
#dispose;
|
|
11
13
|
constructor(partInfo) {
|
|
12
14
|
super(partInfo);
|
|
13
15
|
if (partInfo.type !== PartType.ELEMENT) throw new TypeError("Runtime event bindings must be used in an element expression.");
|
|
@@ -35,12 +37,13 @@ var RuntimeEventBindingDirective = class extends AsyncDirective {
|
|
|
35
37
|
}
|
|
36
38
|
#addListener() {
|
|
37
39
|
if (!this.isConnected || this.#listening || !this.#element || !this.#eventName || !this.#listener) return;
|
|
38
|
-
this.#
|
|
40
|
+
this.#dispose = listenRuntimeEvent(this.#element, this.#eventName, this.#listener, this.#capture);
|
|
39
41
|
this.#listening = true;
|
|
40
42
|
}
|
|
41
43
|
#removeListener() {
|
|
42
44
|
if (!this.#listening || !this.#element || !this.#eventName || !this.#listener) return;
|
|
43
|
-
this.#
|
|
45
|
+
this.#dispose?.();
|
|
46
|
+
this.#dispose = void 0;
|
|
44
47
|
this.#listening = false;
|
|
45
48
|
}
|
|
46
49
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eventBinding.mjs","names":[],"sources":["../../src/runtime/eventBinding.ts"],"sourcesContent":["import type { ElementPart, PartInfo } from 'lit/async-directive.js'\nimport { nothing } from 'lit'\nimport { AsyncDirective, directive, PartType } from 'lit/async-directive.js'\n\ninterface RuntimeEventFlags {\n capture?: boolean\n}\n\nclass RuntimeEventBindingDirective extends AsyncDirective {\n #capture = false\n #element?: Element\n #eventName?: string\n #listener?: EventListener\n #listening = false\n\n constructor(partInfo: PartInfo) {\n super(partInfo)\n if (partInfo.type !== PartType.ELEMENT) {\n throw new TypeError('Runtime event bindings must be used in an element expression.')\n }\n }\n\n render(_eventName: string, _listener: EventListener, _flags?: RuntimeEventFlags) {\n return nothing\n }\n\n update(\n part: ElementPart,\n [eventName, listener, flags]: Parameters<this['render']>,\n ) {\n const capture = Boolean(flags?.capture)\n if (\n part.element !== this.#element\n || eventName !== this.#eventName\n || listener !== this.#listener\n || capture !== this.#capture\n ) {\n this.#removeListener()\n this.#element = part.element\n this.#eventName = eventName\n this.#listener = listener\n this.#capture = capture\n this.#addListener()\n }\n return nothing\n }\n\n protected disconnected() {\n this.#removeListener()\n }\n\n protected reconnected() {\n this.#addListener()\n }\n\n #addListener() {\n if (!this.isConnected || this.#listening || !this.#element || !this.#eventName || !this.#listener) {\n return\n }\n this.#
|
|
1
|
+
{"version":3,"file":"eventBinding.mjs","names":[],"sources":["../../src/runtime/eventBinding.ts"],"sourcesContent":["import type { ElementPart, PartInfo } from 'lit/async-directive.js'\nimport { nothing } from 'lit'\nimport { AsyncDirective, directive, PartType } from 'lit/async-directive.js'\nimport { listenRuntimeEvent } from './componentEvents'\n\ninterface RuntimeEventFlags {\n capture?: boolean\n}\n\nclass RuntimeEventBindingDirective extends AsyncDirective {\n #capture = false\n #element?: Element\n #eventName?: string\n #listener?: EventListener\n #listening = false\n #dispose?: () => void\n\n constructor(partInfo: PartInfo) {\n super(partInfo)\n if (partInfo.type !== PartType.ELEMENT) {\n throw new TypeError('Runtime event bindings must be used in an element expression.')\n }\n }\n\n render(_eventName: string, _listener: EventListener, _flags?: RuntimeEventFlags) {\n return nothing\n }\n\n update(\n part: ElementPart,\n [eventName, listener, flags]: Parameters<this['render']>,\n ) {\n const capture = Boolean(flags?.capture)\n if (\n part.element !== this.#element\n || eventName !== this.#eventName\n || listener !== this.#listener\n || capture !== this.#capture\n ) {\n this.#removeListener()\n this.#element = part.element\n this.#eventName = eventName\n this.#listener = listener\n this.#capture = capture\n this.#addListener()\n }\n return nothing\n }\n\n protected disconnected() {\n this.#removeListener()\n }\n\n protected reconnected() {\n this.#addListener()\n }\n\n #addListener() {\n if (!this.isConnected || this.#listening || !this.#element || !this.#eventName || !this.#listener) {\n return\n }\n this.#dispose = listenRuntimeEvent(this.#element, this.#eventName, this.#listener, this.#capture)\n this.#listening = true\n }\n\n #removeListener() {\n if (!this.#listening || !this.#element || !this.#eventName || !this.#listener) {\n return\n }\n this.#dispose?.()\n this.#dispose = undefined\n this.#listening = false\n }\n}\n\nexport const bindRuntimeEvent = directive(RuntimeEventBindingDirective)\n"],"mappings":";;;;;AASA,IAAM,+BAAN,cAA2C,eAAe;CACxD,WAAW;CACX;CACA;CACA;CACA,aAAa;CACb;CAEA,YAAY,UAAoB;EAC9B,MAAM,QAAQ;EACd,IAAI,SAAS,SAAS,SAAS,SAC7B,MAAM,IAAI,UAAU,+DAA+D;CAEvF;CAEA,OAAO,YAAoB,WAA0B,QAA4B;EAC/E,OAAO;CACT;CAEA,OACE,MACA,CAAC,WAAW,UAAU,QACtB;EACA,MAAM,UAAU,QAAQ,OAAO,OAAO;EACtC,IACE,KAAK,YAAY,KAAK,YACnB,cAAc,KAAK,cACnB,aAAa,KAAK,aAClB,YAAY,KAAK,UACpB;GACA,KAAK,gBAAgB;GACrB,KAAK,WAAW,KAAK;GACrB,KAAK,aAAa;GAClB,KAAK,YAAY;GACjB,KAAK,WAAW;GAChB,KAAK,aAAa;EACpB;EACA,OAAO;CACT;CAEA,AAAU,eAAe;EACvB,KAAK,gBAAgB;CACvB;CAEA,AAAU,cAAc;EACtB,KAAK,aAAa;CACpB;CAEA,eAAe;EACb,IAAI,CAAC,KAAK,eAAe,KAAK,cAAc,CAAC,KAAK,YAAY,CAAC,KAAK,cAAc,CAAC,KAAK,WACtF;EAEF,KAAK,WAAW,mBAAmB,KAAK,UAAU,KAAK,YAAY,KAAK,WAAW,KAAK,QAAQ;EAChG,KAAK,aAAa;CACpB;CAEA,kBAAkB;EAChB,IAAI,CAAC,KAAK,cAAc,CAAC,KAAK,YAAY,CAAC,KAAK,cAAc,CAAC,KAAK,WAClE;EAEF,KAAK,WAAW;EAChB,KAAK,WAAW;EAChB,KAAK,aAAa;CACpB;AACF;AAEA,MAAa,mBAAmB,UAAU,4BAA4B"}
|
|
@@ -1,14 +1,9 @@
|
|
|
1
|
-
import { CONTROL_ATTRS, hasControlAttribute, normalizeAttributeName, resolveControlAttributeValue } from "../../shared/wxml.mjs";
|
|
1
|
+
import { CONTROL_ATTRS, EVENT_KIND_ALIAS, hasControlAttribute, normalizeAttributeName, resolveControlAttributeValue } from "../../shared/wxml.mjs";
|
|
2
2
|
import { MINI_PROGRAM_EVENT_ATTRIBUTE_PREFIX, MINI_PROGRAM_EVENT_FLAG_ATTRIBUTE_PREFIX, encodeEventAttributeName } from "../component/constants.mjs";
|
|
3
3
|
import { escapeAttribute, resolveAttributeValue } from "./expression.mjs";
|
|
4
4
|
|
|
5
5
|
//#region src/runtime/legacyTemplate/dom.ts
|
|
6
6
|
const EVENT_PREFIX_RE = /^(bind|catch|mut-bind|capture-bind|capture-catch)([\w-]+)$/;
|
|
7
|
-
const EVENT_KIND_ALIAS = {
|
|
8
|
-
tap: "click",
|
|
9
|
-
longtap: "contextmenu",
|
|
10
|
-
longpress: "contextmenu"
|
|
11
|
-
};
|
|
12
7
|
const EVENT_PREFIX_FLAGS = {
|
|
13
8
|
"bind": {},
|
|
14
9
|
"catch": { catch: true },
|
|
@@ -61,7 +56,7 @@ function buildAttributeString(attribs, scope) {
|
|
|
61
56
|
const eventInfo = parseEventAttribute(name);
|
|
62
57
|
if (eventInfo) {
|
|
63
58
|
const normalizedEvent = eventInfo.rawEvent.toLowerCase();
|
|
64
|
-
const runtimeEvent = EVENT_KIND_ALIAS[normalizedEvent]
|
|
59
|
+
const runtimeEvent = EVENT_KIND_ALIAS[normalizedEvent] ? normalizedEvent : eventInfo.rawEvent;
|
|
65
60
|
const encodedEvent = encodeEventAttributeName(runtimeEvent);
|
|
66
61
|
const handlerName = resolveAttributeValue(rawValue, scope).trim();
|
|
67
62
|
if (!handlerName) continue;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dom.mjs","names":[],"sources":["../../../src/runtime/legacyTemplate/dom.ts"],"sourcesContent":["import type { Element, Node } from 'domhandler'\nimport type { ExtractForResult, LegacyTemplateScope } from './types'\nimport {\n CONTROL_ATTRS,\n hasControlAttribute,\n normalizeAttributeName,\n resolveControlAttributeValue,\n} from '../../shared/wxml'\nimport {\n encodeEventAttributeName,\n MINI_PROGRAM_EVENT_ATTRIBUTE_PREFIX,\n MINI_PROGRAM_EVENT_FLAG_ATTRIBUTE_PREFIX,\n} from '../component/constants'\nimport { escapeAttribute, resolveAttributeValue } from './expression'\n\nconst EVENT_PREFIX_RE = /^(bind|catch|mut-bind|capture-bind|capture-catch)([\\w-]+)$/\nconst
|
|
1
|
+
{"version":3,"file":"dom.mjs","names":[],"sources":["../../../src/runtime/legacyTemplate/dom.ts"],"sourcesContent":["import type { Element, Node } from 'domhandler'\nimport type { ExtractForResult, LegacyTemplateScope } from './types'\nimport {\n CONTROL_ATTRS,\n EVENT_KIND_ALIAS,\n hasControlAttribute,\n normalizeAttributeName,\n resolveControlAttributeValue,\n} from '../../shared/wxml'\nimport {\n encodeEventAttributeName,\n MINI_PROGRAM_EVENT_ATTRIBUTE_PREFIX,\n MINI_PROGRAM_EVENT_FLAG_ATTRIBUTE_PREFIX,\n} from '../component/constants'\nimport { escapeAttribute, resolveAttributeValue } from './expression'\n\nconst EVENT_PREFIX_RE = /^(bind|catch|mut-bind|capture-bind|capture-catch)([\\w-]+)$/\nconst EVENT_PREFIX_FLAGS: Record<string, { catch?: boolean, capture?: boolean }> = {\n 'bind': {},\n 'catch': { catch: true },\n 'mut-bind': {},\n 'capture-bind': { capture: true },\n 'capture-catch': { capture: true, catch: true },\n}\n\nfunction parseEventAttribute(name: string) {\n const separatorIndex = name.indexOf(':')\n if (separatorIndex >= 0) {\n const prefix = name.slice(0, separatorIndex)\n const rawEvent = name.slice(separatorIndex + 1)\n if (rawEvent && prefix in EVENT_PREFIX_FLAGS) {\n return { prefix, rawEvent }\n }\n return undefined\n }\n const match = EVENT_PREFIX_RE.exec(name)\n if (!match) {\n return undefined\n }\n return { prefix: match[1]!, rawEvent: match[2]! }\n}\n\nexport function extractFor(attribs: Record<string, string>): ExtractForResult {\n const expr = resolveControlAttributeValue(attribs, 'for')\n const restAttribs: Record<string, string> = {}\n const itemName = resolveControlAttributeValue(attribs, 'for-item')?.trim() || 'item'\n let indexName = resolveControlAttributeValue(attribs, 'for-index')?.trim() || 'index'\n\n for (const [key, val] of Object.entries(attribs)) {\n if (CONTROL_ATTRS.has(key)) {\n continue\n }\n restAttribs[key] = val\n }\n\n if (itemName === indexName) {\n indexName = `${indexName}Index`\n }\n\n return {\n expr,\n itemName,\n indexName,\n restAttribs,\n }\n}\n\nexport function buildAttributeString(\n attribs: Record<string, string>,\n scope: LegacyTemplateScope,\n) {\n let result = ''\n for (const [name, rawValue] of Object.entries(attribs)) {\n if (CONTROL_ATTRS.has(name)) {\n continue\n }\n\n const eventInfo = parseEventAttribute(name)\n if (eventInfo) {\n const normalizedEvent = eventInfo.rawEvent.toLowerCase()\n const aliasedEvent = EVENT_KIND_ALIAS[normalizedEvent]\n const runtimeEvent = aliasedEvent ? normalizedEvent : eventInfo.rawEvent\n const encodedEvent = encodeEventAttributeName(runtimeEvent)\n const handlerName = resolveAttributeValue(rawValue, scope).trim()\n if (!handlerName) {\n continue\n }\n const flags = EVENT_PREFIX_FLAGS[eventInfo.prefix]!\n result += ` ${MINI_PROGRAM_EVENT_ATTRIBUTE_PREFIX}${encodedEvent}=\"${escapeAttribute(handlerName)}\"`\n const flagTokens = [\n flags.capture ? 'capture' : '',\n flags.catch ? 'catch' : '',\n ].filter(Boolean)\n if (flagTokens.length) {\n result += ` ${MINI_PROGRAM_EVENT_FLAG_ATTRIBUTE_PREFIX}${encodedEvent}=\"${flagTokens.join(',')}\"`\n }\n continue\n }\n\n const value = resolveAttributeValue(rawValue, scope)\n if (value === '') {\n continue\n }\n const normalizedName = normalizeAttributeName(name)\n result += ` ${normalizedName}=\"${escapeAttribute(value)}\"`\n }\n return result\n}\n\nexport function stripControlAttributes(attribs: Record<string, string>) {\n const result: Record<string, string> = {}\n for (const [name, value] of Object.entries(attribs)) {\n if (!CONTROL_ATTRS.has(name)) {\n result[name] = value\n }\n }\n return result\n}\n\nexport function isConditionalElement(node: Node): node is Element {\n if (node.type !== 'tag') {\n return false\n }\n const attribs = (node as Element).attribs\n return hasControlAttribute(attribs, 'if')\n || hasControlAttribute(attribs, 'elif')\n || hasControlAttribute(attribs, 'else')\n}\n"],"mappings":";;;;;AAgBA,MAAM,kBAAkB;AACxB,MAAM,qBAA6E;CACjF,QAAQ,CAAC;CACT,SAAS,EAAE,OAAO,KAAK;CACvB,YAAY,CAAC;CACb,gBAAgB,EAAE,SAAS,KAAK;CAChC,iBAAiB;EAAE,SAAS;EAAM,OAAO;CAAK;AAChD;AAEA,SAAS,oBAAoB,MAAc;CACzC,MAAM,iBAAiB,KAAK,QAAQ,GAAG;CACvC,IAAI,kBAAkB,GAAG;EACvB,MAAM,SAAS,KAAK,MAAM,GAAG,cAAc;EAC3C,MAAM,WAAW,KAAK,MAAM,iBAAiB,CAAC;EAC9C,IAAI,YAAY,UAAU,oBACxB,OAAO;GAAE;GAAQ;EAAS;EAE5B;CACF;CACA,MAAM,QAAQ,gBAAgB,KAAK,IAAI;CACvC,IAAI,CAAC,OACH;CAEF,OAAO;EAAE,QAAQ,MAAM;EAAK,UAAU,MAAM;CAAI;AAClD;AAEA,SAAgB,WAAW,SAAmD;CAC5E,MAAM,OAAO,6BAA6B,SAAS,KAAK;CACxD,MAAM,cAAsC,CAAC;CAC7C,MAAM,WAAW,6BAA6B,SAAS,UAAU,CAAC,EAAE,KAAK,KAAK;CAC9E,IAAI,YAAY,6BAA6B,SAAS,WAAW,CAAC,EAAE,KAAK,KAAK;CAE9E,KAAK,MAAM,CAAC,KAAK,QAAQ,OAAO,QAAQ,OAAO,GAAG;EAChD,IAAI,cAAc,IAAI,GAAG,GACvB;EAEF,YAAY,OAAO;CACrB;CAEA,IAAI,aAAa,WACf,YAAY,GAAG,UAAU;CAG3B,OAAO;EACL;EACA;EACA;EACA;CACF;AACF;AAEA,SAAgB,qBACd,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