@nibblearn/editor 0.0.0-stage → 0.3.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/LICENSE +21 -0
- package/README.md +28 -2
- package/dist/index.cjs +2023 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +223 -0
- package/dist/index.d.ts +223 -0
- package/dist/index.js +1987 -0
- package/dist/index.js.map +1 -0
- package/dist/styles.css +634 -0
- package/package.json +74 -3
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import { JsonSchema, MessageValues, ModuleRegistry, UiHint, ValidationIssue } from '@nibblearn/react';
|
|
2
|
+
|
|
3
|
+
/** A location inside a config: object keys and array indices. */
|
|
4
|
+
export type Path = ReadonlyArray<string | number>;
|
|
5
|
+
/** Read the value at `path` (own properties only). */
|
|
6
|
+
export declare function getAt(root: unknown, path: Path): unknown;
|
|
7
|
+
/**
|
|
8
|
+
* Return a copy of `root` with `value` at `path`; containers along the path are copied, the
|
|
9
|
+
* rest is shared. `undefined` removes an object key.
|
|
10
|
+
*/
|
|
11
|
+
export declare function setAt<T>(root: T, path: Path, value: unknown): T;
|
|
12
|
+
/** Remove the array item or object key at `path`. */
|
|
13
|
+
export declare function removeAt<T>(root: T, path: Path): T;
|
|
14
|
+
/** Insert `value` into the array at `path` before `index` (default: at the end). */
|
|
15
|
+
export declare function insertAt<T>(root: T, path: Path, value: unknown, index?: number): T;
|
|
16
|
+
/** Move the array item at `path` from `from` to `to`. */
|
|
17
|
+
export declare function moveItem<T>(root: T, path: Path, from: number, to: number): T;
|
|
18
|
+
export interface PickedImage {
|
|
19
|
+
src: string;
|
|
20
|
+
alt?: string;
|
|
21
|
+
}
|
|
22
|
+
export interface ModuleFormProps {
|
|
23
|
+
/** Module config in its input (authoring) form. */
|
|
24
|
+
value: Record<string, unknown>;
|
|
25
|
+
onChange: (next: Record<string, unknown>) => void;
|
|
26
|
+
/** Validation issues to show next to their fields (e.g. from `validateModule`). */
|
|
27
|
+
issues?: ValidationIssue[];
|
|
28
|
+
/** Registry used to find the module's schema. Defaults to the built-in modules. */
|
|
29
|
+
registry?: ModuleRegistry;
|
|
30
|
+
/** Called with the path of the list item that receives focus (for preview `focus`). */
|
|
31
|
+
onFocusPath?: (path: (string | number)[]) => void;
|
|
32
|
+
/** Opens the host's file picker; enables the "Choose image" button. */
|
|
33
|
+
onPickImage?: () => Promise<PickedImage | null>;
|
|
34
|
+
/** Use this JSON Schema instead of the module type's (e.g. lesson settings). */
|
|
35
|
+
schema?: JsonSchema;
|
|
36
|
+
className?: string;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* A form for any registered module, generated from its JSON Schema (field titles, hints and
|
|
40
|
+
* widgets come from the schema's `x-ui` metadata). Fully controlled.
|
|
41
|
+
*/
|
|
42
|
+
export declare function ModuleForm({ value, onChange, issues, registry, onFocusPath, onPickImage, schema: schemaOverride, className, }: ModuleFormProps): import("react").JSX.Element | null;
|
|
43
|
+
export interface ModuleEditorProps extends Omit<ModuleFormProps, "issues" | "onFocusPath"> {
|
|
44
|
+
/** "split" (default): form and preview side by side, stacked on narrow containers. */
|
|
45
|
+
layout?: "split" | "stacked" | "form";
|
|
46
|
+
/** Called whenever validity changes. */
|
|
47
|
+
onValidityChange?: (state: {
|
|
48
|
+
valid: boolean;
|
|
49
|
+
issues: ValidationIssue[];
|
|
50
|
+
}) => void;
|
|
51
|
+
}
|
|
52
|
+
/** A module form with a live preview that follows the item being edited. */
|
|
53
|
+
export declare function ModuleEditor({ layout, onValidityChange, ...form }: ModuleEditorProps): import("react").JSX.Element;
|
|
54
|
+
export interface BlockPickerProps {
|
|
55
|
+
registry?: ModuleRegistry;
|
|
56
|
+
/** Receives a new, valid module config. */
|
|
57
|
+
onPick: (config: Record<string, unknown>, info: {
|
|
58
|
+
type: string;
|
|
59
|
+
from: "example" | "empty";
|
|
60
|
+
}) => void;
|
|
61
|
+
/** Ids already used in the lesson; the new block gets a unique id. */
|
|
62
|
+
existingIds?: string[];
|
|
63
|
+
/** Start with example content (default) or blank placeholders. */
|
|
64
|
+
defaultFrom?: "example" | "empty";
|
|
65
|
+
}
|
|
66
|
+
/** A searchable catalogue of block types that creates ready-to-edit configs. */
|
|
67
|
+
export declare function BlockPicker({ registry, onPick, existingIds, defaultFrom, }: BlockPickerProps): import("react").JSX.Element;
|
|
68
|
+
export interface LessonEditorProps {
|
|
69
|
+
/** Lesson JSON (input form). */
|
|
70
|
+
value: Record<string, unknown>;
|
|
71
|
+
onChange: (next: Record<string, unknown>) => void;
|
|
72
|
+
registry?: ModuleRegistry;
|
|
73
|
+
onPickImage?: ModuleFormProps["onPickImage"];
|
|
74
|
+
}
|
|
75
|
+
/** Edit a whole lesson: the list of blocks, each block's settings with preview, and lesson settings. */
|
|
76
|
+
export declare function LessonEditor({ value, onChange, registry, onPickImage, }: LessonEditorProps): import("react").JSX.Element;
|
|
77
|
+
/** English UI strings of the editor. Override any of them through `NibblearnProvider messages`. */
|
|
78
|
+
export declare const editorMessages: {
|
|
79
|
+
readonly "editor.add": "Add {item}";
|
|
80
|
+
readonly "editor.remove": "Delete";
|
|
81
|
+
readonly "editor.removeItem": "Delete {item} {index}";
|
|
82
|
+
readonly "editor.duplicate": "Duplicate";
|
|
83
|
+
readonly "editor.duplicateItem": "Duplicate {item} {index}";
|
|
84
|
+
readonly "editor.moveUp": "Move up";
|
|
85
|
+
readonly "editor.moveUpItem": "Move {item} {index} up";
|
|
86
|
+
readonly "editor.moveDown": "Move down";
|
|
87
|
+
readonly "editor.moveDownItem": "Move {item} {index} down";
|
|
88
|
+
readonly "editor.expandItem": "Show {item} {index}";
|
|
89
|
+
readonly "editor.collapseItem": "Hide {item} {index}";
|
|
90
|
+
readonly "editor.itemAdded": "{item} added.";
|
|
91
|
+
readonly "editor.itemRemoved": "{item} {index} deleted.";
|
|
92
|
+
readonly "editor.itemMoved": "{item} moved to position {position}.";
|
|
93
|
+
readonly "editor.itemDuplicated": "{item} duplicated.";
|
|
94
|
+
readonly "editor.untitled": "Untitled {item}";
|
|
95
|
+
readonly "editor.optional": "optional";
|
|
96
|
+
readonly "editor.set": "Add";
|
|
97
|
+
readonly "editor.clear": "Clear";
|
|
98
|
+
readonly "editor.variant": "Type";
|
|
99
|
+
readonly "editor.group.content": "Content";
|
|
100
|
+
readonly "editor.group.behavior": "Behaviour";
|
|
101
|
+
readonly "editor.group.feedback": "Feedback";
|
|
102
|
+
readonly "editor.group.appearance": "Appearance";
|
|
103
|
+
readonly "editor.group.advanced": "Advanced";
|
|
104
|
+
readonly "editor.image.src": "Image URL";
|
|
105
|
+
readonly "editor.image.alt": "Alternative text";
|
|
106
|
+
readonly "editor.image.caption": "Caption";
|
|
107
|
+
readonly "editor.image.choose": "Choose image";
|
|
108
|
+
readonly "editor.image.decorative": "Leave empty for a decorative image.";
|
|
109
|
+
readonly "editor.richtext.bold": "Bold";
|
|
110
|
+
readonly "editor.richtext.italic": "Italic";
|
|
111
|
+
readonly "editor.richtext.code": "Code";
|
|
112
|
+
readonly "editor.richtext.link": "Link";
|
|
113
|
+
readonly "editor.richtext.list": "List";
|
|
114
|
+
readonly "editor.richtext.toolbar": "Formatting for {field}";
|
|
115
|
+
readonly "editor.json.invalid": "Not valid JSON.";
|
|
116
|
+
readonly "editor.record.key": "Key";
|
|
117
|
+
readonly "editor.record.value": "Value";
|
|
118
|
+
readonly "editor.record.add": "Add entry";
|
|
119
|
+
readonly "editor.issues.title": "Fix {count} problem(s) before this block can be shown";
|
|
120
|
+
readonly "editor.issues.goTo": "Go to {field}";
|
|
121
|
+
readonly "editor.preview": "Preview";
|
|
122
|
+
readonly "editor.preview.lastValid": "Showing the last valid version while you edit.";
|
|
123
|
+
readonly "editor.form": "Settings";
|
|
124
|
+
readonly "editor.picker.title": "Add a block";
|
|
125
|
+
readonly "editor.picker.search": "Search blocks";
|
|
126
|
+
readonly "editor.picker.example": "With example content";
|
|
127
|
+
readonly "editor.picker.blank": "Blank";
|
|
128
|
+
readonly "editor.picker.start": "Start from";
|
|
129
|
+
readonly "editor.picker.empty": "No blocks match \u201C{query}\u201D.";
|
|
130
|
+
readonly "editor.picker.add": "Add {name}";
|
|
131
|
+
readonly "editor.category.learn": "Learn";
|
|
132
|
+
readonly "editor.category.practice": "Practice";
|
|
133
|
+
readonly "editor.category.explore": "Explore";
|
|
134
|
+
readonly "editor.category.decide": "Decide";
|
|
135
|
+
readonly "editor.category.simulate": "Simulate";
|
|
136
|
+
readonly "editor.category.present": "Present";
|
|
137
|
+
readonly "editor.lesson.modules": "Blocks";
|
|
138
|
+
readonly "editor.lesson.settings": "Lesson settings";
|
|
139
|
+
readonly "editor.lesson.addBlock": "Add block";
|
|
140
|
+
readonly "editor.lesson.empty": "This lesson has no blocks yet.";
|
|
141
|
+
readonly "editor.lesson.select": "Edit {name}";
|
|
142
|
+
readonly "editor.lesson.position": "Block {current} of {total}";
|
|
143
|
+
readonly "editor.lesson.hasIssues": "Has problems";
|
|
144
|
+
readonly "editor.lesson.blockIssues": "In this lesson:";
|
|
145
|
+
};
|
|
146
|
+
export type EditorMessageKey = keyof typeof editorMessages;
|
|
147
|
+
/** Translator for editor strings: provider `messages` first, then the English defaults. */
|
|
148
|
+
export declare function useEditorT(): (key: EditorMessageKey | (string & {}), values?: MessageValues) => string;
|
|
149
|
+
/** A JSON Schema reduced to what a form needs. */
|
|
150
|
+
export type FormNode = {
|
|
151
|
+
kind: "string";
|
|
152
|
+
enum?: string[];
|
|
153
|
+
maxLength?: number;
|
|
154
|
+
minLength?: number;
|
|
155
|
+
pattern?: string;
|
|
156
|
+
} | {
|
|
157
|
+
kind: "number";
|
|
158
|
+
integer: boolean;
|
|
159
|
+
min?: number;
|
|
160
|
+
max?: number;
|
|
161
|
+
step?: number;
|
|
162
|
+
/** `min` / `max` themselves are not allowed (JSON Schema exclusiveMinimum / exclusiveMaximum). */
|
|
163
|
+
minExclusive?: boolean;
|
|
164
|
+
maxExclusive?: boolean;
|
|
165
|
+
} | {
|
|
166
|
+
kind: "boolean";
|
|
167
|
+
} | {
|
|
168
|
+
kind: "const";
|
|
169
|
+
value: unknown;
|
|
170
|
+
} | {
|
|
171
|
+
kind: "object";
|
|
172
|
+
fields: FormField[];
|
|
173
|
+
} | {
|
|
174
|
+
kind: "array";
|
|
175
|
+
item: FormNodeWithMeta;
|
|
176
|
+
minItems?: number;
|
|
177
|
+
maxItems?: number;
|
|
178
|
+
} | {
|
|
179
|
+
kind: "union";
|
|
180
|
+
discriminator?: string;
|
|
181
|
+
variants: FormVariant[];
|
|
182
|
+
} | {
|
|
183
|
+
kind: "record";
|
|
184
|
+
value: FormNodeWithMeta;
|
|
185
|
+
} | {
|
|
186
|
+
kind: "unknown";
|
|
187
|
+
};
|
|
188
|
+
export interface FormField {
|
|
189
|
+
key: string;
|
|
190
|
+
node: FormNodeWithMeta;
|
|
191
|
+
required: boolean;
|
|
192
|
+
}
|
|
193
|
+
export interface FormVariant {
|
|
194
|
+
label: string;
|
|
195
|
+
/** Discriminator value, when the union has one. */
|
|
196
|
+
value?: string;
|
|
197
|
+
node: FormNodeWithMeta;
|
|
198
|
+
}
|
|
199
|
+
export type FormNodeWithMeta = FormNode & {
|
|
200
|
+
title?: string;
|
|
201
|
+
description?: string;
|
|
202
|
+
default?: unknown;
|
|
203
|
+
/** True when `null` is allowed in addition to the node's own type. */
|
|
204
|
+
nullable?: boolean;
|
|
205
|
+
ui: UiHint;
|
|
206
|
+
};
|
|
207
|
+
/** Normalise a JSON Schema (as produced by `getModuleJsonSchema`) into a form tree. */
|
|
208
|
+
export declare function toFormNode(schema: JsonSchema, depth?: number): FormNodeWithMeta;
|
|
209
|
+
/** A new id like `card-3` that is not used by `siblings` (deterministic: a counter, not random). */
|
|
210
|
+
export declare function uniqueId(prefix: string, taken: Iterable<string>): string;
|
|
211
|
+
interface DefaultContext {
|
|
212
|
+
/** Ids already used by siblings, for `id` fields. */
|
|
213
|
+
takenIds?: Iterable<string>;
|
|
214
|
+
/** Prefix for generated ids, e.g. "card". */
|
|
215
|
+
idPrefix?: string;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* A minimal value for a node: required object fields filled recursively, `minItems` array
|
|
219
|
+
* items, the first enum value, `min` for numbers. Optional fields are left out.
|
|
220
|
+
*/
|
|
221
|
+
export declare function defaultFor(node: FormNodeWithMeta, ctx?: DefaultContext, depth?: number): unknown;
|
|
222
|
+
|
|
223
|
+
export {};
|