fritx / vue-at

At.js for Vue.
https://fritx.github.io/vue-at/
MIT License
529 stars 114 forks source link

Backlog #2

Open fritx opened 7 years ago

fritx commented 7 years ago
huangruichang commented 7 years ago

very nice

fritx commented 7 years ago

nice 🍻 @huangruichang

fritx commented 7 years ago
// http://stackoverflow.com/questions/15157435/get-last-character-before-caret-position-in-javascript
export function getPrecedingRange() {
  const r = getRange()
  if (r) {
    const range = r.cloneRange()
    range.collapse(true)
    // 修复 "空格+表情+空格+@" range报错 应设(endContainer, 0)
    // stackoverflow上的这段代码有bug
    // var el = closest(range.endContainer, d => d.contentEditable)
    // range.setStart(el, 0)
    range.setStart(range.endContainer, 0)
    return range
  }
}

error stack was:

Uncaught DOMException: Failed to execute 'setStart' on 'Range':
The offset 3 is larger than or equal to the node's length (2).
    at fn (eval at <anonymous> (http://localhost:8081/dist/demo.js:1010:1), <anonymous>:279:11)
fritx commented 7 years ago
# package.json
   "peerDependencies": {
-    "vue": "2.x"
+    "vue": "1.x"
   },
   "devDependencies": {
     "babel-core": "^6.0.0",
     "babel-loader": "^6.0.0",
+    "babel-plugin-transform-runtime": "^6.0.0",
     "babel-preset-es2015": "^6.0.0",
     "babel-preset-stage-0": "^6.16.0",
     // ...
-    "vue": "^2.1.0",
-    "vue-loader": "^10.3.0",
+    "vue": "^1.0.28",
+    "vue-hot-reload-api": "^1.2.0",
+    "vue-html-loader": "^1.0.0",
+    "vue-loader": "^8.2.1",
     "vue-style-loader": "^1.0.0",
-    "vue-template-compiler": "^2.2.4",
-    "webpack": "^2.1.0-beta.25",
-    "webpack-dev-server": "^2.1.0-beta.9"
+    "webpack": "^1.12.2",
+    "webpack-dev-server": "^1.12.0"
   }
# .babelrc
-  "presets": [
-    "stage-0",
-    ["es2015", { "modules": false }]
-  ]
+  "presets": ["es2015", "stage-0"],
+  "plugins": ["transform-runtime"],
+  "comments": false
# webpack/*.js
# ...
# main.js
 new Vue({
-  el: '#app',
-  render: h => h(App)
+  el: 'body',
+  components: { App }
 })
# index.html
   <body>
-    <div id="app"></div>
+    <app></app>
     <script src="/dist/demo.js"></script>
   </body>
[Vue warn]: Possible usage error for prop `namekey` - did you mean `name-key`?
HTML is case-insensitive, remember to use kebab-case for props in templates. (found in component: <at>)
Error: Cannot read property '0' of undefined -- (this.$refs.xx)
-  <div ref="wrap"
+  <div v-el:wrap
-  <li v-for="(item, index) in atwho.list"
+  <li v-for="(index, item) in atwho.list"
[Vue warn]: Error when evaluating expression "s.item.name":
TypeError: Cannot read property 'item' of undefined (found in component: <app>)
-      <template slot="item" scope="s">
-        <img :src="s.item.avatar">
-        <span v-text="s.item.name"></span>
+      <template slot="item">
+        <img data-src="item.avatar">
+        <span data-text="item.name"></span>
handleStateChange (state) {
  forEach.call(els, el => {
    const textNode = el.querySelector('[data-text]')
    textNode.textContent = this.itemExpr(item, textExpr)
    const imgNode = el.querySelector('[data-src]')
    imgNode.src = this.itemExpr(item, imgExpr)
  })
}