@toife/vue 3.1.5 → 3.2.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/README.md +1 -52
- package/dist/components/action/action.composable.d.ts +44 -0
- package/dist/components/action/action.vue.d.ts +16 -0
- package/dist/components/action/index.d.ts +2 -0
- package/dist/components/app/app.vue.d.ts +11 -0
- package/dist/components/app/index.d.ts +1 -0
- package/dist/components/avatar/avatar.vue.d.ts +8 -0
- package/dist/components/avatar/index.d.ts +1 -0
- package/dist/components/button/button.vue.d.ts +9 -0
- package/dist/components/button/index.d.ts +1 -0
- package/dist/components/cable/cable.vue.d.ts +6 -0
- package/dist/components/cable/index.d.ts +1 -0
- package/dist/components/card/card/card.vue.d.ts +7 -0
- package/dist/components/card/card/index.d.ts +1 -0
- package/dist/components/card/card-body/card-body.vue.d.ts +2 -0
- package/dist/components/card/card-body/index.d.ts +1 -0
- package/dist/components/card/card-footer/card-footer.vue.d.ts +2 -0
- package/dist/components/card/card-footer/index.d.ts +1 -0
- package/dist/components/card/card-header/card-header.vue.d.ts +2 -0
- package/dist/components/card/card-header/index.d.ts +1 -0
- package/dist/components/card/index.d.ts +4 -0
- package/dist/components/checkbox/checkbox.vue.d.ts +18 -0
- package/dist/components/checkbox/index.d.ts +1 -0
- package/dist/components/collapse/collapse.vue.d.ts +12 -0
- package/dist/components/collapse/index.d.ts +1 -0
- package/dist/components/container/container.vue.d.ts +2 -0
- package/dist/components/container/index.d.ts +1 -0
- package/dist/components/decision-modal/decision-modal.composable.d.ts +46 -0
- package/dist/components/decision-modal/decision-modal.vue.d.ts +16 -0
- package/dist/components/decision-modal/index.d.ts +2 -0
- package/dist/components/divider/divider.vue.d.ts +5 -0
- package/dist/components/divider/index.d.ts +1 -0
- package/dist/components/dropdown/dropdown.vue.d.ts +20 -0
- package/dist/components/dropdown/index.d.ts +1 -0
- package/dist/components/field/field.vue.d.ts +30 -0
- package/dist/components/field/index.d.ts +1 -0
- package/dist/components/form-group/form-group.vue.d.ts +5 -0
- package/dist/components/form-group/index.d.ts +1 -0
- package/dist/components/gesture-indicator/gesture-indicator.vue.d.ts +6 -0
- package/dist/components/gesture-indicator/index.d.ts +1 -0
- package/dist/components/image/image.vue.d.ts +3 -0
- package/dist/components/image/index.d.ts +1 -0
- package/dist/components/index.d.ts +32 -0
- package/dist/components/layout/flex/flex.vue.d.ts +5 -0
- package/dist/components/layout/flex/index.d.ts +1 -0
- package/dist/components/layout/flex-item/flex-item.vue.d.ts +5 -0
- package/dist/components/layout/flex-item/index.d.ts +1 -0
- package/dist/components/layout/grid/grid.vue.d.ts +5 -0
- package/dist/components/layout/grid/index.d.ts +1 -0
- package/dist/components/layout/grid-item/grid-item.vue.d.ts +5 -0
- package/dist/components/layout/grid-item/index.d.ts +1 -0
- package/dist/components/layout/index.d.ts +4 -0
- package/dist/components/modal/index.d.ts +1 -0
- package/dist/components/modal/modal.vue.d.ts +17 -0
- package/dist/components/page/index.d.ts +1 -0
- package/dist/components/page/page.vue.d.ts +2 -0
- package/dist/components/present/index.d.ts +2 -0
- package/dist/components/present/present.composable.d.ts +5 -0
- package/dist/components/present/present.vue.d.ts +18 -0
- package/dist/components/radio/index.d.ts +2 -0
- package/dist/components/radio/radio/index.d.ts +1 -0
- package/dist/components/radio/radio/radio.vue.d.ts +7 -0
- package/dist/components/radio/radio-group/index.d.ts +1 -0
- package/dist/components/radio/radio-group/radio-group.vue.d.ts +13 -0
- package/dist/components/refresher/index.d.ts +1 -0
- package/dist/components/refresher/refresher.vue.d.ts +12 -0
- package/dist/components/route/index.d.ts +5 -0
- package/dist/components/route/route-navigator/index.d.ts +1 -0
- package/dist/components/route/route-navigator/route-navigator.vue.d.ts +11 -0
- package/dist/components/route/route-outlet/index.d.ts +1 -0
- package/dist/components/route/route-outlet/route-outlet.vue.d.ts +5 -0
- package/dist/components/route/route-provider/index.d.ts +1 -0
- package/dist/components/route/route-provider/route-provider.vue.d.ts +3 -0
- package/dist/components/route/route-wrapper/index.d.ts +2 -0
- package/dist/components/route/route-wrapper/route-wrapper.composable.d.ts +6 -0
- package/dist/components/route/route-wrapper/route-wrapper.vue.d.ts +5 -0
- package/dist/components/route/route.util.d.ts +3 -0
- package/dist/components/segmented-field/index.d.ts +1 -0
- package/dist/components/segmented-field/segmented-field.vue.d.ts +28 -0
- package/dist/components/select/index.d.ts +1 -0
- package/dist/components/select/select.vue.d.ts +19 -0
- package/dist/components/skeleton/index.d.ts +1 -0
- package/dist/components/skeleton/skeleton.vue.d.ts +6 -0
- package/dist/components/slide-range/index.d.ts +1 -0
- package/dist/components/slide-range/slide-range.vue.d.ts +17 -0
- package/dist/components/switch/index.d.ts +1 -0
- package/dist/components/switch/switch.vue.d.ts +13 -0
- package/dist/components/tabs/index.d.ts +2 -0
- package/dist/components/tabs/tab/index.d.ts +1 -0
- package/dist/components/tabs/tab/tab.vue.d.ts +5 -0
- package/dist/components/tabs/tabs/index.d.ts +1 -0
- package/dist/components/tabs/tabs/tabs.vue.d.ts +14 -0
- package/dist/components/tag/index.d.ts +1 -0
- package/dist/components/tag/tag.vue.d.ts +6 -0
- package/dist/components/toast/index.d.ts +3 -0
- package/dist/components/toast/toast/index.d.ts +1 -0
- package/dist/components/toast/toast/toast.vue.d.ts +5 -0
- package/dist/components/toast/toast-content/index.d.ts +1 -0
- package/dist/components/toast/toast-content/toast-content.vue.d.ts +11 -0
- package/dist/components/toast/toast.composable.d.ts +22 -0
- package/dist/components/toolbar/index.d.ts +1 -0
- package/dist/components/toolbar/toolbar.vue.d.ts +7 -0
- package/dist/factory.d.ts +38 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.es.js +3491 -0
- package/dist/index.umd.js +1 -0
- package/dist/shared/provider-state.d.ts +5 -0
- package/dist/styles/action.css +1 -0
- package/dist/styles/app.css +1 -0
- package/dist/styles/avatar.css +1 -0
- package/dist/styles/button.css +1 -0
- package/dist/styles/cable.css +1 -0
- package/dist/styles/card-body.css +1 -0
- package/dist/styles/card-footer.css +1 -0
- package/dist/styles/card-header.css +1 -0
- package/dist/styles/card.css +1 -0
- package/dist/styles/checkbox.css +1 -0
- package/dist/styles/collapse.css +1 -0
- package/dist/styles/container.css +1 -0
- package/dist/styles/decision-modal.css +1 -0
- package/dist/styles/divider.css +1 -0
- package/dist/styles/dropdown.css +1 -0
- package/dist/styles/field.css +1 -0
- package/dist/styles/flex-item.css +1 -0
- package/dist/styles/flex.css +1 -0
- package/dist/styles/form-group.css +1 -0
- package/dist/styles/gesture-indicator.css +1 -0
- package/dist/styles/grid-item.css +1 -0
- package/dist/styles/grid.css +1 -0
- package/dist/styles/index.css +40 -0
- package/dist/styles/modal.css +1 -0
- package/dist/styles/page.css +1 -0
- package/dist/styles/present.css +1 -0
- package/dist/styles/radio-group.css +1 -0
- package/dist/styles/radio.css +1 -0
- package/dist/styles/refresher.css +1 -0
- package/dist/styles/route-navigator.css +1 -0
- package/dist/styles/segmented-field.css +1 -0
- package/dist/styles/select.css +1 -0
- package/dist/styles/skeleton.css +1 -0
- package/dist/styles/slide-range.css +1 -0
- package/dist/styles/switch.css +1 -0
- package/dist/styles/tab.css +1 -0
- package/dist/styles/tabs.css +1 -0
- package/dist/styles/tag.css +1 -0
- package/dist/styles/toast-content.css +1 -0
- package/dist/styles/toast.css +1 -0
- package/dist/styles/toolbar.css +1 -0
- package/dist/types.d.ts +4 -0
- package/package.json +24 -14
- package/src/components/action/action.composable.ts +0 -32
- package/src/components/action/action.html +0 -25
- package/src/components/action/action.scss +0 -106
- package/src/components/action/action.type.ts +0 -44
- package/src/components/action/action.vue +0 -72
- package/src/components/action/index.ts +0 -9
- package/src/components/app/app.constants.ts +0 -1
- package/src/components/app/app.html +0 -24
- package/src/components/app/app.scss +0 -27
- package/src/components/app/app.type.ts +0 -36
- package/src/components/app/app.vue +0 -52
- package/src/components/app/index.ts +0 -3
- package/src/components/avatar/avatar.html +0 -3
- package/src/components/avatar/avatar.scss +0 -45
- package/src/components/avatar/avatar.type.ts +0 -8
- package/src/components/avatar/avatar.vue +0 -44
- package/src/components/avatar/index.ts +0 -2
- package/src/components/button/button.html +0 -6
- package/src/components/button/button.scss +0 -116
- package/src/components/button/button.type.ts +0 -16
- package/src/components/button/button.vue +0 -61
- package/src/components/button/index.ts +0 -2
- package/src/components/cable/cable.constants.ts +0 -1
- package/src/components/cable/cable.html +0 -3
- package/src/components/cable/cable.scss +0 -37
- package/src/components/cable/cable.type.ts +0 -11
- package/src/components/cable/cable.vue +0 -33
- package/src/components/cable/index.ts +0 -3
- package/src/components/card/card/card.constants.ts +0 -1
- package/src/components/card/card/card.html +0 -3
- package/src/components/card/card/card.scss +0 -37
- package/src/components/card/card/card.type.ts +0 -14
- package/src/components/card/card/card.vue +0 -62
- package/src/components/card/card/index.ts +0 -3
- package/src/components/card/card-body/card-body.html +0 -3
- package/src/components/card/card-body/card-body.scss +0 -23
- package/src/components/card/card-body/card-body.vue +0 -9
- package/src/components/card/card-body/index.ts +0 -1
- package/src/components/card/card-footer/card-footer.html +0 -3
- package/src/components/card/card-footer/card-footer.scss +0 -32
- package/src/components/card/card-footer/card-footer.vue +0 -25
- package/src/components/card/card-footer/index.ts +0 -1
- package/src/components/card/card-header/card-header.html +0 -3
- package/src/components/card/card-header/card-header.scss +0 -32
- package/src/components/card/card-header/card-header.vue +0 -25
- package/src/components/card/card-header/index.ts +0 -1
- package/src/components/card/index.ts +0 -4
- package/src/components/checkbox/checkbox.html +0 -12
- package/src/components/checkbox/checkbox.scss +0 -150
- package/src/components/checkbox/checkbox.type.ts +0 -21
- package/src/components/checkbox/checkbox.vue +0 -80
- package/src/components/checkbox/index.ts +0 -2
- package/src/components/collapse/collapse.html +0 -16
- package/src/components/collapse/collapse.scss +0 -59
- package/src/components/collapse/collapse.type.ts +0 -11
- package/src/components/collapse/collapse.vue +0 -127
- package/src/components/collapse/index.ts +0 -2
- package/src/components/container/container.html +0 -1
- package/src/components/container/container.scss +0 -10
- package/src/components/container/container.vue +0 -10
- package/src/components/container/index.ts +0 -1
- package/src/components/decision-modal/decision-modal.composable.ts +0 -33
- package/src/components/decision-modal/decision-modal.html +0 -29
- package/src/components/decision-modal/decision-modal.scss +0 -144
- package/src/components/decision-modal/decision-modal.type.ts +0 -35
- package/src/components/decision-modal/decision-modal.vue +0 -96
- package/src/components/decision-modal/index.ts +0 -9
- package/src/components/divider/divider.html +0 -1
- package/src/components/divider/divider.scss +0 -29
- package/src/components/divider/divider.type.ts +0 -6
- package/src/components/divider/divider.vue +0 -31
- package/src/components/divider/index.ts +0 -2
- package/src/components/dropdown/dropdown.html +0 -6
- package/src/components/dropdown/dropdown.scss +0 -71
- package/src/components/dropdown/dropdown.type.ts +0 -22
- package/src/components/dropdown/dropdown.vue +0 -111
- package/src/components/dropdown/index.ts +0 -2
- package/src/components/field/field.html +0 -12
- package/src/components/field/field.type.ts +0 -43
- package/src/components/field/field.vue +0 -86
- package/src/components/field/index.ts +0 -2
- package/src/components/field/outline/index.ts +0 -1
- package/src/components/field/outline/outline.html +0 -36
- package/src/components/field/outline/outline.scss +0 -282
- package/src/components/field/outline/outline.vue +0 -294
- package/src/components/form-group/form-group.html +0 -3
- package/src/components/form-group/form-group.scss +0 -91
- package/src/components/form-group/form-group.type.ts +0 -5
- package/src/components/form-group/form-group.vue +0 -21
- package/src/components/form-group/index.ts +0 -2
- package/src/components/gesture-indicator/gesture-indicator.html +0 -1
- package/src/components/gesture-indicator/gesture-indicator.scss +0 -47
- package/src/components/gesture-indicator/gesture-indicator.type.ts +0 -5
- package/src/components/gesture-indicator/gesture-indicator.vue +0 -31
- package/src/components/gesture-indicator/index.ts +0 -1
- package/src/components/image/image.html +0 -1
- package/src/components/image/image.type.ts +0 -5
- package/src/components/image/image.vue +0 -29
- package/src/components/image/index.ts +0 -2
- package/src/components/index.ts +0 -31
- package/src/components/layout/flex/flex.html +0 -1
- package/src/components/layout/flex/flex.scss +0 -57
- package/src/components/layout/flex/flex.type.ts +0 -15
- package/src/components/layout/flex/flex.vue +0 -34
- package/src/components/layout/flex/index.ts +0 -2
- package/src/components/layout/flex-item/flex-item.html +0 -1
- package/src/components/layout/flex-item/flex-item.scss +0 -48
- package/src/components/layout/flex-item/flex-item.type.ts +0 -11
- package/src/components/layout/flex-item/flex-item.vue +0 -27
- package/src/components/layout/flex-item/index.ts +0 -2
- package/src/components/layout/grid/grid.html +0 -1
- package/src/components/layout/grid/grid.scss +0 -51
- package/src/components/layout/grid/grid.type.ts +0 -12
- package/src/components/layout/grid/grid.vue +0 -32
- package/src/components/layout/grid/index.ts +0 -2
- package/src/components/layout/grid-item/grid-item.html +0 -1
- package/src/components/layout/grid-item/grid-item.scss +0 -49
- package/src/components/layout/grid-item/grid-item.type.ts +0 -14
- package/src/components/layout/grid-item/grid-item.vue +0 -27
- package/src/components/layout/grid-item/index.ts +0 -2
- package/src/components/layout/index.ts +0 -4
- package/src/components/modal/index.ts +0 -2
- package/src/components/modal/modal.html +0 -20
- package/src/components/modal/modal.scss +0 -80
- package/src/components/modal/modal.type.ts +0 -21
- package/src/components/modal/modal.vue +0 -251
- package/src/components/page/index.ts +0 -1
- package/src/components/page/page.html +0 -3
- package/src/components/page/page.scss +0 -17
- package/src/components/page/page.vue +0 -10
- package/src/components/present/index.ts +0 -3
- package/src/components/present/present.composable.ts +0 -22
- package/src/components/present/present.html +0 -9
- package/src/components/present/present.scss +0 -81
- package/src/components/present/present.type.ts +0 -26
- package/src/components/present/present.vue +0 -198
- package/src/components/radio/index.ts +0 -2
- package/src/components/radio/radio/index.ts +0 -2
- package/src/components/radio/radio/radio.html +0 -11
- package/src/components/radio/radio/radio.scss +0 -142
- package/src/components/radio/radio/radio.type.ts +0 -15
- package/src/components/radio/radio/radio.vue +0 -87
- package/src/components/radio/radio-group/index.ts +0 -7
- package/src/components/radio/radio-group/radio-group.constants.ts +0 -1
- package/src/components/radio/radio-group/radio-group.html +0 -3
- package/src/components/radio/radio-group/radio-group.scss +0 -16
- package/src/components/radio/radio-group/radio-group.type.ts +0 -28
- package/src/components/radio/radio-group/radio-group.vue +0 -57
- package/src/components/refresher/index.ts +0 -2
- package/src/components/refresher/refresher.html +0 -3
- package/src/components/refresher/refresher.scss +0 -18
- package/src/components/refresher/refresher.type.ts +0 -16
- package/src/components/refresher/refresher.vue +0 -123
- package/src/components/route/index.ts +0 -5
- package/src/components/route/route-navigator/index.ts +0 -2
- package/src/components/route/route-navigator/route-navigator.html +0 -19
- package/src/components/route/route-navigator/route-navigator.scss +0 -127
- package/src/components/route/route-navigator/route-navigator.type.ts +0 -36
- package/src/components/route/route-navigator/route-navigator.vue +0 -275
- package/src/components/route/route-outlet/index.ts +0 -1
- package/src/components/route/route-outlet/route-outlet.html +0 -1
- package/src/components/route/route-outlet/route-outlet.vue +0 -39
- package/src/components/route/route-provider/index.ts +0 -3
- package/src/components/route/route-provider/route-provider.constant.ts +0 -1
- package/src/components/route/route-provider/route-provider.html +0 -1
- package/src/components/route/route-provider/route-provider.type.ts +0 -10
- package/src/components/route/route-provider/route-provider.vue +0 -20
- package/src/components/route/route-wrapper/index.ts +0 -3
- package/src/components/route/route-wrapper/route-wrapper.composable.ts +0 -49
- package/src/components/route/route-wrapper/route-wrapper.html +0 -3
- package/src/components/route/route-wrapper/route-wrapper.type.ts +0 -3
- package/src/components/route/route-wrapper/route-wrapper.vue +0 -45
- package/src/components/route/route.type.ts +0 -7
- package/src/components/route/route.util.ts +0 -9
- package/src/components/segmented-field/index.ts +0 -7
- package/src/components/segmented-field/segmented-field.html +0 -17
- package/src/components/segmented-field/segmented-field.scss +0 -53
- package/src/components/segmented-field/segmented-field.type.ts +0 -29
- package/src/components/segmented-field/segmented-field.vue +0 -145
- package/src/components/select/index.ts +0 -2
- package/src/components/select/select.html +0 -29
- package/src/components/select/select.scss +0 -129
- package/src/components/select/select.type.ts +0 -45
- package/src/components/select/select.vue +0 -119
- package/src/components/skeleton/index.ts +0 -2
- package/src/components/skeleton/skeleton.html +0 -1
- package/src/components/skeleton/skeleton.scss +0 -52
- package/src/components/skeleton/skeleton.type.ts +0 -7
- package/src/components/skeleton/skeleton.vue +0 -38
- package/src/components/slide-range/index.ts +0 -2
- package/src/components/slide-range/slide-range.html +0 -19
- package/src/components/slide-range/slide-range.scss +0 -161
- package/src/components/slide-range/slide-range.type.ts +0 -16
- package/src/components/slide-range/slide-range.vue +0 -229
- package/src/components/switch/index.ts +0 -2
- package/src/components/switch/switch.html +0 -14
- package/src/components/switch/switch.scss +0 -128
- package/src/components/switch/switch.type.ts +0 -19
- package/src/components/switch/switch.vue +0 -97
- package/src/components/tabs/index.ts +0 -2
- package/src/components/tabs/tab/index.ts +0 -2
- package/src/components/tabs/tab/tab.html +0 -5
- package/src/components/tabs/tab/tab.scss +0 -13
- package/src/components/tabs/tab/tab.type.ts +0 -5
- package/src/components/tabs/tab/tab.vue +0 -40
- package/src/components/tabs/tabs/index.ts +0 -10
- package/src/components/tabs/tabs/tabs.constants.ts +0 -1
- package/src/components/tabs/tabs/tabs.html +0 -3
- package/src/components/tabs/tabs/tabs.scss +0 -341
- package/src/components/tabs/tabs/tabs.type.ts +0 -39
- package/src/components/tabs/tabs/tabs.vue +0 -177
- package/src/components/toast/index.ts +0 -4
- package/src/components/toast/toast/index.ts +0 -1
- package/src/components/toast/toast/toast.html +0 -9
- package/src/components/toast/toast/toast.scss +0 -61
- package/src/components/toast/toast/toast.vue +0 -34
- package/src/components/toast/toast-content/index.ts +0 -1
- package/src/components/toast/toast-content/toast-content.html +0 -1
- package/src/components/toast/toast-content/toast-content.scss +0 -42
- package/src/components/toast/toast-content/toast-content.vue +0 -53
- package/src/components/toast/toast.composable.ts +0 -22
- package/src/components/toast/toast.type.ts +0 -25
- package/src/components/toolbar/index.ts +0 -2
- package/src/components/toolbar/toolbar.html +0 -3
- package/src/components/toolbar/toolbar.scss +0 -64
- package/src/components/toolbar/toolbar.type.ts +0 -7
- package/src/components/toolbar/toolbar.vue +0 -41
- package/src/env.d.ts +0 -7
- package/src/factory.ts +0 -152
- package/src/index.ts +0 -4
- package/src/type.ts +0 -4
- package/src/utils/element.md +0 -33
- package/src/utils/element.ts +0 -22
- package/src/utils/events.md +0 -29
- package/src/utils/events.ts +0 -18
- package/src/utils/index.ts +0 -3
- package/src/utils/style/index.ts +0 -57
- package/src/utils/style.md +0 -49
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
<template src="./field.html"></template>
|
|
2
|
-
<script lang="ts" setup>
|
|
3
|
-
import { computed, inject } from "vue";
|
|
4
|
-
import type { FieldProps } from "./field.type";
|
|
5
|
-
import type { FieldEmit } from "./field.type";
|
|
6
|
-
import { OutlineField } from "./outline";
|
|
7
|
-
import { type AppProviderState, APP_PROVIDER_STATE_KEY } from "../app";
|
|
8
|
-
|
|
9
|
-
// Component setup (props, emits, injects)
|
|
10
|
-
// ----------------------------------------------------------------------------
|
|
11
|
-
const props = withDefaults(defineProps<FieldProps>(), {
|
|
12
|
-
modelValue: "",
|
|
13
|
-
type: "text",
|
|
14
|
-
size: "standard",
|
|
15
|
-
disabled: false,
|
|
16
|
-
readonly: false,
|
|
17
|
-
message: "",
|
|
18
|
-
help: "",
|
|
19
|
-
variant: "outline",
|
|
20
|
-
placeholder: "",
|
|
21
|
-
shadow: undefined,
|
|
22
|
-
direction: undefined,
|
|
23
|
-
line: 1,
|
|
24
|
-
});
|
|
25
|
-
const emit = defineEmits<FieldEmit>();
|
|
26
|
-
const appState = inject<AppProviderState>(APP_PROVIDER_STATE_KEY);
|
|
27
|
-
|
|
28
|
-
// Computed properties
|
|
29
|
-
// ----------------------------------------------------------------------------
|
|
30
|
-
const role = computed(() => {
|
|
31
|
-
return props.role || appState?.role.value || "";
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
const shape = computed(() => {
|
|
35
|
-
return props.shape || appState?.shape.value || "";
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
const shadow = computed(() => {
|
|
39
|
-
return (props?.shadow !== undefined ? props.shadow : appState?.shadow.value) ?? false;
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
const direction = computed(() => {
|
|
43
|
-
return props.direction || appState?.direction?.value || "left";
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
const fieldAttrs = computed(() => {
|
|
47
|
-
return {
|
|
48
|
-
...props,
|
|
49
|
-
direction: direction.value,
|
|
50
|
-
role: role.value,
|
|
51
|
-
shape: shape.value,
|
|
52
|
-
shadow: shadow.value,
|
|
53
|
-
onInput,
|
|
54
|
-
onFocus,
|
|
55
|
-
onBlur,
|
|
56
|
-
onBeforeinput,
|
|
57
|
-
};
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
// Methods
|
|
61
|
-
// ----------------------------------------------------------------------------
|
|
62
|
-
const onInput = (event: Event) => {
|
|
63
|
-
let raw = "";
|
|
64
|
-
// Outline variant uses contenteditable for non-password types; password uses a real input
|
|
65
|
-
if (props.type !== "password") {
|
|
66
|
-
raw = (event.target as HTMLElement).innerText;
|
|
67
|
-
} else {
|
|
68
|
-
raw = (event.target as HTMLInputElement).value;
|
|
69
|
-
}
|
|
70
|
-
const value = raw.trim() === "" ? "" : raw;
|
|
71
|
-
emit("update:modelValue", value as string);
|
|
72
|
-
emit("input", event);
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
const onFocus = (event: FocusEvent) => {
|
|
76
|
-
emit("focus", event);
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
const onBlur = (event: FocusEvent) => {
|
|
80
|
-
emit("blur", event);
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
const onBeforeinput = (event: Event) => {
|
|
84
|
-
emit("beforeinput", event);
|
|
85
|
-
};
|
|
86
|
-
</script>
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default as OutlineField } from "./outline.vue";
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
<div v-bind="fieldAttrs">
|
|
2
|
-
<div v-bind="fieldContentAttrs">
|
|
3
|
-
<slot name="start-input"></slot>
|
|
4
|
-
<slot name="input">
|
|
5
|
-
<div v-bind="fieldInputShellAttrs" v-if="type !== 'password'">
|
|
6
|
-
<div
|
|
7
|
-
v-bind="fieldEditableAttrs"
|
|
8
|
-
@input="onInput"
|
|
9
|
-
@compositionstart="onCompositionStart"
|
|
10
|
-
@compositionend="onCompositionEnd"
|
|
11
|
-
@focus="onFocus"
|
|
12
|
-
@blur="onBlur"
|
|
13
|
-
@beforeinput="onBeforeinput"
|
|
14
|
-
ref="contentRef"
|
|
15
|
-
></div>
|
|
16
|
-
</div>
|
|
17
|
-
<input
|
|
18
|
-
v-bind="fieldPasswordInputAttrs"
|
|
19
|
-
@input="onInput"
|
|
20
|
-
@compositionstart="onCompositionStart"
|
|
21
|
-
@compositionend="onCompositionEnd"
|
|
22
|
-
@focus="onFocus"
|
|
23
|
-
@blur="onBlur"
|
|
24
|
-
@beforeinput="onBeforeinput"
|
|
25
|
-
ref="contentRef"
|
|
26
|
-
:value="content"
|
|
27
|
-
type="password"
|
|
28
|
-
v-else
|
|
29
|
-
/>
|
|
30
|
-
</slot>
|
|
31
|
-
<slot name="end-input"></slot>
|
|
32
|
-
</div>
|
|
33
|
-
<div v-bind="fieldMessageAttrs" v-if="message">{{ message }}</div>
|
|
34
|
-
<div v-bind="fieldHelpAttrs" v-if="help">{{ help }}</div>
|
|
35
|
-
<slot></slot>
|
|
36
|
-
</div>
|
|
@@ -1,282 +0,0 @@
|
|
|
1
|
-
@use "@toife/sass-layer" as sass;
|
|
2
|
-
|
|
3
|
-
// Class name
|
|
4
|
-
$field: sass.fn-naming-prefix("field");
|
|
5
|
-
$field-content: sass.fn-naming-prefix("field-content");
|
|
6
|
-
$field-input: sass.fn-naming-prefix("field-input");
|
|
7
|
-
$field-input-editable: sass.fn-naming-prefix("field-input-editable");
|
|
8
|
-
$field-message: sass.fn-naming-prefix("field-message");
|
|
9
|
-
$field-help: sass.fn-naming-prefix("field-help");
|
|
10
|
-
|
|
11
|
-
// Property name - layer: field
|
|
12
|
-
$field-border-color: sass.fn-naming-var("field", "border-color");
|
|
13
|
-
$field-background-color: sass.fn-naming-var("field", "background-color");
|
|
14
|
-
$field-color: sass.fn-naming-var("field", "color");
|
|
15
|
-
$field-placeholder-color: sass.fn-naming-var("field", "placeholder-color");
|
|
16
|
-
$field-help-color: sass.fn-naming-var("field", "help-color");
|
|
17
|
-
$field-line: sass.fn-naming-var("field", "line");
|
|
18
|
-
$field-max-line: sass.fn-naming-var("field", "max-line");
|
|
19
|
-
|
|
20
|
-
$radius-ratio: sass.fn-naming-var("radius-ratio");
|
|
21
|
-
$radius-size: sass.fn-naming-var("radius-size");
|
|
22
|
-
$border-width: sass.fn-naming-var("stroke", "width");
|
|
23
|
-
|
|
24
|
-
$spacing-x: sass.fn-naming-var("spacing", "x");
|
|
25
|
-
$spacing-y: sass.fn-naming-var("spacing", "y");
|
|
26
|
-
|
|
27
|
-
$size-font-size: sass.fn-naming-var("font-size");
|
|
28
|
-
$size-control-block-size: sass.fn-naming-var("control-block-size");
|
|
29
|
-
$size-coefficient-x: sass.fn-naming-var("coefficient-x");
|
|
30
|
-
$size-coefficient-y: sass.fn-naming-var("coefficient-y");
|
|
31
|
-
$size-line-height: sass.fn-naming-var("line-height");
|
|
32
|
-
|
|
33
|
-
$transition-duration: sass.fn-naming-var("motion", "duration");
|
|
34
|
-
|
|
35
|
-
$direction-text-align: sass.fn-naming-var("text-align");
|
|
36
|
-
$direction-justify-content: sass.fn-naming-var("justify-content");
|
|
37
|
-
|
|
38
|
-
.#{$field} {
|
|
39
|
-
width: 100%;
|
|
40
|
-
box-shadow: none !important;
|
|
41
|
-
|
|
42
|
-
// Field
|
|
43
|
-
.#{$field-content} {
|
|
44
|
-
transition:
|
|
45
|
-
box-shadow #{$transition-duration} ease,
|
|
46
|
-
border-color #{$transition-duration} ease,
|
|
47
|
-
background-color #{$transition-duration} ease,
|
|
48
|
-
color #{$transition-duration} ease,
|
|
49
|
-
border-radius #{$transition-duration} ease;
|
|
50
|
-
border-color: rgba(#{$field-border-color});
|
|
51
|
-
border-radius: calc(min(#{$size-control-block-size}, #{$radius-size}) * #{$radius-ratio});
|
|
52
|
-
border-width: #{$border-width};
|
|
53
|
-
border-style: solid;
|
|
54
|
-
overflow: hidden;
|
|
55
|
-
line-height: 0;
|
|
56
|
-
height: fit-content;
|
|
57
|
-
position: relative;
|
|
58
|
-
display: flex;
|
|
59
|
-
justify-content: center;
|
|
60
|
-
align-items: center;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// Input shell wrapping contenteditable (flex layout); must not apply display:flex to <input>.
|
|
64
|
-
div.#{$field-input} {
|
|
65
|
-
padding: calc(#{$spacing-y} * #{$size-coefficient-y})
|
|
66
|
-
calc(#{$spacing-x} * #{$size-coefficient-x});
|
|
67
|
-
position: relative;
|
|
68
|
-
background-color: transparent;
|
|
69
|
-
z-index: 2;
|
|
70
|
-
min-height: calc(#{$field-line} * #{$size-control-block-size} - 2 * #{$border-width});
|
|
71
|
-
max-height: calc(#{$field-max-line} * #{$size-control-block-size} - 2 * #{$border-width});
|
|
72
|
-
box-sizing: border-box;
|
|
73
|
-
width: 100%;
|
|
74
|
-
flex: 1;
|
|
75
|
-
display: flex;
|
|
76
|
-
align-items: center;
|
|
77
|
-
transition:
|
|
78
|
-
box-shadow #{$transition-duration} ease,
|
|
79
|
-
border-color #{$transition-duration} ease,
|
|
80
|
-
background-color #{$transition-duration} ease,
|
|
81
|
-
color #{$transition-duration} ease,
|
|
82
|
-
border-radius #{$transition-duration} ease;
|
|
83
|
-
|
|
84
|
-
&:focus-within,
|
|
85
|
-
&:active,
|
|
86
|
-
&:hover {
|
|
87
|
-
outline: none;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
&::placeholder {
|
|
91
|
-
color: rgba(#{$field-placeholder-color});
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
// Native password <input> (single node, not wrapped).
|
|
96
|
-
input.#{$field-input} {
|
|
97
|
-
padding: calc(#{$spacing-y} * #{$size-coefficient-y})
|
|
98
|
-
calc(#{$spacing-x} * #{$size-coefficient-x});
|
|
99
|
-
position: relative;
|
|
100
|
-
background-color: transparent;
|
|
101
|
-
z-index: 2;
|
|
102
|
-
min-height: calc(#{$field-line} * #{$size-control-block-size} - 2 * #{$border-width});
|
|
103
|
-
max-height: calc(#{$field-max-line} * #{$size-control-block-size} - 2 * #{$border-width});
|
|
104
|
-
box-sizing: border-box;
|
|
105
|
-
width: 100%;
|
|
106
|
-
flex: 1;
|
|
107
|
-
color: rgba(#{$field-color});
|
|
108
|
-
caret-color: rgba(#{$field-color});
|
|
109
|
-
border: none;
|
|
110
|
-
-webkit-user-select: text;
|
|
111
|
-
user-select: text;
|
|
112
|
-
font-size: #{$size-font-size};
|
|
113
|
-
line-height: #{$size-line-height};
|
|
114
|
-
overflow: auto;
|
|
115
|
-
transition:
|
|
116
|
-
box-shadow #{$transition-duration} ease,
|
|
117
|
-
border-color #{$transition-duration} ease,
|
|
118
|
-
background-color #{$transition-duration} ease,
|
|
119
|
-
color #{$transition-duration} ease,
|
|
120
|
-
border-radius #{$transition-duration} ease;
|
|
121
|
-
|
|
122
|
-
// Firefox
|
|
123
|
-
-moz-appearance: textfield;
|
|
124
|
-
appearance: textfield;
|
|
125
|
-
|
|
126
|
-
// Chrome, Edge, Safari
|
|
127
|
-
&::-webkit-outer-spin-button,
|
|
128
|
-
&::-webkit-inner-spin-button {
|
|
129
|
-
-webkit-appearance: none;
|
|
130
|
-
margin: 0;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
&:focus,
|
|
134
|
-
&:active,
|
|
135
|
-
&:hover {
|
|
136
|
-
outline: none;
|
|
137
|
-
border: none;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
&::placeholder {
|
|
141
|
-
color: rgba(#{$field-placeholder-color});
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
.#{$field-input-editable} {
|
|
146
|
-
flex: 1 1 auto;
|
|
147
|
-
min-width: 0;
|
|
148
|
-
min-height: 0;
|
|
149
|
-
display: block;
|
|
150
|
-
position: relative;
|
|
151
|
-
z-index: 2;
|
|
152
|
-
background-color: transparent;
|
|
153
|
-
color: rgba(#{$field-color});
|
|
154
|
-
caret-color: rgba(#{$field-color});
|
|
155
|
-
border: none;
|
|
156
|
-
// user-select:all breaks caret placement on many mobile browsers for contenteditable.
|
|
157
|
-
-webkit-user-select: text;
|
|
158
|
-
user-select: text;
|
|
159
|
-
font-size: #{$size-font-size};
|
|
160
|
-
line-height: #{$size-line-height};
|
|
161
|
-
box-sizing: border-box;
|
|
162
|
-
width: 100%;
|
|
163
|
-
overflow: auto;
|
|
164
|
-
outline: none;
|
|
165
|
-
|
|
166
|
-
&:focus,
|
|
167
|
-
&:active {
|
|
168
|
-
outline: none;
|
|
169
|
-
border: none;
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
// Message
|
|
174
|
-
.#{$field-message} {
|
|
175
|
-
color: rgba(#{$field-background-color});
|
|
176
|
-
font-size: 0.9em;
|
|
177
|
-
line-height: 1.5;
|
|
178
|
-
transition:
|
|
179
|
-
box-shadow #{$transition-duration} ease,
|
|
180
|
-
border-color #{$transition-duration} ease,
|
|
181
|
-
background-color #{$transition-duration} ease,
|
|
182
|
-
color #{$transition-duration} ease,
|
|
183
|
-
border-radius #{$transition-duration} ease;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
// Help
|
|
187
|
-
.#{$field-help} {
|
|
188
|
-
color: rgba(#{$field-help-color});
|
|
189
|
-
font-size: 0.8em;
|
|
190
|
-
line-height: 1.5;
|
|
191
|
-
transition:
|
|
192
|
-
box-shadow #{$transition-duration} ease,
|
|
193
|
-
border-color #{$transition-duration} ease,
|
|
194
|
-
background-color #{$transition-duration} ease,
|
|
195
|
-
color #{$transition-duration} ease,
|
|
196
|
-
border-radius #{$transition-duration} ease;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
&.focus {
|
|
200
|
-
&.shadow {
|
|
201
|
-
.#{$field-content} {
|
|
202
|
-
box-shadow: 0 0 0 0.25rem rgba(#{$field-border-color}, 0.25);
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
&:not(.shadow) {
|
|
207
|
-
.#{$field-content} {
|
|
208
|
-
box-shadow: 0 0 0 calc(#{$border-width} * 1.5) rgba(#{$field-border-color});
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
&.disabled {
|
|
214
|
-
opacity: 0.5;
|
|
215
|
-
cursor: not-allowed;
|
|
216
|
-
div.#{$field-input},
|
|
217
|
-
input.#{$field-input},
|
|
218
|
-
.#{$field-input-editable} {
|
|
219
|
-
cursor: not-allowed;
|
|
220
|
-
-webkit-user-select: none;
|
|
221
|
-
user-select: none;
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
&.empty:not(.typing) {
|
|
226
|
-
div.#{$field-input} {
|
|
227
|
-
&::before {
|
|
228
|
-
content: attr(placeholder);
|
|
229
|
-
color: rgba(#{$field-placeholder-color});
|
|
230
|
-
transition: color #{$transition-duration} ease;
|
|
231
|
-
position: absolute;
|
|
232
|
-
height: calc(#{$size-control-block-size} - #{$border-width} * 2);
|
|
233
|
-
box-sizing: border-box;
|
|
234
|
-
top: 0;
|
|
235
|
-
pointer-events: none;
|
|
236
|
-
z-index: 0;
|
|
237
|
-
display: block;
|
|
238
|
-
white-space: pre-wrap;
|
|
239
|
-
word-break: break-word;
|
|
240
|
-
line-height: inherit;
|
|
241
|
-
font-size: inherit;
|
|
242
|
-
display: flex;
|
|
243
|
-
align-items: center;
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
// Type
|
|
249
|
-
&.paragraph {
|
|
250
|
-
div.#{$field-input} {
|
|
251
|
-
align-items: flex-start;
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
.#{$field-input-editable} {
|
|
255
|
-
white-space: pre-wrap;
|
|
256
|
-
word-break: break-word;
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
&.text {
|
|
261
|
-
.#{$field-input-editable},
|
|
262
|
-
input.#{$field-input} {
|
|
263
|
-
white-space: nowrap;
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
&.password {
|
|
268
|
-
input.#{$field-input} {
|
|
269
|
-
white-space: nowrap;
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
// Direction
|
|
274
|
-
div.#{$field-input} {
|
|
275
|
-
justify-content: #{$direction-justify-content};
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
.#{$field-input-editable},
|
|
279
|
-
input.#{$field-input} {
|
|
280
|
-
text-align: #{$direction-text-align};
|
|
281
|
-
}
|
|
282
|
-
}
|
|
@@ -1,294 +0,0 @@
|
|
|
1
|
-
<style lang="scss" src="./outline.scss" scoped></style>
|
|
2
|
-
<template src="./outline.html"></template>
|
|
3
|
-
<script lang="ts" setup>
|
|
4
|
-
import { computed, nextTick, onMounted, ref, watch } from "vue";
|
|
5
|
-
import type { FieldProps, FieldEmit } from "../field.type";
|
|
6
|
-
import { cssProperty, cssPrefix } from "../../../utils";
|
|
7
|
-
|
|
8
|
-
// Component setup (props, emits, injects)
|
|
9
|
-
// ----------------------------------------------------------------------------
|
|
10
|
-
const props = withDefaults(defineProps<FieldProps>(), {
|
|
11
|
-
modelValue: "",
|
|
12
|
-
type: "text",
|
|
13
|
-
size: "standard",
|
|
14
|
-
disabled: false,
|
|
15
|
-
readonly: false,
|
|
16
|
-
message: "",
|
|
17
|
-
help: "",
|
|
18
|
-
variant: "fill",
|
|
19
|
-
placeholder: "",
|
|
20
|
-
shadow: undefined,
|
|
21
|
-
direction: undefined,
|
|
22
|
-
});
|
|
23
|
-
const emit = defineEmits<FieldEmit>();
|
|
24
|
-
|
|
25
|
-
// Reactive state
|
|
26
|
-
// ----------------------------------------------------------------------------
|
|
27
|
-
const isFocus = ref(false);
|
|
28
|
-
const contentRef = ref<HTMLElement>();
|
|
29
|
-
const caret = ref(0);
|
|
30
|
-
const isComposing = ref(false);
|
|
31
|
-
|
|
32
|
-
// Computed properties
|
|
33
|
-
// ----------------------------------------------------------------------------
|
|
34
|
-
const content = computed(() => {
|
|
35
|
-
if (props.value !== undefined && props.value !== null) {
|
|
36
|
-
return props.value;
|
|
37
|
-
}
|
|
38
|
-
return props.modelValue ?? "";
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
const isContentEmpty = computed(() => {
|
|
42
|
-
const v = content.value;
|
|
43
|
-
return v === "" || v === undefined || v === null;
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
const fieldAttrs = computed(() => {
|
|
47
|
-
return {
|
|
48
|
-
class: [
|
|
49
|
-
cssPrefix(["layer", "field"]),
|
|
50
|
-
cssPrefix(["role", props.role || ""]),
|
|
51
|
-
cssPrefix(["shape", props.shape || ""]),
|
|
52
|
-
cssPrefix("field"),
|
|
53
|
-
cssPrefix(["size", props.size]),
|
|
54
|
-
cssPrefix(["direction", props.direction || "left"]),
|
|
55
|
-
props.variant,
|
|
56
|
-
props.type,
|
|
57
|
-
{
|
|
58
|
-
disabled: props.disabled,
|
|
59
|
-
focus: isFocus.value,
|
|
60
|
-
shadow: props.shadow,
|
|
61
|
-
empty: isContentEmpty.value,
|
|
62
|
-
readonly: props.readonly,
|
|
63
|
-
typing: isComposing.value,
|
|
64
|
-
},
|
|
65
|
-
],
|
|
66
|
-
style: {
|
|
67
|
-
[cssProperty(["field", "line"])]: props.line,
|
|
68
|
-
[cssProperty(["field", "max-line"])]: props.maxLine || props.line,
|
|
69
|
-
},
|
|
70
|
-
};
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
const fieldContentAttrs = computed(() => ({
|
|
74
|
-
class: [cssPrefix("field-content")],
|
|
75
|
-
}));
|
|
76
|
-
|
|
77
|
-
/** Outer shell: layout, placeholder pseudo-element (must stay off the contenteditable node on iOS). */
|
|
78
|
-
const fieldInputShellAttrs = computed(() => ({
|
|
79
|
-
class: [cssPrefix("field-input")],
|
|
80
|
-
placeholder: props.placeholder,
|
|
81
|
-
}));
|
|
82
|
-
|
|
83
|
-
/** contenteditable as the literal string "true"|"false" improves mobile WebKit behavior vs boolean. */
|
|
84
|
-
const fieldEditableAttrs = computed(() => ({
|
|
85
|
-
class: [cssPrefix("field-input-editable")],
|
|
86
|
-
name: props.name,
|
|
87
|
-
id: props.id,
|
|
88
|
-
contenteditable:
|
|
89
|
-
props.type === "password" ? undefined : props.disabled || props.readonly ? "false" : "true",
|
|
90
|
-
autocomplete: props.autocomplete,
|
|
91
|
-
tabindex: props.readonly ? 0 : props.disabled ? -1 : props.tabindex,
|
|
92
|
-
}));
|
|
93
|
-
|
|
94
|
-
const fieldPasswordInputAttrs = computed(() => ({
|
|
95
|
-
class: [cssPrefix("field-input")],
|
|
96
|
-
name: props.name,
|
|
97
|
-
id: props.id,
|
|
98
|
-
placeholder: props.placeholder,
|
|
99
|
-
autocomplete: props.autocomplete,
|
|
100
|
-
tabindex: props.readonly ? 0 : props.disabled ? -1 : props.tabindex,
|
|
101
|
-
readonly: props.readonly,
|
|
102
|
-
disabled: props.disabled,
|
|
103
|
-
}));
|
|
104
|
-
|
|
105
|
-
const fieldMessageAttrs = computed(() => ({
|
|
106
|
-
class: [cssPrefix("field-message")],
|
|
107
|
-
}));
|
|
108
|
-
|
|
109
|
-
const fieldHelpAttrs = computed(() => ({
|
|
110
|
-
class: [cssPrefix("field-help")],
|
|
111
|
-
}));
|
|
112
|
-
|
|
113
|
-
// Methods
|
|
114
|
-
// ----------------------------------------------------------------------------
|
|
115
|
-
const isBr = (node: Node): node is HTMLBRElement =>
|
|
116
|
-
node.nodeType === 1 && (node as HTMLElement).tagName === "BR";
|
|
117
|
-
|
|
118
|
-
const isBlockLineBreak = (node: Node, parent: Node | null): node is HTMLElement =>
|
|
119
|
-
parent != null && node.nodeType === 1 && ["DIV", "P"].includes((node as HTMLElement).tagName);
|
|
120
|
-
|
|
121
|
-
const getCaretOffset = (el: HTMLElement) => {
|
|
122
|
-
const selection = window.getSelection();
|
|
123
|
-
if (!selection || selection.rangeCount === 0) return 0;
|
|
124
|
-
|
|
125
|
-
const range = selection.getRangeAt(0);
|
|
126
|
-
const endContainer = range.endContainer;
|
|
127
|
-
const endOffset = range.endOffset;
|
|
128
|
-
let offset = 0;
|
|
129
|
-
|
|
130
|
-
function walk(node: Node, parent: Node | null): boolean {
|
|
131
|
-
if (node === endContainer) {
|
|
132
|
-
if (node.nodeType === 3) {
|
|
133
|
-
offset += endOffset;
|
|
134
|
-
} else if (isBr(node)) {
|
|
135
|
-
offset += endOffset > 0 ? 1 : 0;
|
|
136
|
-
} else if (isBlockLineBreak(node, parent)) {
|
|
137
|
-
offset += 1;
|
|
138
|
-
} else if (node === el) {
|
|
139
|
-
for (let i = 0; i < endOffset; i++) {
|
|
140
|
-
const child = node.childNodes[i];
|
|
141
|
-
if (!child) break;
|
|
142
|
-
if (child.nodeType === 3) offset += child.textContent?.length ?? 0;
|
|
143
|
-
else if (isBr(child)) offset += 1;
|
|
144
|
-
else if (isBlockLineBreak(child, el)) offset += 1;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
return true;
|
|
148
|
-
}
|
|
149
|
-
if (node.nodeType === 3) {
|
|
150
|
-
offset += node.textContent?.length ?? 0;
|
|
151
|
-
} else if (isBr(node)) {
|
|
152
|
-
offset += 1;
|
|
153
|
-
} else if (isBlockLineBreak(node, parent)) {
|
|
154
|
-
offset += 1;
|
|
155
|
-
}
|
|
156
|
-
for (const child of Array.from(node.childNodes)) {
|
|
157
|
-
if (walk(child, node)) return true;
|
|
158
|
-
}
|
|
159
|
-
return false;
|
|
160
|
-
}
|
|
161
|
-
walk(el, null);
|
|
162
|
-
return offset;
|
|
163
|
-
};
|
|
164
|
-
|
|
165
|
-
const setCaretOffset = (el: HTMLElement, offset: number) => {
|
|
166
|
-
const sel = window.getSelection();
|
|
167
|
-
if (!sel) return;
|
|
168
|
-
let current = 0;
|
|
169
|
-
const range = document.createRange();
|
|
170
|
-
|
|
171
|
-
function walk(node: Node): boolean {
|
|
172
|
-
if (node.nodeType === 3) {
|
|
173
|
-
const len = node.textContent?.length ?? 0;
|
|
174
|
-
const next = current + len;
|
|
175
|
-
if (offset <= next) {
|
|
176
|
-
range.setStart(node, Math.min(offset - current, len));
|
|
177
|
-
range.collapse(true);
|
|
178
|
-
sel!.removeAllRanges();
|
|
179
|
-
sel!.addRange(range);
|
|
180
|
-
return true;
|
|
181
|
-
}
|
|
182
|
-
current = next;
|
|
183
|
-
} else if (isBr(node)) {
|
|
184
|
-
if (offset <= current) {
|
|
185
|
-
range.setStartBefore(node);
|
|
186
|
-
range.collapse(true);
|
|
187
|
-
sel!.removeAllRanges();
|
|
188
|
-
sel!.addRange(range);
|
|
189
|
-
return true;
|
|
190
|
-
}
|
|
191
|
-
if (offset <= current + 1) {
|
|
192
|
-
range.setStartAfter(node);
|
|
193
|
-
range.collapse(true);
|
|
194
|
-
sel!.removeAllRanges();
|
|
195
|
-
sel!.addRange(range);
|
|
196
|
-
return true;
|
|
197
|
-
}
|
|
198
|
-
current += 1;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
for (const child of Array.from(node.childNodes)) {
|
|
202
|
-
if (walk(child)) return true;
|
|
203
|
-
}
|
|
204
|
-
return false;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
walk(el);
|
|
208
|
-
};
|
|
209
|
-
|
|
210
|
-
const onInput = (ev: Event) => {
|
|
211
|
-
if (props.disabled || props.readonly || isComposing.value) return;
|
|
212
|
-
|
|
213
|
-
caret.value = getCaretOffset(ev.target as HTMLElement);
|
|
214
|
-
emit("input", ev);
|
|
215
|
-
};
|
|
216
|
-
|
|
217
|
-
const onCompositionStart = () => {
|
|
218
|
-
isComposing.value = true;
|
|
219
|
-
};
|
|
220
|
-
|
|
221
|
-
const onCompositionEnd = (ev: CompositionEvent) => {
|
|
222
|
-
const el = ev.target as HTMLElement;
|
|
223
|
-
isComposing.value = false;
|
|
224
|
-
nextTick(() => {
|
|
225
|
-
caret.value = getCaretOffset(el);
|
|
226
|
-
const inputEv = new InputEvent("input", { bubbles: true });
|
|
227
|
-
el.dispatchEvent(inputEv);
|
|
228
|
-
emit("input", inputEv);
|
|
229
|
-
});
|
|
230
|
-
};
|
|
231
|
-
|
|
232
|
-
const normalizeText = (s: string) => s.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
233
|
-
|
|
234
|
-
const ensureEditableCanReceiveCaret = (el: HTMLElement) => {
|
|
235
|
-
// iOS Safari often refuses to show caret / accept input in an empty contenteditable.
|
|
236
|
-
if (!el.textContent?.length && el.childNodes.length === 0) {
|
|
237
|
-
el.appendChild(document.createElement("br"));
|
|
238
|
-
}
|
|
239
|
-
};
|
|
240
|
-
|
|
241
|
-
const syncContentFromModel = async () => {
|
|
242
|
-
const el = contentRef.value;
|
|
243
|
-
if (!el || props.type === "password") return;
|
|
244
|
-
if (isComposing.value) return;
|
|
245
|
-
|
|
246
|
-
const next = normalizeText(content.value.toString() ?? "");
|
|
247
|
-
const current = normalizeText(el.innerText);
|
|
248
|
-
if (current === next) return;
|
|
249
|
-
|
|
250
|
-
if (isFocus.value) {
|
|
251
|
-
const saved = caret.value;
|
|
252
|
-
el.innerText = next;
|
|
253
|
-
await nextTick();
|
|
254
|
-
el.focus();
|
|
255
|
-
setCaretOffset(el, Math.min(saved, next.length));
|
|
256
|
-
} else {
|
|
257
|
-
el.innerText = next;
|
|
258
|
-
}
|
|
259
|
-
};
|
|
260
|
-
|
|
261
|
-
const onFocus = (ev: FocusEvent) => {
|
|
262
|
-
if (props.disabled) return;
|
|
263
|
-
isFocus.value = true;
|
|
264
|
-
const el = contentRef.value;
|
|
265
|
-
if (el && props.type !== "password") {
|
|
266
|
-
ensureEditableCanReceiveCaret(el);
|
|
267
|
-
}
|
|
268
|
-
emit("focus", ev);
|
|
269
|
-
};
|
|
270
|
-
|
|
271
|
-
const onBlur = (ev: FocusEvent) => {
|
|
272
|
-
if (props.disabled) return;
|
|
273
|
-
isFocus.value = false;
|
|
274
|
-
emit("blur", ev);
|
|
275
|
-
};
|
|
276
|
-
|
|
277
|
-
const onBeforeinput = (ev: Event) => {
|
|
278
|
-
if (props.disabled || props.readonly) {
|
|
279
|
-
ev.preventDefault();
|
|
280
|
-
return;
|
|
281
|
-
}
|
|
282
|
-
emit("beforeinput", ev);
|
|
283
|
-
};
|
|
284
|
-
|
|
285
|
-
// Lifecycle
|
|
286
|
-
// ----------------------------------------------------------------------------
|
|
287
|
-
watch(
|
|
288
|
-
() => content.value,
|
|
289
|
-
() => void syncContentFromModel(),
|
|
290
|
-
{ flush: "post" }
|
|
291
|
-
);
|
|
292
|
-
|
|
293
|
-
onMounted(() => void syncContentFromModel());
|
|
294
|
-
</script>
|