Refactor Vue components using Composition API #230

- Migrate `StatefulVue`:
  - Introduce `UseCollectionState` that replaces its behavior and acts
    as a shared state store.
  - Add more encapsulated, granular functions based on read or write
    access to state in CollectionState.
- Some linting rules get activates due to new code-base compability to
  modern parses, fix linting errors.
  - Rename Dialog to ModalDialog as after refactoring,
    eslintvue/no-reserved-component-names does not allow name Dialog.
  - To comply with `vue/multi-word-component-names`, rename:
    - `Code`          -> `CodeInstruction`
    - `Handle`        -> `SliderHandle`
    - `Documentable`  -> `DocumentableNode`
    - `Node`          -> `NodeContent`
    - `INode`         -> `INodeContent`
    - `Responsive`    -> `SizeObserver`
- Remove `vue-property-decorator` and `vue-class-component`
  dependencies.
- Refactor `watch` with computed properties when possible for cleaner
  code.
  - Introduce `UseApplication` to reduce repeated code in new components
    that use `computed` more heavily than before.
- Change TypeScript target to `es2017` to allow top level async calls
  for getting application context/state/instance to simplify the code by
  removing async calls. However, mocha (unit and integration) tests do
  not run with top level awaits, so a workaround is used.
This commit is contained in:
undergroundwires
2023-08-07 13:16:39 +02:00
parent 3a594ac7fd
commit 1b9be8fe2d
67 changed files with 2135 additions and 1267 deletions

View File

@@ -2,16 +2,16 @@
<div
class="slider"
v-bind:style="{
'--vertical-margin': this.verticalMargin,
'--first-min-width': this.firstMinWidth,
'--first-initial-width': this.firstInitialWidth,
'--second-min-width': this.secondMinWidth,
'--vertical-margin': verticalMargin,
'--first-min-width': firstMinWidth,
'--first-initial-width': firstInitialWidth,
'--second-min-width': secondMinWidth,
}"
>
<div class="first" ref="firstElement">
<slot name="first" />
</div>
<Handle class="handle" @resized="onResize($event)" />
<SliderHandle class="handle" @resized="onResize($event)" />
<div class="second">
<slot name="second" />
</div>
@@ -19,30 +19,45 @@
</template>
<script lang="ts">
import { Component, Vue, Prop } from 'vue-property-decorator';
import Handle from './Handle.vue';
import { defineComponent, ref } from 'vue';
import SliderHandle from './SliderHandle.vue';
@Component({
export default defineComponent({
components: {
Handle,
SliderHandle,
},
})
export default class HorizontalResizeSlider extends Vue {
@Prop() public verticalMargin: string;
props: {
verticalMargin: {
type: String,
required: true,
},
firstMinWidth: {
type: String,
required: true,
},
firstInitialWidth: {
type: String,
required: true,
},
secondMinWidth: {
type: String,
required: true,
},
},
setup() {
const firstElement = ref<HTMLElement>();
@Prop() public firstMinWidth: string;
function onResize(displacementX: number): void {
const leftWidth = firstElement.value.offsetWidth + displacementX;
firstElement.value.style.width = `${leftWidth}px`;
}
@Prop() public firstInitialWidth: string;
@Prop() public secondMinWidth: string;
private get left(): HTMLElement { return this.$refs.firstElement as HTMLElement; }
public onResize(displacementX: number): void {
const leftWidth = this.left.offsetWidth + displacementX;
this.left.style.width = `${leftWidth}px`;
}
}
return {
firstElement,
onResize,
};
},
});
</script>
<style lang="scss" scoped>