Skip to content

Commit 34cc834

Browse files
committed
feat: add clampchange event, revert raf
1 parent 357bd0f commit 34cc834

File tree

7 files changed

+4951
-2976
lines changed

7 files changed

+4951
-2976
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.3.0
2+
3+
* Add `clampchange` event.
4+
15
## 0.2.2
26

37
* Preserve at lease a single line of content when even a single line would exceeds `max-height`.

babel.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module.exports = {
22
presets: [
3-
'@vue/app'
3+
'@vue/cli-plugin-babel/preset'
44
]
55
}

package-lock.json

+4,785-2,904
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+32-31
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,56 @@
11
{
22
"name": "vue-clamp",
3-
"version": "0.2.2",
4-
"license": "MIT",
3+
"version": "0.3.0",
54
"description": "Clamping multiline text with ease.",
65
"scripts": {
76
"serve": "vue-cli-service serve",
8-
"build:demo": "vue-cli-service build",
9-
"lint": "vue-cli-service lint",
107
"build": "NODE_ENV=production rollup -c",
8+
"lint": "vue-cli-service lint",
9+
"build:demo": "vue-cli-service build",
1110
"prepublishOnly": "cp ./src/components/Clamp.js .",
1211
"publish": "rm ./Clamp.js"
1312
},
14-
"repository": {
15-
"type": "git",
16-
"url": "git+https://github.com/Justineo/vue-clamp.git"
17-
},
18-
"bugs": {
19-
"url": "https://github.com/Justineo/vue-clamp/issues"
20-
},
21-
"homepage": "https://justineo.github.io/vue-clamp/demo/",
2213
"main": "dist/vue-clamp.js",
2314
"module": "Clamp.js",
2415
"dependencies": {
16+
"core-js": "^3.6.4",
2517
"resize-detector": "^0.1.10"
2618
},
2719
"devDependencies": {
28-
"@vue/cli-plugin-babel": "^3.11.0",
29-
"@vue/cli-plugin-eslint": "^3.11.0",
30-
"@vue/cli-service": "^3.11.0",
20+
"@rollup/plugin-buble": "^0.21.1",
21+
"@rollup/plugin-node-resolve": "^7.1.1",
22+
"@vue/cli-plugin-babel": "^4.2.3",
23+
"@vue/cli-plugin-eslint": "^4.2.3",
24+
"@vue/cli-service": "^4.2.3",
3125
"@vue/eslint-config-standard": "^4.0.0",
32-
"babel-eslint": "^10.0.3",
33-
"eslint": "^5.16.0",
34-
"eslint-config-prettier": "^4.3.0",
35-
"eslint-config-standard": "^6.2.1",
36-
"eslint-plugin-vue": "^5.2.3",
37-
"highlight.js": "^9.15.10",
38-
"prettier": "^1.18.2",
39-
"prettier-eslint": "^8.8.2",
40-
"qs": "^6.8.0",
41-
"rollup": "^0.68.2",
42-
"rollup-plugin-buble": "^0.19.8",
43-
"rollup-plugin-node-resolve": "^4.2.4",
44-
"rollup-plugin-terser": "^3.0.0",
45-
"rollup-plugin-vue": "^4.7.2",
26+
"babel-eslint": "^10.1.0",
27+
"eslint": "^6.8.0",
28+
"eslint-config-prettier": "^6.10.1",
29+
"eslint-config-standard": "^14.1.1",
30+
"eslint-plugin-vue": "^6.2.2",
31+
"highlight.js": "^9.18.1",
32+
"prettier": "^2.0.2",
33+
"prettier-eslint": "^9.0.1",
34+
"qs": "^6.9.3",
35+
"rollup": "^2.2.0",
36+
"rollup-plugin-terser": "^5.3.0",
37+
"rollup-plugin-vue": "^5.1.6",
4638
"spectre.css": "^0.5.8",
4739
"stylus": "^0.54.7",
4840
"stylus-loader": "^3.0.2",
49-
"vue": "^2.6.10",
50-
"vue-template-compiler": "^2.6.10"
41+
"vue": "^2.6.11",
42+
"vue-template-compiler": "^2.6.11"
5143
},
5244
"peerDependencies": {
5345
"vue": "^2.5.17"
46+
},
47+
"bugs": {
48+
"url": "https://github.com/Justineo/vue-clamp/issues"
49+
},
50+
"homepage": "https://justineo.github.io/vue-clamp/demo/",
51+
"license": "MIT",
52+
"repository": {
53+
"type": "git",
54+
"url": "git+https://github.com/Justineo/vue-clamp.git"
5455
}
5556
}

rollup.config.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import vue from 'rollup-plugin-vue'
2-
import buble from 'rollup-plugin-buble'
2+
import buble from '@rollup/plugin-buble'
33
import { terser } from 'rollup-plugin-terser'
4-
import resolve from 'rollup-plugin-node-resolve'
4+
import resolve from '@rollup/plugin-node-resolve'
55

66
export default {
77
input: 'src/components/Clamp.js',

src/App.vue

+106-5
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,13 @@
3232
GitHub →
3333
</a>
3434
</p>
35-
3635
<h2 id="features"><a href="#features">#</a> {{ zh ? '功能' : 'Features' }}</h2>
3736
<ul>
3837
<li>{{ zh ? '可以选择限制行数与/或最大高度,无需指定行高。' : 'Clamps text with max lines and/or max height. No need to specify line height.' }}</li>
3938
<li>{{ zh ? '支持在布局变化时自动更新。' : 'Automatically updates upon layout change.' }}</li>
4039
<li>{{ zh ? '支持展开/收起被截断部分内容。' : 'The clamped text can be expanded/collapsed.' }}</li>
4140
<li>{{ zh ? '支持自定义截断文本前后内容,并且进行响应式更新。' : 'Customizable and responsive content before/after clamped text.' }}</li>
4241
</ul>
43-
4442
<h2 id="demo"><a href="#demo">#</a> Demo</h2>
4543
<div
4644
class="divider text-center"
@@ -224,6 +222,88 @@
224222
</template>
225223
</v-clamp>
226224
</section>
225+
<div
226+
class="divider text-center"
227+
data-content="↓ `clampchange` event"
228+
/>
229+
<section class="case">
230+
<div class="form-horizontal">
231+
<div class="form-group">
232+
<label
233+
class="form-label col-5 col-sm-12"
234+
for="lines3"
235+
>
236+
{{ zh ? '最大行数' : 'Max lines' }}
237+
</label>
238+
<div
239+
class="col-7 col-sm-12"
240+
>
241+
<input
242+
id="lines3"
243+
v-model.number="lines3"
244+
class="form-input"
245+
type="number"
246+
min="1"
247+
max="8"
248+
step="1"
249+
>
250+
</div>
251+
</div>
252+
<div class="form-group">
253+
<label
254+
class="form-label col-5 col-sm-12"
255+
for="width3"
256+
>
257+
{{ zh ? '容器宽度' : 'Container width' }}
258+
</label>
259+
<div
260+
class="col-7 col-sm-12 tooltip"
261+
:data-tooltip="`${width3}px`"
262+
>
263+
<input
264+
id="width3"
265+
v-model="width3"
266+
class="slider"
267+
type="range"
268+
min="240"
269+
max="600"
270+
>
271+
</div>
272+
</div>
273+
<div
274+
v-if="!zh"
275+
class="form-group"
276+
>
277+
<div class="col-5 col-sm-12">
278+
<label class="form-checkbox">
279+
<input
280+
v-model="hyphens3"
281+
type="checkbox"
282+
>
283+
<i class="form-icon"/>
284+
CSS <code>hyphens</code>
285+
</label>
286+
</div>
287+
</div>
288+
</div>
289+
<v-clamp
290+
:class="{
291+
demo: true,
292+
hyphens: hyphens3
293+
}"
294+
:max-lines="lines3"
295+
autoresize
296+
:style="{
297+
width: `${width3}px`
298+
}"
299+
@clampchange="clamped3 = $event"
300+
>
301+
{{ zh ? textZh : text }}
302+
</v-clamp>
303+
<p class="mt-2">
304+
{{ zh ? '截断状态:' + (clamped3 ? '已截断' : '未截断') : 'Clamped: ' + (clamped3 ? 'Yes' : 'No')}}
305+
</p>
306+
</section>
227307
<h2 id="usage"><a href="#usage">#</a> {{ zh ? '使用方法' : 'Usage' }}</h2>
228308
<div
229309
class="divider text-center"
@@ -392,6 +472,19 @@ export default {
392472
</li>
393473
</ul>
394474
</section>
475+
<div
476+
class="divider text-center"
477+
data-content="↓ Events"
478+
/>
479+
<section>
480+
<ul>
481+
<li>
482+
<p><code>clampchange</code></p>
483+
<p>{{ zh ? '截断状态变化时触发。' : 'Emitted when clamp state changes.' }}</p>
484+
<p>{{ parameterText }}<code>(clamped: Boolean)</code></p>
485+
</li>
486+
</ul>
487+
</section>
395488
<footer>
396489
<p v-if="zh">由 <a href="https://github.com/Justineo">@Justineo</a> 创作。</p>
397490
<p v-else>Made by <a href="https://github.com/Justineo">@Justineo</a>.</p>
@@ -417,9 +510,9 @@ hljs.registerLanguage('javascript', javascript)
417510
hljs.registerLanguage('diff', diff)
418511
hljs.registerLanguage('shell', shell)
419512
420-
let search = location.search.replace(/^\?/, '')
421-
let query = qs.parse(search)
422-
let zh = query.lang === 'zh'
513+
const search = location.search.replace(/^\?/, '')
514+
const query = qs.parse(search)
515+
const zh = query.lang === 'zh'
423516
424517
export default {
425518
name: 'app',
@@ -435,6 +528,10 @@ export default {
435528
height: 'calc(48px + 12em)',
436529
width2: 600,
437530
hyphens2: true,
531+
lines3: 5,
532+
width3: 600,
533+
hyphens3: true,
534+
clamped3: false,
438535
text:
439536
'Vue (pronounced /vjuː/, like view) is a progressive framework for building user interfaces. Unlike other monolithic frameworks, Vue is designed from the ground up to be incrementally adoptable. The core library is focused on the view layer only, and is easy to pick up and integrate with other libraries or existing projects. On the other hand, Vue is also perfectly capable of powering sophisticated Single-Page Applications when used in combination with modern tooling and supporting libraries.',
440537
textZh:
@@ -446,6 +543,9 @@ export default {
446543
computed: {
447544
defaultText () {
448545
return this.zh ? '默认值:' : 'Default:'
546+
},
547+
parameterText () {
548+
return this.zh ? '回调参数:' : 'Callback parameter list:'
449549
}
450550
},
451551
watch: {
@@ -548,6 +648,7 @@ summary
548648
display flex
549649
align-items center
550650
margin-bottom 0.5em
651+
cursor pointer
551652
552653
h4
553654
margin 0

0 commit comments

Comments
 (0)