@teacharium/widget 0.1.0 → 0.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/dist/main.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { PuckComponent } from '@measured/puck';
|
|
2
|
+
import { TeachariumComponentConfig } from './teacharium-widget';
|
|
3
|
+
import { React } from 'next/dist/server/route-modules/app-page/vendored/rsc/entrypoints';
|
|
4
|
+
type StandardLayoutProps = {
|
|
5
|
+
margin: number;
|
|
6
|
+
};
|
|
7
|
+
export declare const LayoutContainer: PuckComponent<StandardLayoutProps & {
|
|
8
|
+
children: React.ReactNode;
|
|
9
|
+
}>;
|
|
10
|
+
export declare const addStandardLayoutOptions: <T>(config: TeachariumComponentConfig<T>) => TeachariumComponentConfig<T & StandardLayoutProps>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { BaseField } from '@measured/puck';
|
|
2
|
+
export interface ImageMediaField extends BaseField {
|
|
3
|
+
type: "imageMedia";
|
|
4
|
+
label: string;
|
|
5
|
+
}
|
|
6
|
+
export interface VideoMediaField extends BaseField {
|
|
7
|
+
type: "videoMedia";
|
|
8
|
+
label: string;
|
|
9
|
+
}
|
|
10
|
+
export interface AudioMediaField extends BaseField {
|
|
11
|
+
type: "audioMedia";
|
|
12
|
+
label: string;
|
|
13
|
+
}
|
|
14
|
+
export interface ActionField extends BaseField {
|
|
15
|
+
type: "action";
|
|
16
|
+
label: string;
|
|
17
|
+
}
|
|
18
|
+
export interface VariableField extends BaseField {
|
|
19
|
+
type: "variable";
|
|
20
|
+
label: string;
|
|
21
|
+
}
|
|
22
|
+
export interface NumericExpressionField extends BaseField {
|
|
23
|
+
type: "numericExpression";
|
|
24
|
+
label: string;
|
|
25
|
+
}
|
|
26
|
+
export interface StringExpressionField extends BaseField {
|
|
27
|
+
type: "stringExpression";
|
|
28
|
+
label: string;
|
|
29
|
+
}
|
|
30
|
+
export interface ConditionField extends BaseField {
|
|
31
|
+
type: "condition";
|
|
32
|
+
label: string;
|
|
33
|
+
}
|
|
34
|
+
export type TeachariumCustomFields = ImageMediaField | VideoMediaField | AudioMediaField | ActionField | VariableField | NumericExpressionField | StringExpressionField | ConditionField;
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
export declare const EVENT_SOURCE_PLAYER = "player";
|
|
3
|
+
export declare const EVENT_SOURCE_FOOTER = "footer";
|
|
4
|
+
type EventListener<T = any> = (event: T) => void;
|
|
5
|
+
export interface BaseEvent {
|
|
6
|
+
type: string;
|
|
7
|
+
timestamp?: string;
|
|
8
|
+
emittedBy?: string;
|
|
9
|
+
}
|
|
10
|
+
export type VariableValue = string | number | boolean;
|
|
11
|
+
export interface UseNumberExpression {
|
|
12
|
+
(expression: string, defaultValue: number): number;
|
|
13
|
+
(expression: string): number | null;
|
|
14
|
+
}
|
|
15
|
+
export interface UseStringExpression {
|
|
16
|
+
(expression: string, defaultValue?: string): string;
|
|
17
|
+
}
|
|
18
|
+
export interface UseVariableValue {
|
|
19
|
+
(name: string): VariableValue | undefined;
|
|
20
|
+
}
|
|
21
|
+
export interface UseVariableValues {
|
|
22
|
+
(names: string[]): (VariableValue | undefined)[];
|
|
23
|
+
}
|
|
24
|
+
export interface UseUpdateVariable {
|
|
25
|
+
(newValue: VariableValue): void;
|
|
26
|
+
}
|
|
27
|
+
export interface UseMediaUrl {
|
|
28
|
+
(src: string, expiresIn?: number): {
|
|
29
|
+
data: string | undefined;
|
|
30
|
+
error: Error | null;
|
|
31
|
+
isError: boolean;
|
|
32
|
+
isLoading: boolean;
|
|
33
|
+
isLoadingError: boolean;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
export interface ConditionValue {
|
|
37
|
+
leftOperand: string;
|
|
38
|
+
operator: string;
|
|
39
|
+
rightOperand: string;
|
|
40
|
+
type: "string" | "number";
|
|
41
|
+
}
|
|
42
|
+
export interface UseConditionEvaluationResult {
|
|
43
|
+
result: boolean | null;
|
|
44
|
+
hasError: boolean;
|
|
45
|
+
}
|
|
46
|
+
export interface UseConditionEvaluation {
|
|
47
|
+
(condition: ConditionValue): UseConditionEvaluationResult;
|
|
48
|
+
}
|
|
49
|
+
export interface ItemOptions {
|
|
50
|
+
correctVariableName: string;
|
|
51
|
+
feedbackVariableName?: string;
|
|
52
|
+
attemptedVariableName?: string;
|
|
53
|
+
}
|
|
54
|
+
export interface UseIsItem {
|
|
55
|
+
(widgetId: string, options: ItemOptions): void;
|
|
56
|
+
}
|
|
57
|
+
export interface ItemData {
|
|
58
|
+
widgetId: string;
|
|
59
|
+
correctVariableName: string;
|
|
60
|
+
feedbackVariableName?: string;
|
|
61
|
+
attemptedVariableName?: string;
|
|
62
|
+
}
|
|
63
|
+
export interface ItemsContextValue {
|
|
64
|
+
items: Map<string, ItemData>;
|
|
65
|
+
registerItem: (widgetId: string, options: ItemOptions) => void;
|
|
66
|
+
unregisterItem: (widgetId: string) => void;
|
|
67
|
+
getItems: () => ItemData[];
|
|
68
|
+
}
|
|
69
|
+
export interface UseItemsContext {
|
|
70
|
+
(): ItemsContextValue;
|
|
71
|
+
}
|
|
72
|
+
export interface UseLessonEventEmitter {
|
|
73
|
+
(): <T extends BaseEvent = BaseEvent>(event: T) => void;
|
|
74
|
+
}
|
|
75
|
+
export interface UseLessonEventSubscription {
|
|
76
|
+
<T = any>(eventType: string, listener: EventListener<T>, priority?: number, deps?: React.DependencyList): void;
|
|
77
|
+
}
|
|
78
|
+
export interface TeachariumWidgetApi {
|
|
79
|
+
isEditing: boolean;
|
|
80
|
+
playerMode: "editing" | "preview" | "playbook";
|
|
81
|
+
events: {
|
|
82
|
+
/**
|
|
83
|
+
* Emit an event with type and params
|
|
84
|
+
* Example: api.events.emit({ type: "nextStep", params: {} })
|
|
85
|
+
*/
|
|
86
|
+
emit<T extends BaseEvent = BaseEvent>(event: T): void;
|
|
87
|
+
subscribe<T extends BaseEvent = BaseEvent>(eventType: string, listener: EventListener<T>): () => void;
|
|
88
|
+
unsubscribe(eventType: string, listener: EventListener): void;
|
|
89
|
+
};
|
|
90
|
+
React: any;
|
|
91
|
+
hooks: {
|
|
92
|
+
useNumberExpression: UseNumberExpression;
|
|
93
|
+
useStringExpression: UseStringExpression;
|
|
94
|
+
useVariableValue: UseVariableValue;
|
|
95
|
+
useVariableValues: UseVariableValues;
|
|
96
|
+
useUpdateVariable: (variableName: string) => UseUpdateVariable;
|
|
97
|
+
useMediaUrl: UseMediaUrl;
|
|
98
|
+
useConditionEvaluation: UseConditionEvaluation;
|
|
99
|
+
useIsItem: UseIsItem;
|
|
100
|
+
useItemsContext: UseItemsContext;
|
|
101
|
+
useLessonEventEmitter: UseLessonEventEmitter;
|
|
102
|
+
useLessonEventSubscription: UseLessonEventSubscription;
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* Create a transient variable that exists only during runtime
|
|
106
|
+
* Automatically prefixes the variable name with the widget ID
|
|
107
|
+
* Example: addVariable('selectedAnswer', 0) might create 'mcwidget1_selectedAnswer'
|
|
108
|
+
* @param name - Base name for the variable (will be prefixed with widget ID)
|
|
109
|
+
* @param initialValue - Initial value for the variable
|
|
110
|
+
* @param type - Optional type specification (auto-inferred if not provided)
|
|
111
|
+
* @returns The full variable name that was created
|
|
112
|
+
*/
|
|
113
|
+
addVariable: (name: string, initialValue: VariableValue, type?: "string" | "number" | "boolean") => string;
|
|
114
|
+
}
|
|
115
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { DefaultComponentProps, Fields, PuckComponent } from '@measured/puck';
|
|
2
|
+
import { TeachariumWidgetApi } from './teacharium-widget-api';
|
|
3
|
+
import { TeachariumCustomFields } from './teacharium-custom-fields';
|
|
4
|
+
interface TeachariumComponentProps {
|
|
5
|
+
api: TeachariumWidgetApi;
|
|
6
|
+
}
|
|
7
|
+
export interface TeachariumComponentConfig<T = {}> {
|
|
8
|
+
fields: Fields<DefaultComponentProps, TeachariumCustomFields>;
|
|
9
|
+
defaultProps: DefaultComponentProps;
|
|
10
|
+
render: PuckComponent<T & TeachariumComponentProps>;
|
|
11
|
+
}
|
|
12
|
+
export interface TeachariumWidget<T> {
|
|
13
|
+
name: string;
|
|
14
|
+
category: string;
|
|
15
|
+
config: TeachariumComponentConfig<T>;
|
|
16
|
+
}
|
|
17
|
+
export declare const registerWidget: (widget: TeachariumWidget<any>) => void;
|
|
18
|
+
export declare const getWidgets: () => TeachariumWidget<any>[];
|
|
19
|
+
declare global {
|
|
20
|
+
interface Window {
|
|
21
|
+
TeachariumComponents?: Record<string, TeachariumWidget<any>>;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export {};
|