Skip to content

Commit aed7015

Browse files
committed
various TS build error/warning fixes
1 parent 0230ec9 commit aed7015

File tree

19 files changed

+109
-77
lines changed

19 files changed

+109
-77
lines changed

packages/courses/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
{
22
"name": "@vue-skuilder/courses",
33
"version": "0.1.0",
4+
"type": "module",
45
"main": "dist/index.js",
56
"module": "dist/index.mjs",
67
"types": "dist/index.d.ts",
78
"files": [
8-
"dist"
9+
"dist",
10+
"src/assets"
911
],
1012
"scripts": {
1113
"build": "yarn clean && vite build",

packages/courses/src/chess/chessground/chessground.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export function Chessground(element: HTMLElement, config?: Config): Api {
4545
state.drawable.prevSvgHash = '';
4646
updateBounds(state);
4747
redrawNow(false);
48-
events.bindBoard(state, onResize);
48+
events.bindBoard(state);
4949
if (!prevUnbind) state.dom.unbind = events.bindDocument(state, onResize);
5050
state.events.insert && state.events.insert(elements);
5151
return state;

packages/courses/src/chess/chessground/events.ts

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ import * as cg from './types';
88
type MouchBind = (e: cg.MouchEvent) => void;
99
type StateMouchBind = (d: State, e: cg.MouchEvent) => void;
1010

11-
export function bindBoard(s: State, onResize: () => void): void {
11+
export function bindBoard(s: State): void {
1212
const boardEl = s.dom.elements.board;
1313

1414
// if ('ResizeObserver' in window) new ResizeObserver(onResize).observe(s.dom.elements.wrap);
1515

1616
if (s.disableContextMenu || s.drawable.enabled) {
17-
boardEl.addEventListener('contextmenu', e => e.preventDefault());
17+
boardEl.addEventListener('contextmenu', (e) => e.preventDefault());
1818
}
1919

2020
if (s.viewOnly) return;
@@ -36,51 +36,53 @@ export function bindDocument(s: State, onResize: () => void): cg.Unbind {
3636

3737
// Old versions of Edge and Safari do not support ResizeObserver. Send
3838
// chessground.resize if a user action has changed the bounds of the board.
39-
if (!('ResizeObserver' in window)) unbinds.push(unbindable(document.body, 'chessground.resize', onResize));
39+
if (!('ResizeObserver' in window))
40+
unbinds.push(unbindable(document.body, 'chessground.resize', onResize));
4041

4142
if (!s.viewOnly) {
4243
const onmove = dragOrDraw(s, drag.move, draw.move);
4344
const onend = dragOrDraw(s, drag.end, draw.end);
4445

4546
for (const ev of ['touchmove', 'mousemove'])
4647
unbinds.push(unbindable(document, ev, onmove as EventListener));
47-
for (const ev of ['touchend', 'mouseup']) unbinds.push(unbindable(document, ev, onend as EventListener));
48+
for (const ev of ['touchend', 'mouseup'])
49+
unbinds.push(unbindable(document, ev, onend as EventListener));
4850

4951
const onScroll = () => s.dom.bounds.clear();
5052
unbinds.push(unbindable(document, 'scroll', onScroll, { capture: true, passive: true }));
5153
unbinds.push(unbindable(window, 'resize', onScroll, { passive: true }));
5254
}
5355

54-
return () => unbinds.forEach(f => f());
56+
return () => unbinds.forEach((f) => f());
5557
}
5658

5759
function unbindable(
5860
el: EventTarget,
5961
eventName: string,
6062
callback: EventListener,
61-
options?: AddEventListenerOptions,
63+
options?: AddEventListenerOptions
6264
): cg.Unbind {
6365
el.addEventListener(eventName, callback, options);
6466
return () => el.removeEventListener(eventName, callback, options);
6567
}
6668

6769
const startDragOrDraw =
6870
(s: State): MouchBind =>
69-
e => {
70-
if (s.draggable.current) drag.cancel(s);
71-
else if (s.drawable.current) draw.cancel(s);
72-
else if (e.shiftKey || isRightButton(e)) {
73-
if (s.drawable.enabled) draw.start(s, e);
74-
} else if (!s.viewOnly) {
75-
if (s.dropmode.active) drop(s, e);
76-
else drag.start(s, e);
77-
}
78-
};
71+
(e) => {
72+
if (s.draggable.current) drag.cancel(s);
73+
else if (s.drawable.current) draw.cancel(s);
74+
else if (e.shiftKey || isRightButton(e)) {
75+
if (s.drawable.enabled) draw.start(s, e);
76+
} else if (!s.viewOnly) {
77+
if (s.dropmode.active) drop(s, e);
78+
else drag.start(s, e);
79+
}
80+
};
7981

8082
const dragOrDraw =
8183
(s: State, withDrag: StateMouchBind, withDraw: StateMouchBind): MouchBind =>
82-
e => {
83-
if (s.drawable.current) {
84-
if (s.drawable.enabled) withDraw(s, e);
85-
} else if (!s.viewOnly) withDrag(s, e);
86-
};
84+
(e) => {
85+
if (s.drawable.current) {
86+
if (s.drawable.enabled) withDraw(s, e);
87+
} else if (!s.viewOnly) withDrag(s, e);
88+
};

packages/courses/src/chess/questions/puzzle/puzzle.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,11 @@ export default defineComponent({
145145
});
146146
};
147147
148-
const handlePromotion = (promotionPiece: PromotionPiece) => {
148+
const handlePromotion = (promotionPiece: PromotionPiece | string) => {
149+
if (promotionPiece !== 'q' && promotionPiece !== 'r' && promotionPiece !== 'b' && promotionPiece !== 'n') {
150+
viewableUtils.logger.error(`Invalid promotion piece: ${promotionPiece}`);
151+
return;
152+
}
149153
if (!promotionMove.value) return;
150154
151155
viewableUtils.logger.log(`promoting to ${promotionPiece}`);

packages/courses/src/default/questions/fillIn/fillIn.vue

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<template>
22
<div data-viewable="FillInView">
33
<audio-auto-player v-if="hasAudio" :src="audioURL" />
4-
<img v-if="hasImage" :src="imageURL" />
4+
<template v-if="hasImage">
5+
<img v-for="(url, index) in imageURLs" :key="index" :src="url" />
6+
</template>
57
<!-- Add v-if to prevent undefined markdown -->
68
<markdown-renderer v-if="markdownText" :md="markdownText" />
79
<radio-multiple-choice v-if="question?.options" :choice-list="truncatedOptions" />
@@ -20,13 +22,7 @@
2022

2123
<script lang="ts">
2224
import { defineAsyncComponent, defineComponent, ref, computed, PropType, onMounted, onUnmounted, watch } from 'vue';
23-
import {
24-
useViewable,
25-
useQuestionView,
26-
AudioAutoPlayer,
27-
RadioMultipleChoice,
28-
MarkdownRenderer,
29-
} from '@vue-skuilder/common-ui';
25+
import { useViewable, useQuestionView, AudioAutoPlayer, RadioMultipleChoice } from '@vue-skuilder/common-ui';
3026
import _ from 'lodash';
3127
import { BlanksCard } from './index';
3228
import gradeSpellingAttempt from './blanksCorrection';
@@ -100,7 +96,7 @@ export default defineComponent({
10096
10197
const hasImage = computed(() => !!props.data[0]['image-1']);
10298
103-
const imageURL = computed(() => {
99+
const imageURLs = computed(() => {
104100
if (!hasImage.value) return [''];
105101
106102
const urls: string[] = [];
@@ -236,7 +232,7 @@ export default defineComponent({
236232
question,
237233
truncatedOptions,
238234
hasImage,
239-
imageURL,
235+
imageURLs,
240236
hasAudio,
241237
audioURL,
242238
obscuredAnswer,

packages/courses/src/default/questions/fillIn/index.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Question, splitByDelimiters } from '@vue-skuilder/common-ui';
1+
import { Question, splitByDelimiters, containsComponent } from '@vue-skuilder/common-ui';
22
import { Answer, RadioMultipleChoiceAnswer, DataShape } from '@vue-skuilder/common';
33
import { Validator, ViewData } from '@vue-skuilder/common';
44
import { randomInt } from '@/math/utility';
@@ -24,6 +24,7 @@ export const BlanksCardDataShapes: DataShape[] = [
2424
];
2525

2626
// eslint-disable-next-line @typescript-eslint/no-unused-vars
27+
// @ts-expect-error
2728
const val: Validator = {
2829
test: (input) => {
2930
console.log(`Testing md input: ${input}`);
@@ -56,6 +57,25 @@ export interface FillInSection {
5657
text: string;
5758
}
5859

60+
function splitText(
61+
text: string,
62+
leftBound: string,
63+
rightBound: string
64+
): {
65+
left: string;
66+
middle: string;
67+
right: string;
68+
} {
69+
const leftSplit = text.split(leftBound);
70+
const left = leftSplit[0];
71+
72+
const rightSplit = leftSplit[1].split(rightBound);
73+
const middle = rightSplit[0];
74+
const right = rightSplit[1];
75+
76+
return { left, middle, right };
77+
}
78+
5979
export class BlanksCard extends Question {
6080
public static dataShapes = BlanksCardDataShapes;
6181
public static views = [FillInView];

packages/courses/src/math/questions/addition/horizontal.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export default defineComponent({
3434
3535
setup(props, { emit }) {
3636
const viewableUtils = useViewable(props, emit, 'AdditionHorizontal');
37-
const questionUtils = useQuestionView<SingleDigitAdditionQuestion>(viewableUtils, props.modifyDifficulty);
37+
const questionUtils = useQuestionView<SingleDigitAdditionQuestion>(viewableUtils);
3838
3939
const answer = ref('');
4040

packages/courses/src/math/questions/addition/verbal.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export default defineComponent({
3434
3535
setup(props, { emit }) {
3636
const viewableUtils = useViewable(props, emit, 'VerbalAddition');
37-
const questionUtils = useQuestionView<SingleDigitAdditionQuestion>(viewableUtils, props.modifyDifficulty);
37+
const questionUtils = useQuestionView<SingleDigitAdditionQuestion>(viewableUtils);
3838
3939
const answer = ref('');
4040

packages/courses/src/math/questions/angleCategorize/angleCategorize.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<h2>What kind of angle is this?</h2>
55
<canvas ref="canvasRef" width="300" height="300"> </canvas>
66

7-
<radio-multiple-choice :choice-list="question.answers" :mouse-trap="mouseTrap" />
7+
<radio-multiple-choice :choice-list="question.answers" />
88
</template>
99
</div>
1010
</template>
@@ -13,7 +13,7 @@
1313
import { defineComponent, ref, computed, onMounted, PropType } from 'vue';
1414
import { RadioMultipleChoice, useViewable, useQuestionView } from '@vue-skuilder/common-ui';
1515
import { AngleCategorize, AngleCategories } from './index';
16-
import { ViewData } from '@/base-course/Interfaces/ViewData';
16+
import { ViewData } from '@vue-skuilder/common';
1717
import { randomInt } from '../../utility';
1818
1919
export default defineComponent({
@@ -37,7 +37,7 @@ export default defineComponent({
3737
3838
setup(props, { emit }) {
3939
const viewableUtils = useViewable(props, emit, 'AngleCategorizeV');
40-
const questionUtils = useQuestionView<AngleCategorize>(viewableUtils, props.modifyDifficulty);
40+
const questionUtils = useQuestionView<AngleCategorize>(viewableUtils);
4141
const canvasRef = ref<HTMLCanvasElement | null>(null);
4242
4343
// Initialize question immediately

packages/courses/src/math/questions/countBy/default.vue

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
>s:
66
</div>
77

8-
<input type="text" disabled class="correct" :value="question?.answer[0] - question?.n" />,
8+
<input type="text" disabled class="correct" :value="question.answer[0] - question.n" />,
99

10-
<span v-for="(a, i) in question?.answer" :key="i">
10+
<span v-for="(a, i) in question.answer" :key="i">
1111
<input
1212
:id="`input${i}`"
1313
:ref="`input${i}`"
@@ -17,7 +17,7 @@
1717
:autofocus="i === 0"
1818
@keyup="track(i)"
1919
/>
20-
<span v-if="i !== question?.answer.length - 1">, </span>
20+
<span v-if="i !== question.answer.length - 1">, </span>
2121
</span>
2222
</div>
2323
</template>
@@ -53,7 +53,9 @@ export default defineComponent({
5353
questionUtils.question.value = new CountBy(props.data);
5454
5555
// Expose the question directly for template access
56-
const question = computed(() => questionUtils.question.value);
56+
const question = computed(() =>
57+
questionUtils.question.value ? questionUtils.question.value : new CountBy(props.data)
58+
);
5759
5860
const track = (n: number): void => {
5961
console.log(`change in ${n}!

0 commit comments

Comments
 (0)