@leafer-in/state 1.8.0 → 1.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/state.cjs +187 -167
- package/dist/state.esm.js +185 -166
- package/dist/state.esm.min.js +1 -1
- package/dist/state.esm.min.js.map +1 -1
- package/dist/state.js +140 -178
- package/dist/state.min.cjs +1 -1
- package/dist/state.min.cjs.map +1 -1
- package/dist/state.min.js +1 -1
- package/dist/state.min.js.map +1 -1
- package/package.json +4 -4
- package/src/set.ts +2 -2
- package/src/style.ts +3 -3
- package/src/unset.ts +2 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state.esm.min.js","sources":["../../../../../../src/in/packages/state/src/decorator.ts","../../../../../../src/in/packages/state/src/helper.ts","../../../../../../src/in/packages/state/src/style.ts","../../../../../../src/in/packages/state/src/set.ts","../../../../../../src/in/packages/state/src/unset.ts","../../../../../../src/in/packages/state/src/check.ts","../../../../../../src/in/packages/state/src/index.ts","../../../../../../src/in/packages/state/src/event.ts"],"sourcesContent":["import { IValue } from '@leafer-ui/interface'\nimport { decorateLeafAttr, attr, State } from '@leafer-ui/core'\n\nexport function stateType(defaultValue?: IValue, styleName?: string) {\n return decorateLeafAttr(defaultValue, (key: string) => attr({\n set(value: any) {\n this.__setAttr(key, value)\n if (this.leaferIsReady) styleName ? State.setStyleName(this, styleName, value) : State.set(this, value)\n else this.__layout.stateStyleChanged = true\n }\n }))\n}\n\nexport function stateStyleType(defaultValue?: IValue) {\n return decorateLeafAttr(defaultValue, (key: string) => attr({\n set(value: any) {\n this.__setAttr(key, value)\n this.__layout.stateStyleChanged = true\n }\n }))\n}","import { IUI } from '@leafer-ui/interface'\n\n\nexport function findParentButton(leaf: IUI, button?: IUI | boolean): IUI {\n if (button && button !== true) return button\n if (!leaf.button) {\n let { parent } = leaf\n for (let i = 0; i < 2; i++) {\n if (parent) {\n if (parent.button) return parent\n parent = parent.parent\n }\n }\n }\n return null\n}","import { IUI, IObject, IUIInputData, IStateStyle, IScaleData, ITransition } from '@leafer-ui/interface'\nimport { State, MathHelper, isNull } from '@leafer-ui/core'\n\nimport { findParentButton } from './helper'\n\n\nexport function setStyle(leaf: IUI, style: IStateStyle): void {\n if (typeof style !== 'object') style = undefined\n updateStyle(leaf, style, 'in')\n}\n\nexport function unsetStyle(leaf: IUI, style?: IStateStyle): void {\n const { normalStyle } = leaf\n if (typeof style !== 'object') style = undefined\n if (normalStyle) {\n if (!style) style = normalStyle\n updateStyle(leaf, style, 'out')\n }\n}\n\nconst emprtyStyle = {}\n\nexport function updateStyle(leaf: IUI, style?: IStateStyle, type?: 'in' | 'out'): void {\n const { normalStyle } = leaf\n\n if (!style) style = emprtyStyle\n\n if (style.scale) {\n MathHelper.assignScale(style as IScaleData, style.scale)\n delete style.scale\n }\n\n if (style === emprtyStyle || !State.canAnimate) type = null\n let transition = type ? getTransition(type, style, leaf) : false\n const fromStyle = transition ? getFromStyle(leaf, style) : undefined\n\n // 回到正常状态\n const nextStyle = State.canAnimate && getStyle(leaf)\n if (nextStyle) leaf.killAnimate('transition')\n if (normalStyle) leaf.set(normalStyle, 'temp')\n\n\n const statesStyle = getStyle(leaf) // 必须在回到正常状态之后获取\n if (statesStyle) {\n\n const { animation } = statesStyle\n if (animation) {\n const animate = leaf.animate(animation, undefined, 'animation', true)\n Object.assign(statesStyle, animate.endingStyle) // 加上最终的动画样式\n\n if (type !== 'in' || style.animation !== animation) animate.kill()\n else transition = false\n\n delete statesStyle.animation\n }\n\n\n leaf.normalStyle = filterStyle(statesStyle, leaf)\n leaf.set(statesStyle, 'temp')\n } else {\n leaf.normalStyle = undefined\n }\n\n if (transition) {\n const toStyle = filterStyle(fromStyle, leaf)\n leaf.set(fromStyle, 'temp')\n leaf.animate([fromStyle, toStyle], transition, 'transition', true)\n }\n\n leaf.__layout.stateStyleChanged = false\n}\n\nexport function getStyle(leaf: IUI): IStateStyle {\n\n // 从低到高依次覆盖: states < selected < placeholder < focus < hover < press < disabled\n\n let exist: boolean\n const style: IUIInputData = {}, button = findParentButton(leaf)\n const state = button ? (leaf.state || button.state) : leaf.state\n\n const stateStyle = state && leaf.states[state]\n if (stateStyle && State.isState(state, leaf, button)) exist = assign(style, stateStyle)\n\n const selectedStyle = style.selectedStyle || leaf.selectedStyle\n if (selectedStyle && State.isSelected(leaf, button)) exist = assign(style, selectedStyle)\n\n const placeholderStyle = style.placeholderStyle || leaf.placeholderStyle\n if (placeholderStyle && State.isPlacehold(leaf, button)) exist = assign(style, placeholderStyle)\n\n if (State.isDisabled(leaf, button)) {\n\n const disabledStyle = style.disabledStyle || leaf.disabledStyle\n if (disabledStyle) exist = assign(style, disabledStyle)\n\n } else {\n\n const focusStyle = style.focusStyle || leaf.focusStyle\n if (focusStyle && State.isFocus(leaf, button)) exist = assign(style, focusStyle)\n\n const hoverStyle = style.hoverStyle || leaf.hoverStyle\n if (hoverStyle && State.isHover(leaf, button)) exist = assign(style, hoverStyle)\n\n const pressStyle = style.pressStyle || leaf.pressStyle\n if (pressStyle && State.isPress(leaf, button)) exist = assign(style, pressStyle)\n\n }\n\n return exist ? style : undefined\n}\n\n\nfunction filterStyle(style: IObject, data: IObject, addStyle?: IObject, useAnimateExcludes?: boolean): IObject {\n const to: IObject = addStyle ? style : {}, forStyle = addStyle || style\n for (let key in forStyle) {\n if (useAnimateExcludes) {\n if (!State.animateExcludes[key]) to[key] = data[key]\n } else to[key] = data[key]\n }\n return to\n}\n\nfunction filterAnimateStyle(style: IObject, data: IObject, addStyle?: IObject): IObject {\n return filterStyle(style, data, addStyle, true)\n}\n\nfunction getFromStyle(leaf: IUI, style: IObject): IObject {\n const fromStyle = filterAnimateStyle(style, leaf), animate = leaf.animate()\n if (animate) filterAnimateStyle(fromStyle, leaf, animate.fromStyle)\n return fromStyle\n}\n\nfunction getTransition(type: 'in' | 'out', style: IStateStyle, data: IUI): ITransition {\n let name: 'transition' | 'transitionOut' = type === 'in' ? 'transition' : 'transitionOut'\n if (type === 'out' && isNull(data[name]) && isNull(style[name])) name = 'transition'\n return isNull(style[name]) ? data[name] : style[name]\n}\n\nfunction assign(style: IStateStyle, stateStyle: IStateStyle): boolean {\n Object.assign(style, stateStyle)\n return true\n}","import { IUI, IStateStyle, IStateStyleType, IStateName } from '@leafer-ui/interface'\nimport { State } from '@leafer-ui/core'\n\nimport { setStyle } from './style'\n\n\nexport function setPointerState(leaf: IUI, stateName: IStateStyleType): void {\n const style = leaf[stateName]\n if (style) setStyle(leaf, style)\n if (leaf.button) setChildrenState(leaf.children, stateName)\n}\n\nexport function setState(leaf: IUI, stateName: string, stateStyle?: IStateStyle): void {\n if (!stateStyle) stateStyle = leaf.states[stateName]\n setStyle(leaf, stateStyle)\n if (leaf.button) setChildrenState(leaf.children, null, stateName)\n}\n\n\nfunction setChildrenState(children: IUI[], stateType: IStateStyleType, stateName?: IStateName): void {\n if (!children) return\n\n let leaf: IUI, update: boolean\n for (let i = 0, len = children.length; i < len; i++) {\n leaf = children[i]\n if (stateType) {\n\n update = true\n switch (stateType) {\n case 'hoverStyle':\n if (State.isHover(leaf)) update = false\n break\n case 'pressStyle':\n if (State.isPress(leaf)) update = false\n break\n case 'focusStyle':\n if (State.isFocus(leaf)) update = false\n }\n if (update) setPointerState(leaf, stateType)\n\n } else if (stateName !== undefined) setState(leaf, stateName)\n\n if (leaf.isBranch) setChildrenState(leaf.children, stateType, stateName)\n }\n}","import { IUI, IStateStyleType, IStateStyle, IStateName } from '@leafer-ui/interface'\n\nimport { unsetStyle } from './style'\n\n\nexport function unsetPointerState(leaf: IUI, stateName: IStateStyleType): void {\n const style = leaf[stateName]\n if (style) unsetStyle(leaf, style)\n if (leaf.button) unsetChildrenState(leaf.children, stateName)\n}\n\nexport function unsetState(leaf: IUI, stateName: string, stateStyle?: IStateStyle): void {\n unsetStyle(leaf, stateStyle)\n if (leaf.button) unsetChildrenState(leaf.children, null, stateName)\n}\n\n\nfunction unsetChildrenState(children: IUI[], stateType: IStateStyleType, stateName?: IStateName): void {\n if (!children) return\n\n let leaf: IUI\n for (let i = 0, len = children.length; i < len; i++) {\n leaf = children[i]\n if (stateType) unsetPointerState(leaf, stateType)\n else if (stateName !== undefined) unsetState(leaf, stateName)\n\n if (leaf.isBranch) unsetChildrenState(leaf.children, stateType, stateName)\n }\n}","import { IUI, IStateName, } from '@leafer-ui/interface'\n\nimport { findParentButton } from './helper'\n\n\nexport function checkPointerState(fnName: 'isHover' | 'isPress' | 'isFocus' | 'isDrag', leaf: IUI, button?: IUI | boolean): boolean {\n let find: boolean\n const interaction = leaf.leafer ? leaf.leafer.interaction : null\n if (interaction) {\n find = interaction[fnName](leaf)\n if (!find && button) {\n const parentButton = findParentButton(leaf, button)\n if (parentButton) find = interaction[fnName](parentButton)\n }\n }\n return find\n}\n\nexport function checkFixedState(attrName: 'selected' | 'disabled', leaf: IUI, button?: IUI | boolean): boolean {\n let find = leaf[attrName]\n if (!find && button) {\n const parentButton = findParentButton(leaf, button)\n if (parentButton) find = parentButton[attrName]\n }\n return find\n}\n\nexport function checkState(stateName: IStateName, leaf: IUI, button?: IUI | boolean): boolean {\n let find = leaf.states[stateName]\n if (!find && button) {\n const parentButton = findParentButton(leaf, button)\n if (parentButton) find = parentButton.states[stateName]\n }\n return !!find\n}\n","export { stateType, stateStyleType } from './decorator'\n\nimport { IUI, IStateStyleType, IStateName, IText } from '@leafer-ui/interface'\nimport { State, UI, Text, dataType, Plugin, getDescriptor, doBoundsType, defineKey } from '@leafer-ui/core'\n\nimport { setPointerState, setState } from './set'\nimport { unsetPointerState, unsetState } from './unset'\nimport { updateEventStyle } from './event'\nimport { checkPointerState, checkFixedState, checkState } from './check'\nimport { getStyle, updateStyle } from './style'\nimport { stateType, stateStyleType } from './decorator'\n\n\nPlugin.add('state')\n\n\nState.animateExcludes = {\n animation: 1,\n animationOut: 1,\n\n transition: 1,\n transitionOut: 1,\n\n states: 1,\n state: 1,\n\n placeholder: 1,\n\n normalStyle: 1,\n hoverStyle: 1,\n pressStyle: 1,\n focusStyle: 1,\n selectedStyle: 1,\n disabledStyle: 1,\n placeholderStyle: 1\n}\n\n\nState.isState = function (state: IStateName, leaf: IUI, button?: IUI | boolean): boolean { return checkState(state, leaf, button) }\nState.isSelected = function (leaf: IUI, button?: IUI | boolean): boolean { return checkFixedState('selected', leaf, button) }\nState.isDisabled = function (leaf: IUI, button?: IUI | boolean): boolean { return checkFixedState('disabled', leaf, button) }\n\nState.isFocus = function (leaf: IUI, button?: IUI | boolean): boolean { return checkPointerState('isFocus', leaf, button) }\nState.isHover = function (leaf: IUI, button?: IUI | boolean): boolean { return checkPointerState('isHover', leaf, button) }\nState.isPress = function (leaf: IUI, button?: IUI | boolean): boolean { return checkPointerState('isPress', leaf, button) }\nState.isPlacehold = function (leaf: IUI, _button?: IUI | boolean): boolean { return (leaf as IText).__.__isPlacehold }\n\nState.isDrag = function (leaf: IUI, button?: IUI | boolean): boolean { return checkPointerState('isDrag', leaf, button) }\n\nState.setStyleName = function (leaf: IUI, stateType: IStateStyleType, value: boolean): void { value ? setState(leaf, stateType, leaf[stateType]) : unsetState(leaf, stateType, leaf[stateType]) }\nState.set = function (leaf: IUI, stateName: string): void { const style = leaf.states[stateName]; style ? setState(leaf, stateName, style) : unsetState(leaf, stateName, style) }\n\nState.getStyle = getStyle\nState.updateStyle = updateStyle\nState.updateEventStyle = updateEventStyle\n\n\nconst ui = UI.prototype\n\n// addAttr\nUI.addAttr('selected', false, stateType, 'selectedStyle')\nUI.addAttr('disabled', false, stateType, 'disabledStyle')\n\nUI.addAttr('states', {}, stateStyleType)\nUI.addAttr('state', '', stateType)\n\nUI.addAttr('normalStyle', undefined, dataType)\nUI.addAttr('hoverStyle', undefined, stateStyleType)\nUI.addAttr('pressStyle', undefined, stateStyleType)\nUI.addAttr('focusStyle', undefined, stateStyleType)\nUI.addAttr('selectedStyle', undefined, stateStyleType)\nUI.addAttr('disabledStyle', undefined, stateStyleType)\nUI.addAttr('placeholderStyle', undefined, stateStyleType)\n\nUI.addAttr('button', false, dataType)\n\nui.focus = function (value: boolean = true): void {\n this.waitLeafer(() => {\n let { focusData } = this.app.interaction\n if (value) {\n if (focusData) focusData.focus(false)\n focusData = this\n } else focusData = null\n this.app.interaction.focusData = focusData\n value ? setPointerState(this, 'focusStyle') : unsetPointerState(this, 'focusStyle')\n })\n}\n\nui.updateState = function (): void {\n State.updateStyle(this, undefined, 'in')\n}\n\n\nconst text = Text.prototype, textKey = 'text'\n\ndefineKey(text, textKey, {\n ...getDescriptor(text, textKey),\n set(value: string) {\n const t = this as Text, oldValue = t.text\n if (t.__setAttr(textKey, value)) {\n doBoundsType(t)\n if (t.placeholderStyle && t.placeholder && (oldValue === '' || value === '')) t.__layout.stateStyleChanged = true\n }\n }\n})\n","import { IUI } from '@leafer-ui/interface'\nimport { PointerEvent } from '@leafer-ui/core'\n\nimport { setPointerState } from './set'\nimport { unsetPointerState } from './unset'\n\n\nexport function updateEventStyle(leaf: IUI, eventType: string): void {\n switch (eventType) {\n case PointerEvent.ENTER:\n setPointerState(leaf, 'hoverStyle')\n break\n case PointerEvent.LEAVE:\n unsetPointerState(leaf, 'hoverStyle')\n break\n case PointerEvent.DOWN:\n setPointerState(leaf, 'pressStyle')\n break\n case PointerEvent.UP:\n unsetPointerState(leaf, 'pressStyle')\n break\n }\n}"],"names":["stateType","defaultValue","styleName","decorateLeafAttr","key","attr","set","value","this","__setAttr","leaferIsReady","State","setStyleName","__layout","stateStyleChanged","stateStyleType","findParentButton","leaf","button","parent","i","setStyle","style","undefined","updateStyle","unsetStyle","normalStyle","emprtyStyle","type","scale","MathHelper","assignScale","canAnimate","transition","data","name","isNull","getTransition","fromStyle","filterAnimateStyle","animate","getFromStyle","getStyle","killAnimate","statesStyle","animation","Object","assign","endingStyle","kill","filterStyle","toStyle","exist","state","stateStyle","states","isState","selectedStyle","isSelected","placeholderStyle","isPlacehold","isDisabled","disabledStyle","focusStyle","isFocus","hoverStyle","isHover","pressStyle","isPress","addStyle","useAnimateExcludes","to","forStyle","animateExcludes","setPointerState","stateName","setChildrenState","children","setState","update","len","length","isBranch","unsetPointerState","unsetChildrenState","unsetState","checkPointerState","fnName","find","interaction","leafer","parentButton","checkFixedState","attrName","Plugin","add","animationOut","transitionOut","placeholder","checkState","_button","__","__isPlacehold","isDrag","updateEventStyle","eventType","PointerEvent","ENTER","LEAVE","DOWN","UP","ui","UI","prototype","addAttr","dataType","focus","waitLeafer","focusData","app","updateState","text","Text","textKey","defineKey","getDescriptor","t","oldValue","doBoundsType"],"mappings":"sNAGgB,SAAAA,EAAUC,EAAuBC,GAC7C,OAAOC,EAAiBF,GAAeG,GAAgBC,EAAK,CACxD,GAAAC,CAAIC,GACAC,KAAKC,UAAUL,EAAKG,GAChBC,KAAKE,cAAeR,EAAYS,EAAMC,aAAaJ,KAAMN,EAAWK,GAASI,EAAML,IAAIE,KAAMD,GAC5FC,KAAKK,SAASC,mBAAoB,MAGnD,CAEM,SAAUC,EAAed,GAC3B,OAAOE,EAAiBF,GAAeG,GAAgBC,EAAK,CACxD,GAAAC,CAAIC,GACAC,KAAKC,UAAUL,EAAKG,GACpBC,KAAKK,SAASC,mBAAoB,MAG9C,CCjBgB,SAAAE,EAAiBC,EAAWC,GACxC,GAAIA,IAAqB,IAAXA,EAAiB,OAAOA,EACtC,IAAKD,EAAKC,OAAQ,CACd,IAAIC,OAAEA,GAAWF,EACjB,IAAK,IAAIG,EAAI,EAAGA,EAAI,EAAGA,IACnB,GAAID,EAAQ,CACR,GAAIA,EAAOD,OAAQ,OAAOC,EAC1BA,EAASA,EAAOA,QAI5B,OAAO,IACX,CCTgB,SAAAE,EAASJ,EAAWK,GACX,iBAAVA,IAAoBA,OAAQC,GACvCC,EAAYP,EAAMK,EAAO,KAC7B,CAEgB,SAAAG,EAAWR,EAAWK,GAClC,MAAMI,YAAEA,GAAgBT,EACH,iBAAVK,IAAoBA,OAAQC,GACnCG,IACKJ,IAAOA,EAAQI,GACpBF,EAAYP,EAAMK,EAAO,OAEjC,CAEA,MAA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AAUkH,EAASpH,KACrByH,EAAaF,GACTA,EAAEnE,kBAAoBmE,EAAE5B,cAA6B,KAAb6B,GAA6B,KAAVxH,KAAeuH,EAAEjH,SAASC,mBAAoB,GAEpH"}
|
|
1
|
+
{"version":3,"file":"state.esm.min.js","sources":["../../../../../../src/in/packages/state/src/decorator.ts","../../../../../../src/in/packages/state/src/helper.ts","../../../../../../src/in/packages/state/src/style.ts","../../../../../../src/in/packages/state/src/set.ts","../../../../../../src/in/packages/state/src/unset.ts","../../../../../../src/in/packages/state/src/check.ts","../../../../../../src/in/packages/state/src/index.ts","../../../../../../src/in/packages/state/src/event.ts"],"sourcesContent":["import { IValue } from '@leafer-ui/interface'\nimport { decorateLeafAttr, attr, State } from '@leafer-ui/core'\n\nexport function stateType(defaultValue?: IValue, styleName?: string) {\n return decorateLeafAttr(defaultValue, (key: string) => attr({\n set(value: any) {\n this.__setAttr(key, value)\n if (this.leaferIsReady) styleName ? State.setStyleName(this, styleName, value) : State.set(this, value)\n else this.__layout.stateStyleChanged = true\n }\n }))\n}\n\nexport function stateStyleType(defaultValue?: IValue) {\n return decorateLeafAttr(defaultValue, (key: string) => attr({\n set(value: any) {\n this.__setAttr(key, value)\n this.__layout.stateStyleChanged = true\n }\n }))\n}","import { IUI } from '@leafer-ui/interface'\n\n\nexport function findParentButton(leaf: IUI, button?: IUI | boolean): IUI {\n if (button && button !== true) return button\n if (!leaf.button) {\n let { parent } = leaf\n for (let i = 0; i < 2; i++) {\n if (parent) {\n if (parent.button) return parent\n parent = parent.parent\n }\n }\n }\n return null\n}","import { IUI, IObject, IUIInputData, IStateStyle, IScaleData, ITransition } from '@leafer-ui/interface'\nimport { State, MathHelper, isNull, isObject } from '@leafer-ui/core'\n\nimport { findParentButton } from './helper'\n\n\nexport function setStyle(leaf: IUI, style: IStateStyle): void {\n if (!isObject(style)) style = undefined\n updateStyle(leaf, style, 'in')\n}\n\nexport function unsetStyle(leaf: IUI, style?: IStateStyle): void {\n const { normalStyle } = leaf\n if (!isObject(style)) style = undefined\n if (normalStyle) {\n if (!style) style = normalStyle\n updateStyle(leaf, style, 'out')\n }\n}\n\nconst emprtyStyle = {}\n\nexport function updateStyle(leaf: IUI, style?: IStateStyle, type?: 'in' | 'out'): void {\n const { normalStyle } = leaf\n\n if (!style) style = emprtyStyle\n\n if (style.scale) {\n MathHelper.assignScale(style as IScaleData, style.scale)\n delete style.scale\n }\n\n if (style === emprtyStyle || !State.canAnimate) type = null\n let transition = type ? getTransition(type, style, leaf) : false\n const fromStyle = transition ? getFromStyle(leaf, style) : undefined\n\n // 回到正常状态\n const nextStyle = State.canAnimate && getStyle(leaf)\n if (nextStyle) leaf.killAnimate('transition')\n if (normalStyle) leaf.set(normalStyle, 'temp')\n\n\n const statesStyle = getStyle(leaf) // 必须在回到正常状态之后获取\n if (statesStyle) {\n\n const { animation } = statesStyle\n if (animation) {\n const animate = leaf.animate(animation, undefined, 'animation', true)\n Object.assign(statesStyle, animate.endingStyle) // 加上最终的动画样式\n\n if (type !== 'in' || style.animation !== animation) animate.kill()\n else transition = false\n\n delete statesStyle.animation\n }\n\n\n leaf.normalStyle = filterStyle(statesStyle, leaf)\n leaf.set(statesStyle, 'temp')\n } else {\n leaf.normalStyle = undefined\n }\n\n if (transition) {\n const toStyle = filterStyle(fromStyle, leaf)\n leaf.set(fromStyle, 'temp')\n leaf.animate([fromStyle, toStyle], transition, 'transition', true)\n }\n\n leaf.__layout.stateStyleChanged = false\n}\n\nexport function getStyle(leaf: IUI): IStateStyle {\n\n // 从低到高依次覆盖: states < selected < placeholder < focus < hover < press < disabled\n\n let exist: boolean\n const style: IUIInputData = {}, button = findParentButton(leaf)\n const state = button ? (leaf.state || button.state) : leaf.state\n\n const stateStyle = state && leaf.states[state]\n if (stateStyle && State.isState(state, leaf, button)) exist = assign(style, stateStyle)\n\n const selectedStyle = style.selectedStyle || leaf.selectedStyle\n if (selectedStyle && State.isSelected(leaf, button)) exist = assign(style, selectedStyle)\n\n const placeholderStyle = style.placeholderStyle || leaf.placeholderStyle\n if (placeholderStyle && State.isPlacehold(leaf, button)) exist = assign(style, placeholderStyle)\n\n if (State.isDisabled(leaf, button)) {\n\n const disabledStyle = style.disabledStyle || leaf.disabledStyle\n if (disabledStyle) exist = assign(style, disabledStyle)\n\n } else {\n\n const focusStyle = style.focusStyle || leaf.focusStyle\n if (focusStyle && State.isFocus(leaf, button)) exist = assign(style, focusStyle)\n\n const hoverStyle = style.hoverStyle || leaf.hoverStyle\n if (hoverStyle && State.isHover(leaf, button)) exist = assign(style, hoverStyle)\n\n const pressStyle = style.pressStyle || leaf.pressStyle\n if (pressStyle && State.isPress(leaf, button)) exist = assign(style, pressStyle)\n\n }\n\n return exist ? style : undefined\n}\n\n\nfunction filterStyle(style: IObject, data: IObject, addStyle?: IObject, useAnimateExcludes?: boolean): IObject {\n const to: IObject = addStyle ? style : {}, forStyle = addStyle || style\n for (let key in forStyle) {\n if (useAnimateExcludes) {\n if (!State.animateExcludes[key]) to[key] = data[key]\n } else to[key] = data[key]\n }\n return to\n}\n\nfunction filterAnimateStyle(style: IObject, data: IObject, addStyle?: IObject): IObject {\n return filterStyle(style, data, addStyle, true)\n}\n\nfunction getFromStyle(leaf: IUI, style: IObject): IObject {\n const fromStyle = filterAnimateStyle(style, leaf), animate = leaf.animate()\n if (animate) filterAnimateStyle(fromStyle, leaf, animate.fromStyle)\n return fromStyle\n}\n\nfunction getTransition(type: 'in' | 'out', style: IStateStyle, data: IUI): ITransition {\n let name: 'transition' | 'transitionOut' = type === 'in' ? 'transition' : 'transitionOut'\n if (type === 'out' && isNull(data[name]) && isNull(style[name])) name = 'transition'\n return isNull(style[name]) ? data[name] : style[name]\n}\n\nfunction assign(style: IStateStyle, stateStyle: IStateStyle): boolean {\n Object.assign(style, stateStyle)\n return true\n}","import { IUI, IStateStyle, IStateStyleType, IStateName } from '@leafer-ui/interface'\nimport { State, isUndefined } from '@leafer-ui/core'\n\nimport { setStyle } from './style'\n\n\nexport function setPointerState(leaf: IUI, stateName: IStateStyleType): void {\n const style = leaf[stateName]\n if (style) setStyle(leaf, style)\n if (leaf.button) setChildrenState(leaf.children, stateName)\n}\n\nexport function setState(leaf: IUI, stateName: string, stateStyle?: IStateStyle): void {\n if (!stateStyle) stateStyle = leaf.states[stateName]\n setStyle(leaf, stateStyle)\n if (leaf.button) setChildrenState(leaf.children, null, stateName)\n}\n\n\nfunction setChildrenState(children: IUI[], stateType: IStateStyleType, stateName?: IStateName): void {\n if (!children) return\n\n let leaf: IUI, update: boolean\n for (let i = 0, len = children.length; i < len; i++) {\n leaf = children[i]\n if (stateType) {\n\n update = true\n switch (stateType) {\n case 'hoverStyle':\n if (State.isHover(leaf)) update = false\n break\n case 'pressStyle':\n if (State.isPress(leaf)) update = false\n break\n case 'focusStyle':\n if (State.isFocus(leaf)) update = false\n }\n if (update) setPointerState(leaf, stateType)\n\n } else if (!isUndefined(stateName)) setState(leaf, stateName)\n\n if (leaf.isBranch) setChildrenState(leaf.children, stateType, stateName)\n }\n}","import { IUI, IStateStyleType, IStateStyle, IStateName } from '@leafer-ui/interface'\nimport { isUndefined } from '@leafer-ui/core'\n\nimport { unsetStyle } from './style'\n\n\nexport function unsetPointerState(leaf: IUI, stateName: IStateStyleType): void {\n const style = leaf[stateName]\n if (style) unsetStyle(leaf, style)\n if (leaf.button) unsetChildrenState(leaf.children, stateName)\n}\n\nexport function unsetState(leaf: IUI, stateName: string, stateStyle?: IStateStyle): void {\n unsetStyle(leaf, stateStyle)\n if (leaf.button) unsetChildrenState(leaf.children, null, stateName)\n}\n\n\nfunction unsetChildrenState(children: IUI[], stateType: IStateStyleType, stateName?: IStateName): void {\n if (!children) return\n\n let leaf: IUI\n for (let i = 0, len = children.length; i < len; i++) {\n leaf = children[i]\n if (stateType) unsetPointerState(leaf, stateType)\n else if (!isUndefined(stateName)) unsetState(leaf, stateName)\n\n if (leaf.isBranch) unsetChildrenState(leaf.children, stateType, stateName)\n }\n}","import { IUI, IStateName, } from '@leafer-ui/interface'\n\nimport { findParentButton } from './helper'\n\n\nexport function checkPointerState(fnName: 'isHover' | 'isPress' | 'isFocus' | 'isDrag', leaf: IUI, button?: IUI | boolean): boolean {\n let find: boolean\n const interaction = leaf.leafer ? leaf.leafer.interaction : null\n if (interaction) {\n find = interaction[fnName](leaf)\n if (!find && button) {\n const parentButton = findParentButton(leaf, button)\n if (parentButton) find = interaction[fnName](parentButton)\n }\n }\n return find\n}\n\nexport function checkFixedState(attrName: 'selected' | 'disabled', leaf: IUI, button?: IUI | boolean): boolean {\n let find = leaf[attrName]\n if (!find && button) {\n const parentButton = findParentButton(leaf, button)\n if (parentButton) find = parentButton[attrName]\n }\n return find\n}\n\nexport function checkState(stateName: IStateName, leaf: IUI, button?: IUI | boolean): boolean {\n let find = leaf.states[stateName]\n if (!find && button) {\n const parentButton = findParentButton(leaf, button)\n if (parentButton) find = parentButton.states[stateName]\n }\n return !!find\n}\n","export { stateType, stateStyleType } from './decorator'\n\nimport { IUI, IStateStyleType, IStateName, IText } from '@leafer-ui/interface'\nimport { State, UI, Text, dataType, Plugin, getDescriptor, doBoundsType, defineKey } from '@leafer-ui/core'\n\nimport { setPointerState, setState } from './set'\nimport { unsetPointerState, unsetState } from './unset'\nimport { updateEventStyle } from './event'\nimport { checkPointerState, checkFixedState, checkState } from './check'\nimport { getStyle, updateStyle } from './style'\nimport { stateType, stateStyleType } from './decorator'\n\n\nPlugin.add('state')\n\n\nState.animateExcludes = {\n animation: 1,\n animationOut: 1,\n\n transition: 1,\n transitionOut: 1,\n\n states: 1,\n state: 1,\n\n placeholder: 1,\n\n normalStyle: 1,\n hoverStyle: 1,\n pressStyle: 1,\n focusStyle: 1,\n selectedStyle: 1,\n disabledStyle: 1,\n placeholderStyle: 1\n}\n\n\nState.isState = function (state: IStateName, leaf: IUI, button?: IUI | boolean): boolean { return checkState(state, leaf, button) }\nState.isSelected = function (leaf: IUI, button?: IUI | boolean): boolean { return checkFixedState('selected', leaf, button) }\nState.isDisabled = function (leaf: IUI, button?: IUI | boolean): boolean { return checkFixedState('disabled', leaf, button) }\n\nState.isFocus = function (leaf: IUI, button?: IUI | boolean): boolean { return checkPointerState('isFocus', leaf, button) }\nState.isHover = function (leaf: IUI, button?: IUI | boolean): boolean { return checkPointerState('isHover', leaf, button) }\nState.isPress = function (leaf: IUI, button?: IUI | boolean): boolean { return checkPointerState('isPress', leaf, button) }\nState.isPlacehold = function (leaf: IUI, _button?: IUI | boolean): boolean { return (leaf as IText).__.__isPlacehold }\n\nState.isDrag = function (leaf: IUI, button?: IUI | boolean): boolean { return checkPointerState('isDrag', leaf, button) }\n\nState.setStyleName = function (leaf: IUI, stateType: IStateStyleType, value: boolean): void { value ? setState(leaf, stateType, leaf[stateType]) : unsetState(leaf, stateType, leaf[stateType]) }\nState.set = function (leaf: IUI, stateName: string): void { const style = leaf.states[stateName]; style ? setState(leaf, stateName, style) : unsetState(leaf, stateName, style) }\n\nState.getStyle = getStyle\nState.updateStyle = updateStyle\nState.updateEventStyle = updateEventStyle\n\n\nconst ui = UI.prototype\n\n// addAttr\nUI.addAttr('selected', false, stateType, 'selectedStyle')\nUI.addAttr('disabled', false, stateType, 'disabledStyle')\n\nUI.addAttr('states', {}, stateStyleType)\nUI.addAttr('state', '', stateType)\n\nUI.addAttr('normalStyle', undefined, dataType)\nUI.addAttr('hoverStyle', undefined, stateStyleType)\nUI.addAttr('pressStyle', undefined, stateStyleType)\nUI.addAttr('focusStyle', undefined, stateStyleType)\nUI.addAttr('selectedStyle', undefined, stateStyleType)\nUI.addAttr('disabledStyle', undefined, stateStyleType)\nUI.addAttr('placeholderStyle', undefined, stateStyleType)\n\nUI.addAttr('button', false, dataType)\n\nui.focus = function (value: boolean = true): void {\n this.waitLeafer(() => {\n let { focusData } = this.app.interaction\n if (value) {\n if (focusData) focusData.focus(false)\n focusData = this\n } else focusData = null\n this.app.interaction.focusData = focusData\n value ? setPointerState(this, 'focusStyle') : unsetPointerState(this, 'focusStyle')\n })\n}\n\nui.updateState = function (): void {\n State.updateStyle(this, undefined, 'in')\n}\n\n\nconst text = Text.prototype, textKey = 'text'\n\ndefineKey(text, textKey, {\n ...getDescriptor(text, textKey),\n set(value: string) {\n const t = this as Text, oldValue = t.text\n if (t.__setAttr(textKey, value)) {\n doBoundsType(t)\n if (t.placeholderStyle && t.placeholder && (oldValue === '' || value === '')) t.__layout.stateStyleChanged = true\n }\n }\n})\n","import { IUI } from '@leafer-ui/interface'\nimport { PointerEvent } from '@leafer-ui/core'\n\nimport { setPointerState } from './set'\nimport { unsetPointerState } from './unset'\n\n\nexport function updateEventStyle(leaf: IUI, eventType: string): void {\n switch (eventType) {\n case PointerEvent.ENTER:\n setPointerState(leaf, 'hoverStyle')\n break\n case PointerEvent.LEAVE:\n unsetPointerState(leaf, 'hoverStyle')\n break\n case PointerEvent.DOWN:\n setPointerState(leaf, 'pressStyle')\n break\n case PointerEvent.UP:\n unsetPointerState(leaf, 'pressStyle')\n break\n }\n}"],"names":["stateType","defaultValue","styleName","decorateLeafAttr","key","attr","set","value","this","__setAttr","leaferIsReady","State","setStyleName","__layout","stateStyleChanged","stateStyleType","findParentButton","leaf","button","parent","i","setStyle","style","isObject","undefined","updateStyle","unsetStyle","normalStyle","emprtyStyle","type","scale","MathHelper","assignScale","canAnimate","transition","data","name","isNull","getTransition","fromStyle","filterAnimateStyle","animate","getFromStyle","getStyle","killAnimate","statesStyle","animation","Object","assign","endingStyle","kill","filterStyle","toStyle","exist","state","stateStyle","states","isState","selectedStyle","isSelected","placeholderStyle","isPlacehold","isDisabled","disabledStyle","focusStyle","isFocus","hoverStyle","isHover","pressStyle","isPress","addStyle","useAnimateExcludes","to","forStyle","animateExcludes","setPointerState","stateName","setChildrenState","children","setState","update","len","length","isUndefined","isBranch","unsetPointerState","unsetChildrenState","unsetState","checkPointerState","fnName","find","interaction","leafer","parentButton","checkFixedState","attrName","Plugin","add","animationOut","transitionOut","placeholder","checkState","_button","__","__isPlacehold","isDrag","updateEventStyle","eventType","PointerEvent","ENTER","LEAVE","DOWN","UP","ui","UI","prototype","addAttr","dataType","focus","waitLeafer","focusData","app","updateState","text","Text","textKey","defineKey","getDescriptor","t","oldValue","doBoundsType"],"mappings":"qPAGM,SAAUA,EAAUC,EAAuBC,GAC7C,OAAOC,EAAiBF,EAAeG,GAAgBC,EAAK,CACxD,GAAAC,CAAIC,GACAC,KAAKC,UAAUL,EAAKG,GAChBC,KAAKE,cAAeR,EAAYS,EAAMC,aAAaJ,KAAMN,EAAWK,GAASI,EAAML,IAAIE,KAAMD,GAC5FC,KAAKK,SAASC,mBAAoB,CAC3C,IAER,CAEM,SAAUC,EAAed,GAC3B,OAAOE,EAAiBF,EAAeG,GAAgBC,EAAK,CACxD,GAAAC,CAAIC,GACAC,KAAKC,UAAUL,EAAKG,GACpBC,KAAKK,SAASC,mBAAoB,CACtC,IAER,CCjBM,SAAUE,EAAiBC,EAAWC,GACxC,GAAIA,IAAqB,IAAXA,EAAiB,OAAOA,EACtC,IAAKD,EAAKC,OAAQ,CACd,IAAIC,OAAEA,GAAWF,EACjB,IAAK,IAAIG,EAAI,EAAGA,EAAI,EAAGA,IACnB,GAAID,EAAQ,CACR,GAAIA,EAAOD,OAAQ,OAAOC,EAC1BA,EAASA,EAAOA,MACpB,CAER,CACA,OAAO,IACX,CCTM,SAAUE,EAASJ,EAAWK,GAC3BC,EAASD,KAAQA,OAAQE,GAC9BC,EAAYR,EAAMK,EAAO,KAC7B,CAEM,SAAUI,EAAWT,EAAWK,GAClC,MAAMK,YAAEA,GAAgBV,EACnBM,EAASD,KAAQA,OAAQE,GAC1BG,IACKL,IAAOA,EAAQK,GACpBF,EAAYR,EAAMK,EAAO,OAEjC,CAEA,MAAMM,EAAc,CAAA,WAEJH,EAAYR,EAAWK,EAAqBO,GACxD,MAAMF,YAAEA,GAAgBV,EAEnBK,IAAOA,EAAQM,GAEhBN,EAAMQ,QACNC,EAAWC,YAAYV,EAAqBA,EAAMQ,cAC3CR,EAAMQ,OAGbR,IAAUM,GAAgBjB,EAAMsB,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.js
CHANGED
|
@@ -1,129 +1,103 @@
|
|
|
1
1
|
this.LeaferIN = this.LeaferIN || {};
|
|
2
|
-
this.LeaferIN.state = (function (exports, core) {
|
|
3
|
-
'use strict';
|
|
4
2
|
|
|
3
|
+
this.LeaferIN.state = function(exports, core) {
|
|
4
|
+
"use strict";
|
|
5
5
|
function stateType(defaultValue, styleName) {
|
|
6
|
-
return core.decorateLeafAttr(defaultValue,
|
|
6
|
+
return core.decorateLeafAttr(defaultValue, key => core.attr({
|
|
7
7
|
set(value) {
|
|
8
8
|
this.__setAttr(key, value);
|
|
9
|
-
if (this.leaferIsReady)
|
|
10
|
-
styleName ? core.State.setStyleName(this, styleName, value) : core.State.set(this, value);
|
|
11
|
-
else
|
|
12
|
-
this.__layout.stateStyleChanged = true;
|
|
9
|
+
if (this.leaferIsReady) styleName ? core.State.setStyleName(this, styleName, value) : core.State.set(this, value); else this.__layout.stateStyleChanged = true;
|
|
13
10
|
}
|
|
14
11
|
}));
|
|
15
12
|
}
|
|
16
13
|
function stateStyleType(defaultValue) {
|
|
17
|
-
return core.decorateLeafAttr(defaultValue,
|
|
14
|
+
return core.decorateLeafAttr(defaultValue, key => core.attr({
|
|
18
15
|
set(value) {
|
|
19
16
|
this.__setAttr(key, value);
|
|
20
17
|
this.__layout.stateStyleChanged = true;
|
|
21
18
|
}
|
|
22
19
|
}));
|
|
23
20
|
}
|
|
24
|
-
|
|
25
21
|
function findParentButton(leaf, button) {
|
|
26
|
-
if (button && button !== true)
|
|
27
|
-
return button;
|
|
22
|
+
if (button && button !== true) return button;
|
|
28
23
|
if (!leaf.button) {
|
|
29
|
-
let { parent
|
|
24
|
+
let {parent: parent} = leaf;
|
|
30
25
|
for (let i = 0; i < 2; i++) {
|
|
31
26
|
if (parent) {
|
|
32
|
-
if (parent.button)
|
|
33
|
-
return parent;
|
|
27
|
+
if (parent.button) return parent;
|
|
34
28
|
parent = parent.parent;
|
|
35
29
|
}
|
|
36
30
|
}
|
|
37
31
|
}
|
|
38
32
|
return null;
|
|
39
33
|
}
|
|
40
|
-
|
|
41
34
|
function setStyle(leaf, style) {
|
|
42
|
-
if (
|
|
43
|
-
|
|
44
|
-
updateStyle(leaf, style, 'in');
|
|
35
|
+
if (!core.isObject(style)) style = undefined;
|
|
36
|
+
updateStyle(leaf, style, "in");
|
|
45
37
|
}
|
|
46
38
|
function unsetStyle(leaf, style) {
|
|
47
|
-
const { normalStyle
|
|
48
|
-
if (
|
|
49
|
-
style = undefined;
|
|
39
|
+
const {normalStyle: normalStyle} = leaf;
|
|
40
|
+
if (!core.isObject(style)) style = undefined;
|
|
50
41
|
if (normalStyle) {
|
|
51
|
-
if (!style)
|
|
52
|
-
|
|
53
|
-
updateStyle(leaf, style, 'out');
|
|
42
|
+
if (!style) style = normalStyle;
|
|
43
|
+
updateStyle(leaf, style, "out");
|
|
54
44
|
}
|
|
55
45
|
}
|
|
56
46
|
const emprtyStyle = {};
|
|
57
47
|
function updateStyle(leaf, style, type) {
|
|
58
|
-
const { normalStyle
|
|
59
|
-
if (!style)
|
|
60
|
-
style = emprtyStyle;
|
|
48
|
+
const {normalStyle: normalStyle} = leaf;
|
|
49
|
+
if (!style) style = emprtyStyle;
|
|
61
50
|
if (style.scale) {
|
|
62
51
|
core.MathHelper.assignScale(style, style.scale);
|
|
63
52
|
delete style.scale;
|
|
64
53
|
}
|
|
65
|
-
if (style === emprtyStyle || !core.State.canAnimate)
|
|
66
|
-
type = null;
|
|
54
|
+
if (style === emprtyStyle || !core.State.canAnimate) type = null;
|
|
67
55
|
let transition = type ? getTransition(type, style, leaf) : false;
|
|
68
56
|
const fromStyle = transition ? getFromStyle(leaf, style) : undefined;
|
|
69
57
|
const nextStyle = core.State.canAnimate && getStyle(leaf);
|
|
70
|
-
if (nextStyle)
|
|
71
|
-
|
|
72
|
-
if (normalStyle)
|
|
73
|
-
leaf.set(normalStyle, 'temp');
|
|
58
|
+
if (nextStyle) leaf.killAnimate("transition");
|
|
59
|
+
if (normalStyle) leaf.set(normalStyle, "temp");
|
|
74
60
|
const statesStyle = getStyle(leaf);
|
|
75
61
|
if (statesStyle) {
|
|
76
|
-
const { animation
|
|
62
|
+
const {animation: animation} = statesStyle;
|
|
77
63
|
if (animation) {
|
|
78
|
-
const animate = leaf.animate(animation, undefined,
|
|
64
|
+
const animate = leaf.animate(animation, undefined, "animation", true);
|
|
79
65
|
Object.assign(statesStyle, animate.endingStyle);
|
|
80
|
-
if (type !==
|
|
81
|
-
animate.kill();
|
|
82
|
-
else
|
|
83
|
-
transition = false;
|
|
66
|
+
if (type !== "in" || style.animation !== animation) animate.kill(); else transition = false;
|
|
84
67
|
delete statesStyle.animation;
|
|
85
68
|
}
|
|
86
69
|
leaf.normalStyle = filterStyle(statesStyle, leaf);
|
|
87
|
-
leaf.set(statesStyle,
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
70
|
+
leaf.set(statesStyle, "temp");
|
|
71
|
+
} else {
|
|
90
72
|
leaf.normalStyle = undefined;
|
|
91
73
|
}
|
|
92
74
|
if (transition) {
|
|
93
75
|
const toStyle = filterStyle(fromStyle, leaf);
|
|
94
|
-
leaf.set(fromStyle,
|
|
95
|
-
leaf.animate([fromStyle, toStyle], transition,
|
|
76
|
+
leaf.set(fromStyle, "temp");
|
|
77
|
+
leaf.animate([ fromStyle, toStyle ], transition, "transition", true);
|
|
96
78
|
}
|
|
97
79
|
leaf.__layout.stateStyleChanged = false;
|
|
98
80
|
}
|
|
99
81
|
function getStyle(leaf) {
|
|
100
82
|
let exist;
|
|
101
83
|
const style = {}, button = findParentButton(leaf);
|
|
102
|
-
const state = button ?
|
|
84
|
+
const state = button ? leaf.state || button.state : leaf.state;
|
|
103
85
|
const stateStyle = state && leaf.states[state];
|
|
104
|
-
if (stateStyle && core.State.isState(state, leaf, button))
|
|
105
|
-
exist = assign(style, stateStyle);
|
|
86
|
+
if (stateStyle && core.State.isState(state, leaf, button)) exist = assign(style, stateStyle);
|
|
106
87
|
const selectedStyle = style.selectedStyle || leaf.selectedStyle;
|
|
107
|
-
if (selectedStyle && core.State.isSelected(leaf, button))
|
|
108
|
-
exist = assign(style, selectedStyle);
|
|
88
|
+
if (selectedStyle && core.State.isSelected(leaf, button)) exist = assign(style, selectedStyle);
|
|
109
89
|
const placeholderStyle = style.placeholderStyle || leaf.placeholderStyle;
|
|
110
|
-
if (placeholderStyle && core.State.isPlacehold(leaf, button))
|
|
111
|
-
exist = assign(style, placeholderStyle);
|
|
90
|
+
if (placeholderStyle && core.State.isPlacehold(leaf, button)) exist = assign(style, placeholderStyle);
|
|
112
91
|
if (core.State.isDisabled(leaf, button)) {
|
|
113
92
|
const disabledStyle = style.disabledStyle || leaf.disabledStyle;
|
|
114
|
-
if (disabledStyle)
|
|
115
|
-
|
|
116
|
-
}
|
|
117
|
-
else {
|
|
93
|
+
if (disabledStyle) exist = assign(style, disabledStyle);
|
|
94
|
+
} else {
|
|
118
95
|
const focusStyle = style.focusStyle || leaf.focusStyle;
|
|
119
|
-
if (focusStyle && core.State.isFocus(leaf, button))
|
|
120
|
-
exist = assign(style, focusStyle);
|
|
96
|
+
if (focusStyle && core.State.isFocus(leaf, button)) exist = assign(style, focusStyle);
|
|
121
97
|
const hoverStyle = style.hoverStyle || leaf.hoverStyle;
|
|
122
|
-
if (hoverStyle && core.State.isHover(leaf, button))
|
|
123
|
-
exist = assign(style, hoverStyle);
|
|
98
|
+
if (hoverStyle && core.State.isHover(leaf, button)) exist = assign(style, hoverStyle);
|
|
124
99
|
const pressStyle = style.pressStyle || leaf.pressStyle;
|
|
125
|
-
if (pressStyle && core.State.isPress(leaf, button))
|
|
126
|
-
exist = assign(style, pressStyle);
|
|
100
|
+
if (pressStyle && core.State.isPress(leaf, button)) exist = assign(style, pressStyle);
|
|
127
101
|
}
|
|
128
102
|
return exist ? style : undefined;
|
|
129
103
|
}
|
|
@@ -131,11 +105,8 @@ this.LeaferIN.state = (function (exports, core) {
|
|
|
131
105
|
const to = addStyle ? style : {}, forStyle = addStyle || style;
|
|
132
106
|
for (let key in forStyle) {
|
|
133
107
|
if (useAnimateExcludes) {
|
|
134
|
-
if (!core.State.animateExcludes[key])
|
|
135
|
-
|
|
136
|
-
}
|
|
137
|
-
else
|
|
138
|
-
to[key] = data[key];
|
|
108
|
+
if (!core.State.animateExcludes[key]) to[key] = data[key];
|
|
109
|
+
} else to[key] = data[key];
|
|
139
110
|
}
|
|
140
111
|
return to;
|
|
141
112
|
}
|
|
@@ -144,110 +115,89 @@ this.LeaferIN.state = (function (exports, core) {
|
|
|
144
115
|
}
|
|
145
116
|
function getFromStyle(leaf, style) {
|
|
146
117
|
const fromStyle = filterAnimateStyle(style, leaf), animate = leaf.animate();
|
|
147
|
-
if (animate)
|
|
148
|
-
filterAnimateStyle(fromStyle, leaf, animate.fromStyle);
|
|
118
|
+
if (animate) filterAnimateStyle(fromStyle, leaf, animate.fromStyle);
|
|
149
119
|
return fromStyle;
|
|
150
120
|
}
|
|
151
121
|
function getTransition(type, style, data) {
|
|
152
|
-
let name = type ===
|
|
153
|
-
if (type ===
|
|
154
|
-
name = 'transition';
|
|
122
|
+
let name = type === "in" ? "transition" : "transitionOut";
|
|
123
|
+
if (type === "out" && core.isNull(data[name]) && core.isNull(style[name])) name = "transition";
|
|
155
124
|
return core.isNull(style[name]) ? data[name] : style[name];
|
|
156
125
|
}
|
|
157
126
|
function assign(style, stateStyle) {
|
|
158
127
|
Object.assign(style, stateStyle);
|
|
159
128
|
return true;
|
|
160
129
|
}
|
|
161
|
-
|
|
162
130
|
function setPointerState(leaf, stateName) {
|
|
163
131
|
const style = leaf[stateName];
|
|
164
|
-
if (style)
|
|
165
|
-
|
|
166
|
-
if (leaf.button)
|
|
167
|
-
setChildrenState(leaf.children, stateName);
|
|
132
|
+
if (style) setStyle(leaf, style);
|
|
133
|
+
if (leaf.button) setChildrenState(leaf.children, stateName);
|
|
168
134
|
}
|
|
169
135
|
function setState(leaf, stateName, stateStyle) {
|
|
170
|
-
if (!stateStyle)
|
|
171
|
-
stateStyle = leaf.states[stateName];
|
|
136
|
+
if (!stateStyle) stateStyle = leaf.states[stateName];
|
|
172
137
|
setStyle(leaf, stateStyle);
|
|
173
|
-
if (leaf.button)
|
|
174
|
-
setChildrenState(leaf.children, null, stateName);
|
|
138
|
+
if (leaf.button) setChildrenState(leaf.children, null, stateName);
|
|
175
139
|
}
|
|
176
140
|
function setChildrenState(children, stateType, stateName) {
|
|
177
|
-
if (!children)
|
|
178
|
-
return;
|
|
141
|
+
if (!children) return;
|
|
179
142
|
let leaf, update;
|
|
180
143
|
for (let i = 0, len = children.length; i < len; i++) {
|
|
181
144
|
leaf = children[i];
|
|
182
145
|
if (stateType) {
|
|
183
146
|
update = true;
|
|
184
147
|
switch (stateType) {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
update = false;
|
|
148
|
+
case "hoverStyle":
|
|
149
|
+
if (core.State.isHover(leaf)) update = false;
|
|
150
|
+
break;
|
|
151
|
+
|
|
152
|
+
case "pressStyle":
|
|
153
|
+
if (core.State.isPress(leaf)) update = false;
|
|
154
|
+
break;
|
|
155
|
+
|
|
156
|
+
case "focusStyle":
|
|
157
|
+
if (core.State.isFocus(leaf)) update = false;
|
|
196
158
|
}
|
|
197
|
-
if (update)
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
else if (stateName !== undefined)
|
|
201
|
-
setState(leaf, stateName);
|
|
202
|
-
if (leaf.isBranch)
|
|
203
|
-
setChildrenState(leaf.children, stateType, stateName);
|
|
159
|
+
if (update) setPointerState(leaf, stateType);
|
|
160
|
+
} else if (!core.isUndefined(stateName)) setState(leaf, stateName);
|
|
161
|
+
if (leaf.isBranch) setChildrenState(leaf.children, stateType, stateName);
|
|
204
162
|
}
|
|
205
163
|
}
|
|
206
|
-
|
|
207
164
|
function unsetPointerState(leaf, stateName) {
|
|
208
165
|
const style = leaf[stateName];
|
|
209
|
-
if (style)
|
|
210
|
-
|
|
211
|
-
if (leaf.button)
|
|
212
|
-
unsetChildrenState(leaf.children, stateName);
|
|
166
|
+
if (style) unsetStyle(leaf, style);
|
|
167
|
+
if (leaf.button) unsetChildrenState(leaf.children, stateName);
|
|
213
168
|
}
|
|
214
169
|
function unsetState(leaf, stateName, stateStyle) {
|
|
215
170
|
unsetStyle(leaf, stateStyle);
|
|
216
|
-
if (leaf.button)
|
|
217
|
-
unsetChildrenState(leaf.children, null, stateName);
|
|
171
|
+
if (leaf.button) unsetChildrenState(leaf.children, null, stateName);
|
|
218
172
|
}
|
|
219
173
|
function unsetChildrenState(children, stateType, stateName) {
|
|
220
|
-
if (!children)
|
|
221
|
-
return;
|
|
174
|
+
if (!children) return;
|
|
222
175
|
let leaf;
|
|
223
176
|
for (let i = 0, len = children.length; i < len; i++) {
|
|
224
177
|
leaf = children[i];
|
|
225
|
-
if (stateType)
|
|
226
|
-
|
|
227
|
-
else if (stateName !== undefined)
|
|
228
|
-
unsetState(leaf, stateName);
|
|
229
|
-
if (leaf.isBranch)
|
|
230
|
-
unsetChildrenState(leaf.children, stateType, stateName);
|
|
178
|
+
if (stateType) unsetPointerState(leaf, stateType); else if (!core.isUndefined(stateName)) unsetState(leaf, stateName);
|
|
179
|
+
if (leaf.isBranch) unsetChildrenState(leaf.children, stateType, stateName);
|
|
231
180
|
}
|
|
232
181
|
}
|
|
233
|
-
|
|
234
182
|
function updateEventStyle(leaf, eventType) {
|
|
235
183
|
switch (eventType) {
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
184
|
+
case core.PointerEvent.ENTER:
|
|
185
|
+
setPointerState(leaf, "hoverStyle");
|
|
186
|
+
break;
|
|
187
|
+
|
|
188
|
+
case core.PointerEvent.LEAVE:
|
|
189
|
+
unsetPointerState(leaf, "hoverStyle");
|
|
190
|
+
break;
|
|
191
|
+
|
|
192
|
+
case core.PointerEvent.DOWN:
|
|
193
|
+
setPointerState(leaf, "pressStyle");
|
|
194
|
+
break;
|
|
195
|
+
|
|
196
|
+
case core.PointerEvent.UP:
|
|
197
|
+
unsetPointerState(leaf, "pressStyle");
|
|
198
|
+
break;
|
|
248
199
|
}
|
|
249
200
|
}
|
|
250
|
-
|
|
251
201
|
function checkPointerState(fnName, leaf, button) {
|
|
252
202
|
let find;
|
|
253
203
|
const interaction = leaf.leafer ? leaf.leafer.interaction : null;
|
|
@@ -255,8 +205,7 @@ this.LeaferIN.state = (function (exports, core) {
|
|
|
255
205
|
find = interaction[fnName](leaf);
|
|
256
206
|
if (!find && button) {
|
|
257
207
|
const parentButton = findParentButton(leaf, button);
|
|
258
|
-
if (parentButton)
|
|
259
|
-
find = interaction[fnName](parentButton);
|
|
208
|
+
if (parentButton) find = interaction[fnName](parentButton);
|
|
260
209
|
}
|
|
261
210
|
}
|
|
262
211
|
return find;
|
|
@@ -265,8 +214,7 @@ this.LeaferIN.state = (function (exports, core) {
|
|
|
265
214
|
let find = leaf[attrName];
|
|
266
215
|
if (!find && button) {
|
|
267
216
|
const parentButton = findParentButton(leaf, button);
|
|
268
|
-
if (parentButton)
|
|
269
|
-
find = parentButton[attrName];
|
|
217
|
+
if (parentButton) find = parentButton[attrName];
|
|
270
218
|
}
|
|
271
219
|
return find;
|
|
272
220
|
}
|
|
@@ -274,13 +222,11 @@ this.LeaferIN.state = (function (exports, core) {
|
|
|
274
222
|
let find = leaf.states[stateName];
|
|
275
223
|
if (!find && button) {
|
|
276
224
|
const parentButton = findParentButton(leaf, button);
|
|
277
|
-
if (parentButton)
|
|
278
|
-
find = parentButton.states[stateName];
|
|
225
|
+
if (parentButton) find = parentButton.states[stateName];
|
|
279
226
|
}
|
|
280
227
|
return !!find;
|
|
281
228
|
}
|
|
282
|
-
|
|
283
|
-
core.Plugin.add('state');
|
|
229
|
+
core.Plugin.add("state");
|
|
284
230
|
core.State.animateExcludes = {
|
|
285
231
|
animation: 1,
|
|
286
232
|
animationOut: 1,
|
|
@@ -297,62 +243,78 @@ this.LeaferIN.state = (function (exports, core) {
|
|
|
297
243
|
disabledStyle: 1,
|
|
298
244
|
placeholderStyle: 1
|
|
299
245
|
};
|
|
300
|
-
core.State.isState = function
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
core.State.
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
core.State.
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
core.State.
|
|
246
|
+
core.State.isState = function(state, leaf, button) {
|
|
247
|
+
return checkState(state, leaf, button);
|
|
248
|
+
};
|
|
249
|
+
core.State.isSelected = function(leaf, button) {
|
|
250
|
+
return checkFixedState("selected", leaf, button);
|
|
251
|
+
};
|
|
252
|
+
core.State.isDisabled = function(leaf, button) {
|
|
253
|
+
return checkFixedState("disabled", leaf, button);
|
|
254
|
+
};
|
|
255
|
+
core.State.isFocus = function(leaf, button) {
|
|
256
|
+
return checkPointerState("isFocus", leaf, button);
|
|
257
|
+
};
|
|
258
|
+
core.State.isHover = function(leaf, button) {
|
|
259
|
+
return checkPointerState("isHover", leaf, button);
|
|
260
|
+
};
|
|
261
|
+
core.State.isPress = function(leaf, button) {
|
|
262
|
+
return checkPointerState("isPress", leaf, button);
|
|
263
|
+
};
|
|
264
|
+
core.State.isPlacehold = function(leaf, _button) {
|
|
265
|
+
return leaf.__.__isPlacehold;
|
|
266
|
+
};
|
|
267
|
+
core.State.isDrag = function(leaf, button) {
|
|
268
|
+
return checkPointerState("isDrag", leaf, button);
|
|
269
|
+
};
|
|
270
|
+
core.State.setStyleName = function(leaf, stateType, value) {
|
|
271
|
+
value ? setState(leaf, stateType, leaf[stateType]) : unsetState(leaf, stateType, leaf[stateType]);
|
|
272
|
+
};
|
|
273
|
+
core.State.set = function(leaf, stateName) {
|
|
274
|
+
const style = leaf.states[stateName];
|
|
275
|
+
style ? setState(leaf, stateName, style) : unsetState(leaf, stateName, style);
|
|
276
|
+
};
|
|
310
277
|
core.State.getStyle = getStyle;
|
|
311
278
|
core.State.updateStyle = updateStyle;
|
|
312
279
|
core.State.updateEventStyle = updateEventStyle;
|
|
313
280
|
const ui = core.UI.prototype;
|
|
314
|
-
core.UI.addAttr(
|
|
315
|
-
core.UI.addAttr(
|
|
316
|
-
core.UI.addAttr(
|
|
317
|
-
core.UI.addAttr(
|
|
318
|
-
core.UI.addAttr(
|
|
319
|
-
core.UI.addAttr(
|
|
320
|
-
core.UI.addAttr(
|
|
321
|
-
core.UI.addAttr(
|
|
322
|
-
core.UI.addAttr(
|
|
323
|
-
core.UI.addAttr(
|
|
324
|
-
core.UI.addAttr(
|
|
325
|
-
core.UI.addAttr(
|
|
326
|
-
ui.focus = function
|
|
281
|
+
core.UI.addAttr("selected", false, stateType, "selectedStyle");
|
|
282
|
+
core.UI.addAttr("disabled", false, stateType, "disabledStyle");
|
|
283
|
+
core.UI.addAttr("states", {}, stateStyleType);
|
|
284
|
+
core.UI.addAttr("state", "", stateType);
|
|
285
|
+
core.UI.addAttr("normalStyle", undefined, core.dataType);
|
|
286
|
+
core.UI.addAttr("hoverStyle", undefined, stateStyleType);
|
|
287
|
+
core.UI.addAttr("pressStyle", undefined, stateStyleType);
|
|
288
|
+
core.UI.addAttr("focusStyle", undefined, stateStyleType);
|
|
289
|
+
core.UI.addAttr("selectedStyle", undefined, stateStyleType);
|
|
290
|
+
core.UI.addAttr("disabledStyle", undefined, stateStyleType);
|
|
291
|
+
core.UI.addAttr("placeholderStyle", undefined, stateStyleType);
|
|
292
|
+
core.UI.addAttr("button", false, core.dataType);
|
|
293
|
+
ui.focus = function(value = true) {
|
|
327
294
|
this.waitLeafer(() => {
|
|
328
|
-
let { focusData
|
|
295
|
+
let {focusData: focusData} = this.app.interaction;
|
|
329
296
|
if (value) {
|
|
330
|
-
if (focusData)
|
|
331
|
-
focusData.focus(false);
|
|
297
|
+
if (focusData) focusData.focus(false);
|
|
332
298
|
focusData = this;
|
|
333
|
-
}
|
|
334
|
-
else
|
|
335
|
-
focusData = null;
|
|
299
|
+
} else focusData = null;
|
|
336
300
|
this.app.interaction.focusData = focusData;
|
|
337
|
-
value ? setPointerState(this,
|
|
301
|
+
value ? setPointerState(this, "focusStyle") : unsetPointerState(this, "focusStyle");
|
|
338
302
|
});
|
|
339
303
|
};
|
|
340
|
-
ui.updateState = function
|
|
341
|
-
core.State.updateStyle(this, undefined,
|
|
304
|
+
ui.updateState = function() {
|
|
305
|
+
core.State.updateStyle(this, undefined, "in");
|
|
342
306
|
};
|
|
343
|
-
const text = core.Text.prototype, textKey =
|
|
344
|
-
core.defineKey(text, textKey, Object.assign(Object.assign({}, core.getDescriptor(text, textKey)), {
|
|
307
|
+
const text = core.Text.prototype, textKey = "text";
|
|
308
|
+
core.defineKey(text, textKey, Object.assign(Object.assign({}, core.getDescriptor(text, textKey)), {
|
|
309
|
+
set(value) {
|
|
345
310
|
const t = this, oldValue = t.text;
|
|
346
311
|
if (t.__setAttr(textKey, value)) {
|
|
347
312
|
core.doBoundsType(t);
|
|
348
|
-
if (t.placeholderStyle && t.placeholder && (oldValue ===
|
|
349
|
-
t.__layout.stateStyleChanged = true;
|
|
313
|
+
if (t.placeholderStyle && t.placeholder && (oldValue === "" || value === "")) t.__layout.stateStyleChanged = true;
|
|
350
314
|
}
|
|
351
|
-
}
|
|
352
|
-
|
|
315
|
+
}
|
|
316
|
+
}));
|
|
353
317
|
exports.stateStyleType = stateStyleType;
|
|
354
318
|
exports.stateType = stateType;
|
|
355
|
-
|
|
356
319
|
return exports;
|
|
357
|
-
|
|
358
|
-
})({}, LeaferUI);
|
|
320
|
+
}({}, LeaferUI);
|