Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deployment #4346

Merged
merged 7 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion packages/editor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,13 @@ See below for the current API specification.
- **Long-Term Support**: Unsure
- **Needs Change?**: Unsure

### `SerloEditor` component props
#### 7. `type LearnerEventData`

- **Why Exported/How Used**: This is how the `SerloRenderer` provides the details of a learners interaction to `handleLearnerEvent` (see below).
- **Long-Term Support**: Unsure
- **Needs Change?**: Unsure

### `SerloEditor` component props (`SerloEditorProps`)

- **`children`**: When passed in a function as the `children` prop, the `SerloEditor` component provides an `editor` render prop as the argument to the `children` function. This `editor` object provides:

Expand All @@ -107,6 +113,12 @@ See below for the current API specification.

- **`_ltik` (optional)**: Required by the custom plugin `edusharingAsset` only used in `serlo-editor-for-edusharing`. **To be removed once a better solution is found or the plugin is removed.**

### `SerloRenderer` component props (`SerloRendererProps`)

- For `language`, `state`, `_ltik` and `editorVariant` please see props for `SerloEditor` above.

- **`handleLearnerEvent` (optional)**: Function that receives details about the learners interaction in the form of `LearnerEventData`. Provide if you want to connect the editor to you LRS (Learning Record Store) or similar. [In our wiki you can find more details and a xAPI example](https://github.com/serlo/documentation/wiki/Learner-Events-and-xAPI).

### `pluginMenuEn` / `pluginMenuDe` constant and `Plugin` enum

Exports two records with following structure which you can use to create your own plugin menu in either German or English. This is useful when you for example want to integrate the Serlo Editor as a block / part of another editor.
Expand Down
5 changes: 5 additions & 0 deletions packages/editor/src/___dev-demo/preview.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { showToastNotice } from '@editor/editor-ui/show-toast-notice'
import { EditorPluginType, SerloEditor, SerloRenderer } from '@editor/package'
import { LearnerEventData } from '@editor/plugin/helpers/editor-learner-event'
import { parseDocumentString } from '@editor/static-renderer/helper/parse-document-string'
import { AnyEditorDocument } from '@editor/types/editor-plugins'
import { useMemo, useState } from 'react'
Expand Down Expand Up @@ -90,6 +91,10 @@ export function Preview() {
<SerloRenderer
state={parseDocumentString(previewState)}
editorVariant="unknown"
handleLearnerEvent={(data: LearnerEventData) => {
// eslint-disable-next-line no-console
console.log(data)
}}
/>
</div>
</section>
Expand Down
1 change: 1 addition & 0 deletions packages/editor/src/package/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export { SerloRenderer, type SerloRendererProps } from './serlo-renderer'

export type { SupportedLanguage } from '@editor/types/language-data'
export type { BaseEditor } from '@editor/core'
export type { LearnerEventData } from '@editor/plugin/helpers/editor-learner-event'

// We need to make a distinction between entires on our menu and technical
// plugin types Internally we have for example a `scMcExercise` which has a
Expand Down
9 changes: 9 additions & 0 deletions packages/editor/src/package/serlo-renderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import { EditorMetaContext } from '@editor/core/contexts/editor-meta-context'
import { createRenderers } from '@editor/editor-integration/create-renderers'
import { EditStringsProvider } from '@editor/i18n/edit-strings-provider'
import { StaticStringsProvider } from '@editor/i18n/static-strings-provider'
import {
editorLearnerEvent,
LearnerEventData,
} from '@editor/plugin/helpers/editor-learner-event'
import { editorRenderers } from '@editor/plugin/helpers/editor-renderer'
import { StaticRenderer } from '@editor/static-renderer/static-renderer'
import type { SupportedLanguage } from '@editor/types/language-data'
Expand All @@ -16,6 +20,7 @@ export interface SerloRendererProps {
state: unknown
_ltik?: string
editorVariant: EditorVariant
handleLearnerEvent?: (data: LearnerEventData) => void
}

export function SerloRenderer(props: SerloRendererProps) {
Expand All @@ -36,6 +41,10 @@ export function SerloRenderer(props: SerloRendererProps) {
const basicRenderers = createRenderers()
editorRenderers.init(basicRenderers)

if (props.handleLearnerEvent) {
editorLearnerEvent.init(props.handleLearnerEvent)
}

return (
<StaticStringsProvider value={staticStrings}>
<EditStringsProvider value={editStrings}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function BlankCheckButton(props: BlankCheckButtonProps) {
const isCorrect = [...feedback].every((entry) => entry[1].isCorrect)

return (
<div className="mt-2 flex">
<div className="mx-side mt-5 flex">
<button
className="serlo-button-learner-primary mr-3 h-8"
onClick={onClick}
Expand Down
2 changes: 1 addition & 1 deletion packages/editor/src/plugins/blanks-exercise/renderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ export function BlanksExerciseRenderer({
<DndWrapper>
<div
className={cn(
'mx-side mb-block',
'mb-block',
// Increase Slate line height in the editor
'[&>div>div>div[data-slate-node="element"]]:leading-[30px]',
// Increase Slate line height in the renderer
Expand Down
28 changes: 14 additions & 14 deletions packages/editor/src/plugins/exercise/editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,22 +88,22 @@ export function ExerciseEditor(props: ExerciseProps) {
</div>
<div className="h-10"></div>
<div className="mx-side">
{/* Special case for the blanks exercise: Until the child plugin is selected we hide the task to avoid confusion */}
{/* Background: Users often add their blanks-text to the task */}
<div
className={cn(
'group-has-[.blanks-child-plugin-selection]/exercise:hidden',
'[&_.plugin-rows]:pl-[7px]'
)}
>
{content.render({
config: {
textPluginPlaceholder: exStrings.placeholder,
},
})}
</div>
{interactive.defined ? (
<>
{/* Special case for the blanks exercise: Until the child plugin is selected we hide the task to avoid confusion */}
{/* Background: Users often add their blanks-text to the task */}
<div
className={cn(
'group-has-[.blanks-child-plugin-selection]/exercise:hidden',
'[&_.plugin-rows]:pl-[7px]'
)}
>
{content.render({
config: {
textPluginPlaceholder: exStrings.placeholder,
},
})}
</div>
{interactive.render()}
{hideInteractiveInitially.defined ? (
<small className="bg-editor-primary-200 p-1">
Expand Down
Loading