aboutsummaryrefslogtreecommitdiff
path: root/node_modules/vue/src/platforms/weex/util
diff options
context:
space:
mode:
authorruki <waruqi@gmail.com>2018-11-08 00:38:48 +0800
committerruki <waruqi@gmail.com>2018-11-07 21:53:09 +0800
commit26105034da4fcce7ac883c899d781f016559310d (patch)
treec459a5dc4e3aa0972d9919033ece511ce76dd129 /node_modules/vue/src/platforms/weex/util
parent2c77f00f1a7ecb6c8192f9c16d3b2001b254a107 (diff)
downloadxmake-docs-26105034da4fcce7ac883c899d781f016559310d.tar.gz
xmake-docs-26105034da4fcce7ac883c899d781f016559310d.zip
switch to vuepress
Diffstat (limited to 'node_modules/vue/src/platforms/weex/util')
-rw-r--r--node_modules/vue/src/platforms/weex/util/element.js52
-rwxr-xr-xnode_modules/vue/src/platforms/weex/util/index.js40
-rw-r--r--node_modules/vue/src/platforms/weex/util/parser.js60
3 files changed, 152 insertions, 0 deletions
diff --git a/node_modules/vue/src/platforms/weex/util/element.js b/node_modules/vue/src/platforms/weex/util/element.js
new file mode 100644
index 00000000..97e97feb
--- /dev/null
+++ b/node_modules/vue/src/platforms/weex/util/element.js
@@ -0,0 +1,52 @@
+/* @flow */
+
+// These util functions are split into its own file because Rollup cannot drop
+// makeMap() due to potential side effects, so these variables end up
+// bloating the web builds.
+
+import { makeMap } from 'shared/util'
+
+export const isReservedTag = makeMap(
+ 'template,script,style,element,content,slot,link,meta,svg,view,' +
+ 'a,div,img,image,text,span,input,switch,textarea,spinner,select,' +
+ 'slider,slider-neighbor,indicator,canvas,' +
+ 'list,cell,header,loading,loading-indicator,refresh,scrollable,scroller,' +
+ 'video,web,embed,tabbar,tabheader,datepicker,timepicker,marquee,countdown',
+ true
+)
+
+// Elements that you can, intentionally, leave open (and which close themselves)
+// more flexible than web
+export const canBeLeftOpenTag = makeMap(
+ 'web,spinner,switch,video,textarea,canvas,' +
+ 'indicator,marquee,countdown',
+ true
+)
+
+export const isRuntimeComponent = makeMap(
+ 'richtext,transition,transition-group',
+ true
+)
+
+export const isUnaryTag = makeMap(
+ 'embed,img,image,input,link,meta',
+ true
+)
+
+export function mustUseProp (tag: string, type: ?string, name: string): boolean {
+ return false
+}
+
+export function getTagNamespace (tag?: string): string | void { }
+
+export function isUnknownElement (tag?: string): boolean {
+ return false
+}
+
+export function query (el: string | Element, document: Object) {
+ // document is injected by weex factory wrapper
+ const placeholder = document.createComment('root')
+ placeholder.hasAttribute = placeholder.removeAttribute = function () {} // hack for patch
+ document.documentElement.appendChild(placeholder)
+ return placeholder
+}
diff --git a/node_modules/vue/src/platforms/weex/util/index.js b/node_modules/vue/src/platforms/weex/util/index.js
new file mode 100755
index 00000000..8181d70e
--- /dev/null
+++ b/node_modules/vue/src/platforms/weex/util/index.js
@@ -0,0 +1,40 @@
+/* @flow */
+declare var document: WeexDocument;
+
+import { warn } from 'core/util/index'
+
+export const RECYCLE_LIST_MARKER = '@inRecycleList'
+
+// Register the component hook to weex native render engine.
+// The hook will be triggered by native, not javascript.
+export function registerComponentHook (
+ componentId: string,
+ type: string, // hook type, could be "lifecycle" or "instance"
+ hook: string, // hook name
+ fn: Function
+) {
+ if (!document || !document.taskCenter) {
+ warn(`Can't find available "document" or "taskCenter".`)
+ return
+ }
+ if (typeof document.taskCenter.registerHook === 'function') {
+ return document.taskCenter.registerHook(componentId, type, hook, fn)
+ }
+ warn(`Failed to register component hook "${type}@${hook}#${componentId}".`)
+}
+
+// Updates the state of the component to weex native render engine.
+export function updateComponentData (
+ componentId: string,
+ newData: Object | void,
+ callback?: Function
+) {
+ if (!document || !document.taskCenter) {
+ warn(`Can't find available "document" or "taskCenter".`)
+ return
+ }
+ if (typeof document.taskCenter.updateData === 'function') {
+ return document.taskCenter.updateData(componentId, newData, callback)
+ }
+ warn(`Failed to update component data (${componentId}).`)
+}
diff --git a/node_modules/vue/src/platforms/weex/util/parser.js b/node_modules/vue/src/platforms/weex/util/parser.js
new file mode 100644
index 00000000..081908e8
--- /dev/null
+++ b/node_modules/vue/src/platforms/weex/util/parser.js
@@ -0,0 +1,60 @@
+/* @flow */
+
+// import { warn } from 'core/util/index'
+
+// this will be preserved during build
+// $flow-disable-line
+const acorn = require('acorn') // $flow-disable-line
+const walk = require('acorn/dist/walk') // $flow-disable-line
+const escodegen = require('escodegen')
+
+export function nodeToBinding (node: Object): any {
+ switch (node.type) {
+ case 'Literal': return node.value
+ case 'Identifier':
+ case 'UnaryExpression':
+ case 'BinaryExpression':
+ case 'LogicalExpression':
+ case 'ConditionalExpression':
+ case 'MemberExpression': return { '@binding': escodegen.generate(node) }
+ case 'ArrayExpression': return node.elements.map(_ => nodeToBinding(_))
+ case 'ObjectExpression': {
+ const object = {}
+ node.properties.forEach(prop => {
+ if (!prop.key || prop.key.type !== 'Identifier') {
+ return
+ }
+ const key = escodegen.generate(prop.key)
+ const value = nodeToBinding(prop.value)
+ if (key && value) {
+ object[key] = value
+ }
+ })
+ return object
+ }
+ default: {
+ // warn(`Not support ${node.type}: "${escodegen.generate(node)}"`)
+ return ''
+ }
+ }
+}
+
+export function generateBinding (exp: ?string): any {
+ if (exp && typeof exp === 'string') {
+ let ast = null
+ try {
+ ast = acorn.parse(`(${exp})`)
+ } catch (e) {
+ // warn(`Failed to parse the expression: "${exp}"`)
+ return ''
+ }
+
+ let output = ''
+ walk.simple(ast, {
+ Expression (node) {
+ output = nodeToBinding(node)
+ }
+ })
+ return output
+ }
+}