From dc854043c715cedcb0d9f04584f8c7819bb462fa Mon Sep 17 00:00:00 2001 From: sarahliu Date: Sat, 2 Apr 2022 15:08:30 +0800 Subject: [PATCH 1/2] =?UTF-8?q?mpx=E8=BD=AC=E5=8C=96=E5=BF=AB=E6=89=8B?= =?UTF-8?q?=E5=B0=8F=E7=A8=8B=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .eslintrc.js | 1 + packages/api-proxy/src/common/js/utils.js | 4 +- packages/core/@types/global.d.ts | 2 +- packages/core/@types/index.d.ts | 2 +- packages/core/src/convertor/convertor.js | 4 +- packages/core/src/convertor/getConvertMode.js | 3 +- packages/core/src/convertor/wxToKs.js | 18 ++++++ packages/core/src/helper/env.js | 2 + .../builtInMixins/renderHelperMixin.js | 6 +- packages/webpack-plugin/lib/config.js | 58 +++++++++++++++++++ packages/webpack-plugin/lib/file-loader.js | 2 +- packages/webpack-plugin/lib/loader.js | 2 +- .../lib/platform/json/wx/index.js | 2 +- .../template/wx/component-config/ad.js | 8 ++- .../template/wx/component-config/camera.js | 4 +- .../template/wx/component-config/canvas.js | 18 +++++- .../wx/component-config/cover-image.js | 5 ++ .../template/wx/component-config/form.js | 5 +- .../template/wx/component-config/input.js | 6 +- .../wx/component-config/movable-view.js | 4 +- .../template/wx/component-config/progress.js | 13 ++++- .../wx/component-config/scroll-view.js | 9 ++- .../template/wx/component-config/slider.js | 8 +++ .../template/wx/component-config/swiper.js | 6 +- .../template/wx/component-config/text.js | 5 +- .../template/wx/component-config/textarea.js | 6 +- .../wx/component-config/unsupported.js | 3 +- .../template/wx/component-config/video.js | 10 ++++ .../lib/platform/template/wx/index.js | 9 ++- .../lib/template-compiler/bind-this.js | 2 +- .../lib/template-compiler/compiler.js | 15 +++-- .../lib/template-compiler/index.js | 2 +- 32 files changed, 210 insertions(+), 34 deletions(-) create mode 100644 packages/core/src/convertor/wxToKs.js diff --git a/.eslintrc.js b/.eslintrc.js index d8d9a6d928..975fb0ed43 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -18,6 +18,7 @@ module.exports = { jd: 'readonly', qa: 'readonly', dd: 'readonly', + ks: 'readonly', Component: 'readonly', Page: 'readonly', App: 'readonly', diff --git a/packages/api-proxy/src/common/js/utils.js b/packages/api-proxy/src/common/js/utils.js index 63097f346f..7fdb85c908 100644 --- a/packages/api-proxy/src/common/js/utils.js +++ b/packages/api-proxy/src/common/js/utils.js @@ -46,7 +46,7 @@ const handleSuccess = (opts, getOptions = noop, thisObj) => { function genFromMap () { const result = {} - const platforms = ['wx', 'ali', 'swan', 'qq', 'tt', 'web', 'qa', 'jd', 'dd'] + const platforms = ['wx', 'ali', 'swan', 'qq', 'tt', 'web', 'qa', 'jd', 'dd', 'ks'] platforms.forEach((platform) => { result[`__mpx_src_mode_${platform}__`] = platform }) @@ -71,6 +71,8 @@ function getEnvObj () { return qa case 'dd': return dd + case 'ks': + return ks } } diff --git a/packages/core/@types/global.d.ts b/packages/core/@types/global.d.ts index cc7ce219d7..c68ddd1456 100644 --- a/packages/core/@types/global.d.ts +++ b/packages/core/@types/global.d.ts @@ -1,5 +1,5 @@ // declaration for mpx mode -declare let __mpx_mode__: 'wx' | 'ali' | 'swan' | 'qq' | 'tt' | 'web' | 'dd' | 'qa' | 'jd' +declare let __mpx_mode__: 'wx' | 'ali' | 'swan' | 'qq' | 'tt' | 'web' | 'dd' | 'qa' | 'jd' | 'ks' // declaration for mpx env declare let __mpx_env__: string diff --git a/packages/core/@types/index.d.ts b/packages/core/@types/index.d.ts index ca46d77095..e7c9605555 100644 --- a/packages/core/@types/index.d.ts +++ b/packages/core/@types/index.d.ts @@ -314,7 +314,7 @@ interface MpxConfig { webRouteConfig: object } -type SupportedMode = 'wx' | 'ali' | 'qq' | 'swan' | 'tt' | 'web' | 'qa' +type SupportedMode = 'wx' | 'ali' | 'qq' | 'swan' | 'tt' | 'web' | 'qa' | 'ks' interface ImplementOptions { modes?: Array diff --git a/packages/core/src/convertor/convertor.js b/packages/core/src/convertor/convertor.js index 0dc665d1c6..d02be82bf7 100644 --- a/packages/core/src/convertor/convertor.js +++ b/packages/core/src/convertor/convertor.js @@ -11,6 +11,7 @@ import wxToQqRule from './wxToQq' import wxToTtRule from './wxToTt' import wxToDdRule from './wxToDd' import wxToJdRule from './wxToJd' +import wxToKsRule from './wxToKs' // 根据当前环境获取的默认生命周期信息 let lifecycleInfo @@ -55,7 +56,8 @@ const rulesMap = { wxToQq: { ...defaultConvertRule, ...wxToQqRule }, wxToTt: { ...defaultConvertRule, ...wxToTtRule }, wxToDd: { ...defaultConvertRule, ...wxToDdRule }, - wxToJd: { ...defaultConvertRule, ...wxToJdRule } + wxToJd: { ...defaultConvertRule, ...wxToJdRule }, + wxToKs: { ...defaultConvertRule, ...wxToKsRule } } export function getConvertRule (convertMode) { diff --git a/packages/core/src/convertor/getConvertMode.js b/packages/core/src/convertor/getConvertMode.js index b902f9f358..e77cb75e21 100644 --- a/packages/core/src/convertor/getConvertMode.js +++ b/packages/core/src/convertor/getConvertMode.js @@ -5,7 +5,8 @@ const convertModes = { 'wx-qq': 'wxToQq', 'wx-tt': 'wxToTt', 'wx-jd': 'wxToJd', - 'wx-dd': 'wxToDd' + 'wx-dd': 'wxToDd', + 'wx-ks':'wxToKs' } export function getConvertMode (srcMode) { diff --git a/packages/core/src/convertor/wxToKs.js b/packages/core/src/convertor/wxToKs.js new file mode 100644 index 0000000000..c770bd6f5c --- /dev/null +++ b/packages/core/src/convertor/wxToKs.js @@ -0,0 +1,18 @@ +const BEHAVIORS_MAP = { + 'wx://form-field': 'ks://form-field', + 'wx://form-field-group': 'ks://form-field-group', + 'wx://form-field-button': 'ks://form-field-button', + 'wx://component-export': 'ks://component-export' +} + +export default { + convert (options) { + if (options.behaviors) { + options.behaviors.forEach((behavior, idx) => { + if (typeof behavior === 'string' && BEHAVIORS_MAP[behavior]) { + options.behaviors.splice(idx, 1, BEHAVIORS_MAP[behavior]) + } + }) + } + } +} \ No newline at end of file diff --git a/packages/core/src/helper/env.js b/packages/core/src/helper/env.js index 7d81dff86b..b73dbedf18 100644 --- a/packages/core/src/helper/env.js +++ b/packages/core/src/helper/env.js @@ -16,5 +16,7 @@ export function getEnvObj () { return qa case 'dd': return dd + case 'ks': + return ks } } diff --git a/packages/core/src/platform/builtInMixins/renderHelperMixin.js b/packages/core/src/platform/builtInMixins/renderHelperMixin.js index 42f1889487..426b956a5a 100644 --- a/packages/core/src/platform/builtInMixins/renderHelperMixin.js +++ b/packages/core/src/platform/builtInMixins/renderHelperMixin.js @@ -3,7 +3,7 @@ import { isObject } from '../../helper/utils' export default function renderHelperMixin () { return { methods: { - _i (val, handler) { + i (val, handler) { let i, l, keys, key if (Array.isArray(val) || typeof val === 'string') { for (i = 0, l = val.length; i < l; i++) { @@ -21,11 +21,11 @@ export default function renderHelperMixin () { } } }, - _c (key, value) { + c (key, value) { this.__mpxProxy.renderData[key] = value return value }, - _r () { + r () { this.__mpxProxy.renderWithData() } } diff --git a/packages/webpack-plugin/lib/config.js b/packages/webpack-plugin/lib/config.js index 2f2587f89a..03409ec3b2 100644 --- a/packages/webpack-plugin/lib/config.js +++ b/packages/webpack-plugin/lib/config.js @@ -556,5 +556,63 @@ module.exports = { ref: 'dd:ref', show: 'dd:show' } + }, + ks:{ + typeExtMap: { + json: '.json', + script: '.js', + template: '.ksml', + styles: '.css' + }, + tabBar: { + itemKey: 'list', + iconKey: 'iconPath', + activeIconKey: 'selectedIconPath' + }, + event: { + parseEvent (attr) { + let match = /^(bind|catch|capture-bind|capture-catch):?(.*?)(?:\.(.*))?$/.exec(attr) + if (match) { + return { + prefix: match[1], + eventName: match[2], + modifier: match[3] + } + } + }, + getEvent (eventName, prefix = 'bind') { + return prefix + eventName + }, + defaultModelProp: 'value', + defaultModelEvent: 'input', + defaultModelValuePath: 'value', + shallowStringify (obj) { + let arr = [] + for (let key in obj) { + let value = obj[key] + if (Array.isArray(value)) { + value = `[${value.join(',')}]` + } + arr.push(`${key}:${value}`) + } + return ` {${arr.join(',')}} ` + } + }, + wxs: {}, + directive: { + if: 'ks:if', + elseif: 'ks:elif', + else: 'ks:else', + for: 'ks:for', + dynamicClass: 'class', + dynamicStyle: 'style', + ref: 'ks:ref', + show: 'ks:show', + model: 'ks:model', + modelProp: 'ks:model-prop', + modelEvent: 'ks:model-event', + modelValuePath: 'ks:model-value-path', + modelFilter: 'ks:model-filter' + } } } diff --git a/packages/webpack-plugin/lib/file-loader.js b/packages/webpack-plugin/lib/file-loader.js index 4b7b801ac5..19e7c9862b 100644 --- a/packages/webpack-plugin/lib/file-loader.js +++ b/packages/webpack-plugin/lib/file-loader.js @@ -31,7 +31,7 @@ module.exports = function loader (content, prevOptions) { this._module.addPresentationalDependency(new RecordResourceMapDependency(resourcePath, 'staticResource', outputPath, packageRoot)) } - let publicPath = `__webpack_public_path__ + ${JSON.stringify(url)}` + let publicPath = options.mode === 'ks'&& queryObj?.currentName ==='app' ? JSON.stringify(url) :`__webpack_public_path__ + ${JSON.stringify(url)}` if (options.publicPath) { if (typeof options.publicPath === 'function') { diff --git a/packages/webpack-plugin/lib/loader.js b/packages/webpack-plugin/lib/loader.js index 4f857ce013..6c46dd1b64 100644 --- a/packages/webpack-plugin/lib/loader.js +++ b/packages/webpack-plugin/lib/loader.js @@ -250,7 +250,7 @@ module.exports = function (content) { let ctor = 'App' if (ctorType === 'page') { // swan也默认使用Page构造器 - if (mpx.forceUsePageCtor || mode === 'ali' || mode === 'swan') { + if (mpx.forceUsePageCtor || mode === 'ali' || mode === 'swan' || mode === 'ks') { ctor = 'Page' } else { ctor = 'Component' diff --git a/packages/webpack-plugin/lib/platform/json/wx/index.js b/packages/webpack-plugin/lib/platform/json/wx/index.js index bbb9a31712..2ff6e9b30a 100644 --- a/packages/webpack-plugin/lib/platform/json/wx/index.js +++ b/packages/webpack-plugin/lib/platform/json/wx/index.js @@ -39,7 +39,7 @@ module.exports = function getSpec ({ warn, error }) { } const spec = { - supportedModes: ['ali', 'swan', 'qq', 'tt', 'jd', 'qa', 'dd'], + supportedModes: ['ali', 'swan', 'qq', 'tt', 'jd', 'qa', 'dd', 'ks'], normalizeTest, page: [ { diff --git a/packages/webpack-plugin/lib/platform/template/wx/component-config/ad.js b/packages/webpack-plugin/lib/platform/template/wx/component-config/ad.js index b3fb1a18ad..60848642c9 100644 --- a/packages/webpack-plugin/lib/platform/template/wx/component-config/ad.js +++ b/packages/webpack-plugin/lib/platform/template/wx/component-config/ad.js @@ -8,6 +8,7 @@ module.exports = function ({ print }) { const qqValueWarningLog = print({ platform: 'qq', type: 'value', tag: TAG_NAME, isError: false }) const qqPropLog = print({ platform: 'qq', tag: TAG_NAME, isError: false }) const qqEventLog = print({ platform: 'qq', tag: TAG_NAME, isError: false, type: 'event' }) + const ksPropLog = print({ platform: 'ks', tag: TAG_NAME, isError: false }) return { test: TAG_NAME, props: [ @@ -33,6 +34,10 @@ module.exports = function ({ print }) { baiduValueWarningLog({ name: 'type', value: obj.value }) } return obj + }, + ks (obj) { + obj.name = 'type' + return obj } }, { @@ -42,7 +47,8 @@ module.exports = function ({ print }) { { test: /^(ad-intervals|ad-theme)$/, qq: qqPropLog, - swan: baiduPropLog + swan: baiduPropLog, + ks: ksPropLog } ], event: [ diff --git a/packages/webpack-plugin/lib/platform/template/wx/component-config/camera.js b/packages/webpack-plugin/lib/platform/template/wx/component-config/camera.js index 0d8f8934a0..927c789b83 100644 --- a/packages/webpack-plugin/lib/platform/template/wx/component-config/camera.js +++ b/packages/webpack-plugin/lib/platform/template/wx/component-config/camera.js @@ -13,6 +13,7 @@ module.exports = function ({ print }) { const qqEventLog = print({ platform: 'qq', tag: TAG_NAME, isError: false, type: 'event' }) const qaPropLog = print({ platform: 'qa', tag: TAG_NAME, isError: false }) const qaEventLog = print({ platform: 'qa', tag: TAG_NAME, isError: false, type: 'event' }) + const ksPropLog = print({ platform: 'ks', tag: TAG_NAME, isError: false }) return { test: TAG_NAME, props: [ @@ -46,7 +47,8 @@ module.exports = function ({ print }) { }, { test: /^(resolution|frame-size)$/, - qq: qqPropLog + qq: qqPropLog, + ks: ksPropLog }, { test: /^(frame-size|device-position)$/, diff --git a/packages/webpack-plugin/lib/platform/template/wx/component-config/canvas.js b/packages/webpack-plugin/lib/platform/template/wx/component-config/canvas.js index 0444d0d30c..0b5466b7a8 100644 --- a/packages/webpack-plugin/lib/platform/template/wx/component-config/canvas.js +++ b/packages/webpack-plugin/lib/platform/template/wx/component-config/canvas.js @@ -42,11 +42,27 @@ module.exports = function ({ print }) { 'longtap': 'longTap' } return eventMap[eventName] + }, + ks(eventName){ + const eventMap = { + 'touchstart': 'canvastouchstart', + 'touchmove': 'canvastouchmove', + 'touchend': 'canvastouchend', + 'touchcancel': 'canvastouchcancel', + 'longtap': 'canvaslongtap ' + } + return eventMap[eventName] } }, { test: /^(error)$/, - ali: aliEventLog + ali: aliEventLog, + ks(eventName){ + const eventMap = { + 'error': 'canvaserror', + } + return eventMap[eventName] + } }, { test: /^(longtap|error)$/, diff --git a/packages/webpack-plugin/lib/platform/template/wx/component-config/cover-image.js b/packages/webpack-plugin/lib/platform/template/wx/component-config/cover-image.js index 7dd4339e81..b70e2cc63e 100644 --- a/packages/webpack-plugin/lib/platform/template/wx/component-config/cover-image.js +++ b/packages/webpack-plugin/lib/platform/template/wx/component-config/cover-image.js @@ -2,6 +2,7 @@ const TAG_NAME = 'cover-image' module.exports = function ({ print }) { const aliEventLog = print({ platform: 'ali', tag: TAG_NAME, isError: false, type: 'event' }) + const ksPropLog = print({ platform: 'ks', tag: TAG_NAME, isError: false }) return { test: TAG_NAME, web (tag, { el }) { @@ -17,6 +18,10 @@ module.exports = function ({ print }) { web (prop, { el }) { el.isBuiltIn = true } + }, + { + test:/^referrer-policy$/, + ks:ksPropLog } ], event: [ diff --git a/packages/webpack-plugin/lib/platform/template/wx/component-config/form.js b/packages/webpack-plugin/lib/platform/template/wx/component-config/form.js index ae0e558dc3..a194718aab 100644 --- a/packages/webpack-plugin/lib/platform/template/wx/component-config/form.js +++ b/packages/webpack-plugin/lib/platform/template/wx/component-config/form.js @@ -7,7 +7,7 @@ module.exports = function ({ print }) { const jdPropLog = print({ platform: 'jd', tag: TAG_NAME, isError: false }) const webPropLog = print({ platform: 'web', tag: TAG_NAME, isError: false }) const qaPropLog = print({ platform: 'qa', tag: TAG_NAME, isError: false }) - + const ksPropLog = print({ platform: 'ks', tag: TAG_NAME, isError: false }) return { test: TAG_NAME, web (tag, { el }) { @@ -26,7 +26,8 @@ module.exports = function ({ print }) { { test: /^(report-submit|report-submit-timeout)$/, web: webPropLog, - qa: qaPropLog + qa: qaPropLog, + ks: ksPropLog } ] } diff --git a/packages/webpack-plugin/lib/platform/template/wx/component-config/input.js b/packages/webpack-plugin/lib/platform/template/wx/component-config/input.js index aa99d113d7..7e8a3a599e 100644 --- a/packages/webpack-plugin/lib/platform/template/wx/component-config/input.js +++ b/packages/webpack-plugin/lib/platform/template/wx/component-config/input.js @@ -13,7 +13,7 @@ module.exports = function ({ print }) { const webEventLog = print({ platform: 'web', tag: TAG_NAME, isError: false, type: 'event' }) const webValueLog = print({ platform: 'web', tag: TAG_NAME, isError: false, type: 'value' }) const qaPropLog = print({ platform: 'qa', tag: TAG_NAME, isError: false }) - + const ksPropLog = print({ platform: 'ks', tag: TAG_NAME, isError: false }) return { test: TAG_NAME, web (tag, { el }) { @@ -37,6 +37,10 @@ module.exports = function ({ print }) { test: /^(hold-keyboard)$/, jd: jdPropLog }, + { + test: /^(placeholder-class|cursor-spacing|always-embed|cursor|selection-start|selection-end|safe-password-cert-path|safe-password-length|safe-password-time-stamp|safe-password-nonce|safe-password-salt|safe-password-custom-hash)$/, + ks: ksPropLog + }, { test: 'type', web (prop) { diff --git a/packages/webpack-plugin/lib/platform/template/wx/component-config/movable-view.js b/packages/webpack-plugin/lib/platform/template/wx/component-config/movable-view.js index f772180f75..354cb7a2a2 100644 --- a/packages/webpack-plugin/lib/platform/template/wx/component-config/movable-view.js +++ b/packages/webpack-plugin/lib/platform/template/wx/component-config/movable-view.js @@ -3,6 +3,7 @@ const TAG_NAME = 'movable-view' module.exports = function ({ print }) { const aliEventLog = print({ platform: 'ali', tag: TAG_NAME, isError: false, type: 'event' }) const qaPropLog = print({ platform: 'qa', tag: TAG_NAME, isError: false }) + const ksEventLog = print({ platform: 'ks', tag: TAG_NAME, isError: false, type: 'event' }) return { test: TAG_NAME, web (tag, { el }) { @@ -18,7 +19,8 @@ module.exports = function ({ print }) { event: [ { test: /^(htouchmove|vtouchmove)$/, - ali: aliEventLog + ali: aliEventLog, + ks: ksEventLog } ] } diff --git a/packages/webpack-plugin/lib/platform/template/wx/component-config/progress.js b/packages/webpack-plugin/lib/platform/template/wx/component-config/progress.js index 208eb5ce64..9f711bc004 100644 --- a/packages/webpack-plugin/lib/platform/template/wx/component-config/progress.js +++ b/packages/webpack-plugin/lib/platform/template/wx/component-config/progress.js @@ -10,7 +10,7 @@ module.exports = function ({ print }) { const jdPropLog = print({ platform: 'jd', tag: TAG_NAME, isError: false }) const jdEventLog = print({ platform: 'jd', tag: TAG_NAME, isError: false, type: 'event' }) const qqPropLog = print({ platform: 'qq', tag: TAG_NAME, isError: false }) - + const ksEventLog = print({ platform: 'ks', tag: TAG_NAME, isError: false, type: 'event' }) return { test: TAG_NAME, web (tag, { el }) { @@ -43,6 +43,14 @@ module.exports = function ({ print }) { } obj.name = propsMap[obj.name] return obj + }, + ks (obj) { + const propsMap = { + 'activeColor': 'active-color', + 'backgroundColor': 'background-color' + } + obj.name = propsMap[obj.name] + return obj } }, { @@ -64,7 +72,8 @@ module.exports = function ({ print }) { ali: aliEventLog, swan: baiduEventLog, tt: ttEventLog, - jd: jdEventLog + jd: jdEventLog, + ks: ksEventLog } ] } diff --git a/packages/webpack-plugin/lib/platform/template/wx/component-config/scroll-view.js b/packages/webpack-plugin/lib/platform/template/wx/component-config/scroll-view.js index d84eac3821..3a7a747c8f 100644 --- a/packages/webpack-plugin/lib/platform/template/wx/component-config/scroll-view.js +++ b/packages/webpack-plugin/lib/platform/template/wx/component-config/scroll-view.js @@ -12,6 +12,8 @@ module.exports = function ({ print }) { const aliEventLog = print({ platform: 'ali', tag: TAG_NAME, isError: false, type: 'event' }) const qqEventLog = print({ platform: 'qq', tag: TAG_NAME, isError: false, type: 'event' }) const qqPropLog = print({ platform: 'qq', tag: TAG_NAME, isError: false }) + const ksPropLog = print({ platform: 'ks', tag: TAG_NAME, isError: false }) + const ksEventLog = print({ platform: 'ks', tag: TAG_NAME, isError: false, type:'event' }) return { test: TAG_NAME, @@ -39,6 +41,10 @@ module.exports = function ({ print }) { { test: /^(enable-back-to-top|enable-flex|scroll-anchoring|enhanced|bounces|show-scrollbar|paging-enabled|fast-deceleration|binddragstart|binddragging|binddragend)$/, qa: qaPropLog + }, + { + test:/^(refresher-enabled|refresher-threshold|refresher-default-style|refresher-background|refresher-triggered|enhanced|bounces|show-scrollbar|paging-enabled|fast-deceleration)$/, + ks:ksPropLog } ], event: [ @@ -62,7 +68,8 @@ module.exports = function ({ print }) { ali: aliEventLog, tt: ttEventLog, qq: qqEventLog, - swan: baiduEventLog + swan: baiduEventLog, + ks:ksEventLog } ] } diff --git a/packages/webpack-plugin/lib/platform/template/wx/component-config/slider.js b/packages/webpack-plugin/lib/platform/template/wx/component-config/slider.js index c93d0b4468..e7c60b8d4c 100644 --- a/packages/webpack-plugin/lib/platform/template/wx/component-config/slider.js +++ b/packages/webpack-plugin/lib/platform/template/wx/component-config/slider.js @@ -48,6 +48,14 @@ module.exports = function ({ print }) { } obj.name = propsMap[obj.name] return obj + }, + ks (obj) { + const propsMap = { + 'activeColor': 'active-color', + 'backgroundColor': 'background-color' + } + obj.name = propsMap[obj.name] + return obj } } ] diff --git a/packages/webpack-plugin/lib/platform/template/wx/component-config/swiper.js b/packages/webpack-plugin/lib/platform/template/wx/component-config/swiper.js index 310934ac1d..1d865973a9 100644 --- a/packages/webpack-plugin/lib/platform/template/wx/component-config/swiper.js +++ b/packages/webpack-plugin/lib/platform/template/wx/component-config/swiper.js @@ -10,7 +10,7 @@ module.exports = function ({ print }) { const jdEventLog = print({ platform: 'jd', tag: TAG_NAME, isError: false, type: 'event' }) const jdPropLog = print({ platform: 'jd', tag: TAG_NAME, isError: false }) const qaPropLog = print({ platform: 'qa', tag: TAG_NAME, isError: false }) - + const ksPropLog = print({ platform: 'ks', tag: TAG_NAME, isError: false }) return { test: TAG_NAME, web (tag, { el }) { @@ -45,6 +45,10 @@ module.exports = function ({ print }) { { test: /^(snap-to-edge|easing-function)$/, qa: qaPropLog + }, + { + test: /^(snap-to-edge)$/, + ks: ksPropLog } ], event: [ diff --git a/packages/webpack-plugin/lib/platform/template/wx/component-config/text.js b/packages/webpack-plugin/lib/platform/template/wx/component-config/text.js index 838c44f9ba..c427b3f2e1 100644 --- a/packages/webpack-plugin/lib/platform/template/wx/component-config/text.js +++ b/packages/webpack-plugin/lib/platform/template/wx/component-config/text.js @@ -6,7 +6,7 @@ module.exports = function ({ print }) { const aliPropLog = print({ platform: 'ali', tag: TAG_NAME, isError: false }) const ttPropLog = print({ platform: 'bytedance', tag: TAG_NAME, isError: false }) const qqPropLog = print({ platform: 'qq', tag: TAG_NAME, isError: false }) - + const ksPropLog = print({ platform: 'ks', tag: TAG_NAME, isError: false }) return { test: TAG_NAME, web (tag, { el }) { @@ -29,7 +29,8 @@ module.exports = function ({ print }) { ali: aliPropLog, tt: ttPropLog, qq: qqPropLog, - qa: qaPropLog + qa: qaPropLog, + ks: ksPropLog }, { test: /^(selectable|space|decode|use-built-in)$/, diff --git a/packages/webpack-plugin/lib/platform/template/wx/component-config/textarea.js b/packages/webpack-plugin/lib/platform/template/wx/component-config/textarea.js index b009d67527..2b08a44561 100644 --- a/packages/webpack-plugin/lib/platform/template/wx/component-config/textarea.js +++ b/packages/webpack-plugin/lib/platform/template/wx/component-config/textarea.js @@ -14,7 +14,7 @@ module.exports = function ({ print }) { const qqEventLog = print({ platform: 'qq', tag: TAG_NAME, isError: false, type: 'event' }) const qqPropLog = print({ platform: 'qq', tag: TAG_NAME, isError: false }) const baiduPropLog = print({ platform: 'baidu', tag: TAG_NAME, isError: false }) - + const ksPropLog = print({ platform: 'ks', tag: TAG_NAME, isError: false }) return { test: TAG_NAME, web (tag, { el }) { @@ -47,6 +47,10 @@ module.exports = function ({ print }) { { test: /^(fixed|cursor-spacing|show-confirm-bar|adjust-position|hold-keyboard|auto-height)$/, qa: qaPropLog + }, + { + test:/^(placeholder-class|cursor-spacing|cursor|show-confirm-bar|selection-start|selection-end|disable-default-padding)$/, + ks: ksPropLog } ], event: [ diff --git a/packages/webpack-plugin/lib/platform/template/wx/component-config/unsupported.js b/packages/webpack-plugin/lib/platform/template/wx/component-config/unsupported.js index 2ca7206cae..f9dffe09ba 100644 --- a/packages/webpack-plugin/lib/platform/template/wx/component-config/unsupported.js +++ b/packages/webpack-plugin/lib/platform/template/wx/component-config/unsupported.js @@ -10,7 +10,8 @@ const TT_UNSUPPORTED_TAG_NAME_ARR = ['movable-view', 'cover-image', 'cover-view' const JD_UNSUPPORTED_TAG_NAME_ARR = ['functional-page-navigator', 'live-pusher', 'live-player', 'rich-text', 'audio', 'video', 'camera'] // 快应用不支持的标签集合 const QA_UNSUPPORTED_TAG_NAME_ARR = ['movable-view', 'movable-area', 'open-data', 'official-account', 'editor', 'functional-page-navigator', 'live-player', 'live-pusher', 'ad', 'cover-image'] - +// 快手小程序不支持的标签集合 +const KS_UNSUPPORTED_TAG_NAME_ARR = ['functional-page-navigator', 'live-pusher', 'live-player'] /** * @param {function(object): function} print * @return {array} diff --git a/packages/webpack-plugin/lib/platform/template/wx/component-config/video.js b/packages/webpack-plugin/lib/platform/template/wx/component-config/video.js index 819c6df605..23da60dfb7 100644 --- a/packages/webpack-plugin/lib/platform/template/wx/component-config/video.js +++ b/packages/webpack-plugin/lib/platform/template/wx/component-config/video.js @@ -11,6 +11,8 @@ module.exports = function ({ print }) { const aliEventLogError = print({ platform: 'ali', tag: TAG_NAME, isError: false, type: 'event' }) const qaPropLog = print({ platform: 'qa', tag: TAG_NAME, isError: false }) const qaEventLogError = print({ platform: 'qa', tag: TAG_NAME, isError: false, type: 'event' }) + const ksPropLog = print({ platform: 'ks', tag: TAG_NAME, isError: false }) + const ksEventLogError = print({ platform: 'ks', tag: TAG_NAME, isError: false, type: 'event' }) return { test: TAG_NAME, web (tag, { el }) { @@ -48,6 +50,10 @@ module.exports = function ({ print }) { { test: /^(duration|danmu-list|danmu-btn|enable-danmu|muted|initial-time|page-gesture|direction|show-progress|show-center-play-btn|enable-progress-gesture|show-mute-btn|enable-play-gesture|auto-pause-if-navigate|auto-pause-if-open-native|vslide-gesture|vslide-gesture-in-fullscreen|ad-unit-id|poster-for-crawler|show-casting-button|picture-in-picture-mode|picture-in-picture-show-progress|enable-auto-rotation|show-screen-lock-button|show-snapshot-button)$/, qa: qaPropLog + }, + { + test:/^(enable-auto-rotation|show-snapshot-button|show-background-playback-button|background-poster|referrer-policy|is-drm|provision-url|certificate-url|license-url)$/, + ks: ksPropLog } ], event: [ @@ -82,6 +88,10 @@ module.exports = function ({ print }) { { test: /^(progress|enterpictureinpicture|leavepictureinpicture|controlstoggle|loadedmetadata|seekcomplete)$/, qa: qaEventLogError + }, + { + test:/^(waiting|progress|loadedmetadata|controlstoggle|enterpictureinpicture|leavepictureinpicture|seekcomplete)$/, + ks: ksEventLogError } ] } diff --git a/packages/webpack-plugin/lib/platform/template/wx/index.js b/packages/webpack-plugin/lib/platform/template/wx/index.js index 07a96aedd1..5059428ac4 100644 --- a/packages/webpack-plugin/lib/platform/template/wx/index.js +++ b/packages/webpack-plugin/lib/platform/template/wx/index.js @@ -10,7 +10,7 @@ const normalize = require('../../../utils/normalize') module.exports = function getSpec ({ warn, error }) { const spec = { - supportedModes: ['ali', 'swan', 'qq', 'tt', 'web', 'qa', 'jd', 'dd'], + supportedModes: ['ali', 'swan', 'qq', 'tt', 'web', 'qa', 'jd', 'dd', 'ks'], // props预处理 preProps: [], // props后处理 @@ -265,6 +265,13 @@ module.exports = function getSpec ({ warn, error }) { value } }, + ks ({ name, value }) { + const dir = this.test.exec(name)[1] + return { + name: 'ks:' + dir, + value + } + }, web ({ name, value }) { let dir = this.test.exec(name)[1] const parsed = parseMustache(value) diff --git a/packages/webpack-plugin/lib/template-compiler/bind-this.js b/packages/webpack-plugin/lib/template-compiler/bind-this.js index 3643e1f9da..c0da8ea99a 100644 --- a/packages/webpack-plugin/lib/template-compiler/bind-this.js +++ b/packages/webpack-plugin/lib/template-compiler/bind-this.js @@ -113,7 +113,7 @@ module.exports = { MemberExpression: { exit (path) { if (path.collectPath) { - path.replaceWith(t.callExpression(t.memberExpression(t.thisExpression(), t.identifier('_c')), [path.collectPath, path.node])) + path.replaceWith(t.callExpression(t.memberExpression(t.thisExpression(), t.identifier('c')), [path.collectPath, path.node])) delete path.collectPath } } diff --git a/packages/webpack-plugin/lib/template-compiler/compiler.js b/packages/webpack-plugin/lib/template-compiler/compiler.js index bc198e4e03..d0246b9288 100644 --- a/packages/webpack-plugin/lib/template-compiler/compiler.js +++ b/packages/webpack-plugin/lib/template-compiler/compiler.js @@ -1194,7 +1194,7 @@ function processBindEvent (el, options) { if (!isEmptyObject(eventConfigMap)) { addAttrs(el, [{ name: 'data-eventconfigs', - value: `{{${config[mode].event.shallowStringify(eventConfigMap)}}}` + value: mode === "ks" ? config[mode].event.shallowStringify(eventConfigMap) : `{{${config[mode].event.shallowStringify(eventConfigMap)}}}` }]) } } @@ -1233,7 +1233,7 @@ function parseMustache (raw = '') { const funcNameREG = new RegExp(`${i18nFuncName}\\(`, 'g') if (funcNameRE.test(exp)) { if (i18n.useComputed) { - const i18nInjectComputedKey = `_i${i18nInjectableComputed.length + 1}` + const i18nInjectComputedKey = `i${i18nInjectableComputed.length + 1}` i18nInjectableComputed.push(`${i18nInjectComputedKey}: function(){\nreturn ${exp.trim()}}`) exp = i18nInjectComputedKey } else { @@ -1410,6 +1410,7 @@ function addWxsContent (meta, module, content) { } function postProcessWxs (el, meta) { + if(mode === 'ks') return if (el.tag === config[mode].wxs.tag) { let module = el.attrsMap[config[mode].wxs.module] if (module) { @@ -1607,6 +1608,7 @@ function processText (el) { // } function injectWxs (meta, module, src) { + if(mode === 'ks') return if (addWxsModule(meta, module, src)) { return } @@ -1624,6 +1626,7 @@ function injectWxs (meta, module, src) { } function processClass (el, meta) { + if(mode === 'ks') return const type = 'class' const needEx = el.tag.startsWith('th-') const targetType = needEx ? 'ex-' + type : type @@ -1661,6 +1664,7 @@ function processClass (el, meta) { } function processStyle (el, meta) { + if(mode === 'ks') return const type = 'style' const targetType = el.tag.startsWith('th-') ? 'ex-' + type : type let dynamicStyle = getAndRemoveAttr(el, config[mode].directive.dynamicStyle).val @@ -1683,7 +1687,8 @@ function processStyle (el, meta) { } function isRealNode (el) { - const virtualNodeTagMap = ['block', 'template', 'import', config[mode].wxs.tag].reduce((map, item) => { + let tagList = mode === 'ks' ? ['block', 'template', 'import'] : ['block', 'template', 'import', config[mode].wxs.tag] + const virtualNodeTagMap = tagList.reduce((map, item) => { map[item] = true return map }, {}) @@ -1957,7 +1962,7 @@ function postProcessTemplate (el) { } } -const isValidMode = makeMap('wx,ali,swan,tt,qq,web,qa,jd,dd') +const isValidMode = makeMap('wx,ali,swan,tt,qq,web,qa,jd,dd,ks') const wrapRE = /^\((.*)\)$/ @@ -2352,7 +2357,7 @@ function genFor (node) { node.forProcessed = true let index = node.for.index || 'index' let item = node.for.item || 'item' - return `this._i(${node.for.exp}, function(${item},${index}){\n${genNode(node)}});\n` + return `this.i(${node.for.exp}, function(${item},${index}){\n${genNode(node)}});\n` } function genNode (node) { diff --git a/packages/webpack-plugin/lib/template-compiler/index.js b/packages/webpack-plugin/lib/template-compiler/index.js index 2f61bc9911..6b5e96a207 100644 --- a/packages/webpack-plugin/lib/template-compiler/index.js +++ b/packages/webpack-plugin/lib/template-compiler/index.js @@ -86,7 +86,7 @@ global.currentInject = { moduleId: ${JSON.stringify(moduleId)}, render: function () { ${compiler.genNode(ast)} - this._r(); + this.r(); } };\n` From 6e8f604b1c53cf54a0535141b13cc3476c048c08 Mon Sep 17 00:00:00 2001 From: sarahliu Date: Thu, 7 Apr 2022 21:02:36 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/webpack-plugin/lib/file-loader.js | 2 +- packages/webpack-plugin/lib/json-compiler/index.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/webpack-plugin/lib/file-loader.js b/packages/webpack-plugin/lib/file-loader.js index 19e7c9862b..595c739200 100644 --- a/packages/webpack-plugin/lib/file-loader.js +++ b/packages/webpack-plugin/lib/file-loader.js @@ -31,7 +31,7 @@ module.exports = function loader (content, prevOptions) { this._module.addPresentationalDependency(new RecordResourceMapDependency(resourcePath, 'staticResource', outputPath, packageRoot)) } - let publicPath = options.mode === 'ks'&& queryObj?.currentName ==='app' ? JSON.stringify(url) :`__webpack_public_path__ + ${JSON.stringify(url)}` + let publicPath = queryObj?.noPublicPath ? JSON.stringify(url) :`__webpack_public_path__ + ${JSON.stringify(url)}` if (options.publicPath) { if (typeof options.publicPath === 'function') { diff --git a/packages/webpack-plugin/lib/json-compiler/index.js b/packages/webpack-plugin/lib/json-compiler/index.js index 6fa8fa9693..e3bd4849ce 100644 --- a/packages/webpack-plugin/lib/json-compiler/index.js +++ b/packages/webpack-plugin/lib/json-compiler/index.js @@ -427,14 +427,14 @@ module.exports = function (content) { let itemKey = tabBarCfg.itemKey let iconKey = tabBarCfg.iconKey let activeIconKey = tabBarCfg.activeIconKey - + let noPublicPath = mode === 'ks' if (json.tabBar && json.tabBar[itemKey]) { json.tabBar[itemKey].forEach((item, index) => { if (item[iconKey] && isUrlRequest(item[iconKey])) { - output += `json.tabBar.${itemKey}[${index}].${iconKey} = require("${addQuery(urlToRequest(item[iconKey]), { useLocal: true })}");\n` + output += `json.tabBar.${itemKey}[${index}].${iconKey} = require("${addQuery(urlToRequest(item[iconKey]), { useLocal: true, noPublicPath })}");\n` } if (item[activeIconKey] && isUrlRequest(item[activeIconKey])) { - output += `json.tabBar.${itemKey}[${index}].${activeIconKey} = require("${addQuery(urlToRequest(item[activeIconKey]), { useLocal: true })}");\n` + output += `json.tabBar.${itemKey}[${index}].${activeIconKey} = require("${addQuery(urlToRequest(item[activeIconKey]), { useLocal: true, noPublicPath })}");\n` } }) }