@astl/editor 0.1.4 → 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/CHANGELOG.md +20 -0
- package/dist/authoring.d.ts +12 -0
- package/dist/authoring.d.ts.map +1 -1
- package/dist/authoring.js +6 -3
- package/dist/authoring.js.map +1 -1
- package/dist/elements/help-form.d.ts.map +1 -1
- package/dist/elements/help-form.js +69 -23
- package/dist/elements/help-form.js.map +1 -1
- package/dist/elements/inspector.js +3 -3
- package/dist/elements/inspector.js.map +1 -1
- package/dist/messages/en.json +15 -1
- package/dist/messages/help/en.json +4 -2
- package/dist/messages/help/pl.json +4 -2
- package/dist/messages/pl.json +15 -1
- package/dist/pages.d.ts +8 -0
- package/dist/pages.d.ts.map +1 -1
- package/dist/pages.js +52 -4
- package/dist/pages.js.map +1 -1
- package/dist/textarea.d.ts +2 -0
- package/dist/textarea.d.ts.map +1 -1
- package/dist/textarea.js +7 -1
- package/dist/textarea.js.map +1 -1
- package/package.json +5 -5
- package/src/authoring.ts +25 -2
- package/src/elements/help-form.ts +78 -21
- package/src/elements/inspector.ts +3 -3
- package/src/messages/en.json +15 -1
- package/src/messages/help/en.json +4 -2
- package/src/messages/help/pl.json +4 -2
- package/src/messages/pl.json +15 -1
- package/src/pages.ts +60 -4
- package/src/textarea.ts +14 -1
|
@@ -20,6 +20,7 @@ import { type HelpValue, helpFormatted, helpText, readHelp, textHelp, writeHelp
|
|
|
20
20
|
import en from '../messages/help/en.json' with { type: 'json' };
|
|
21
21
|
import pl from '../messages/help/pl.json' with { type: 'json' };
|
|
22
22
|
import { EDITOR_NAMESPACE } from '../messages.js';
|
|
23
|
+
import { elementTree } from '../scan.js';
|
|
23
24
|
import { AuthoringElement } from './base.js';
|
|
24
25
|
import { kitStyles } from './styles.js';
|
|
25
26
|
|
|
@@ -73,12 +74,14 @@ export function addHelp(authoring: Authoring, adapter: EditorAdapter, kind: Help
|
|
|
73
74
|
/** The order the menu fills feedback texts in: right and wrong first. */
|
|
74
75
|
const FEEDBACK_ORDER: readonly FeedbackVariant[] = ['correct', 'incorrect', 'omitted', 'partial'];
|
|
75
76
|
|
|
76
|
-
/**
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
77
|
+
/** The costs the card offers ('0': free, no attribute); a cost the source has besides stays as an option of its own. */
|
|
78
|
+
const COSTS: readonly string[] = ['0', '0.1', '0.25', '0.5'];
|
|
79
|
+
|
|
80
|
+
/** A hint's cost as one of the select's values: '0' without one, else as written. */
|
|
81
|
+
const costOf = (cost: string | null): string => cost ?? '0';
|
|
82
|
+
|
|
83
|
+
/** Rounds points for display, to at most 2 decimals. */
|
|
84
|
+
const round = (n: number): number => Math.round(n * 100) / 100;
|
|
82
85
|
|
|
83
86
|
const inputValue = (event: Event) => (event.target as HTMLInputElement | HTMLTextAreaElement).value;
|
|
84
87
|
|
|
@@ -154,10 +157,15 @@ export class AstlHelpForm extends AuthoringElement {
|
|
|
154
157
|
display: flex;
|
|
155
158
|
align-items: center;
|
|
156
159
|
gap: var(--astl-space-1);
|
|
160
|
+
min-inline-size: 0;
|
|
161
|
+
max-inline-size: 100%;
|
|
157
162
|
font-weight: 400;
|
|
158
163
|
}
|
|
159
|
-
.cost
|
|
160
|
-
inline-size:
|
|
164
|
+
.cost select {
|
|
165
|
+
inline-size: auto;
|
|
166
|
+
min-inline-size: 0;
|
|
167
|
+
max-inline-size: 100%;
|
|
168
|
+
text-overflow: ellipsis;
|
|
161
169
|
}
|
|
162
170
|
textarea {
|
|
163
171
|
field-sizing: content;
|
|
@@ -176,6 +184,9 @@ export class AstlHelpForm extends AuthoringElement {
|
|
|
176
184
|
declare inline: boolean;
|
|
177
185
|
/** What the author is typing in a field, by field: the source has it cleaned, the field keeps it as typed. */
|
|
178
186
|
#drafts = new Map<string, string>();
|
|
187
|
+
/** The question's points as last worked out, for its source then; and the source being worked out now. */
|
|
188
|
+
#points: { readonly html: string; readonly value: number | null } | null = null;
|
|
189
|
+
#counting: string | null = null;
|
|
179
190
|
#dragged: number | null = null;
|
|
180
191
|
|
|
181
192
|
constructor() {
|
|
@@ -203,6 +214,50 @@ export class AstlHelpForm extends AuthoringElement {
|
|
|
203
214
|
return html === null ? null : { html, help: readHelp(html) };
|
|
204
215
|
}
|
|
205
216
|
|
|
217
|
+
/**
|
|
218
|
+
* The question's points, from a compilation of the element alone (its points, scoring and parts as the engine counts
|
|
219
|
+
* them): null until known, or when it does not compile on its own; then the costs say only their share.
|
|
220
|
+
*/
|
|
221
|
+
#pointsOf(html: string): number | null {
|
|
222
|
+
if (this.#points?.html === html) return this.#points.value;
|
|
223
|
+
const authoring = this.authoring;
|
|
224
|
+
if (this.#counting !== html && authoring !== null) {
|
|
225
|
+
this.#counting = html;
|
|
226
|
+
const inline = authoring.descriptor(elementTree(html)[0]?.name ?? '')?.manifest.display === 'inline';
|
|
227
|
+
void authoring.engine
|
|
228
|
+
.compile(`<astl-doc lang="en">${inline ? `<p>${html}</p>` : html}</astl-doc>`)
|
|
229
|
+
.then(
|
|
230
|
+
(result) => (result.ok ? result.metadata.maxScore : null),
|
|
231
|
+
() => null,
|
|
232
|
+
)
|
|
233
|
+
.then((value) => {
|
|
234
|
+
if (this.#counting !== html) return;
|
|
235
|
+
this.#points = { html, value };
|
|
236
|
+
this.requestUpdate();
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
return null;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/** The cost select's options: free, a share of the points (in points where known), and the source's own cost. */
|
|
243
|
+
#costs(cost: string | null, points: number | null): { readonly value: string; readonly label: string }[] {
|
|
244
|
+
const own = costOf(cost);
|
|
245
|
+
const values = COSTS.includes(own) ? COSTS : [...COSTS, own].sort((a, b) => Number(a) - Number(b));
|
|
246
|
+
return values.map((value) => {
|
|
247
|
+
const share = Number(value);
|
|
248
|
+
if (value === '0') return { value, label: this.t('help.costFree') };
|
|
249
|
+
if (!Number.isFinite(share)) return { value, label: value };
|
|
250
|
+
const percent = round(share * 100);
|
|
251
|
+
return {
|
|
252
|
+
value,
|
|
253
|
+
label:
|
|
254
|
+
points === null || points <= 0
|
|
255
|
+
? this.t('help.costShare', { percent })
|
|
256
|
+
: this.t('help.costPoints', { percent, points: round(share * points), max: points }),
|
|
257
|
+
};
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
|
|
206
261
|
#write(change: (help: HelpValue) => HelpValue): void {
|
|
207
262
|
const current = this.#help();
|
|
208
263
|
if (current === null || this.element === null || this.adapter === null) return;
|
|
@@ -244,7 +299,7 @@ export class AstlHelpForm extends AuthoringElement {
|
|
|
244
299
|
this.#drafts.clear();
|
|
245
300
|
}
|
|
246
301
|
|
|
247
|
-
#hint(help: HelpValue, index: number): TemplateResult {
|
|
302
|
+
#hint(help: HelpValue, index: number, points: number | null): TemplateResult {
|
|
248
303
|
const hint = help.hints[index] as HelpValue['hints'][number];
|
|
249
304
|
const n = index + 1;
|
|
250
305
|
const field = `hint-${index}`;
|
|
@@ -300,25 +355,23 @@ export class AstlHelpForm extends AuthoringElement {
|
|
|
300
355
|
<div class="row">
|
|
301
356
|
<label class="cost">
|
|
302
357
|
${this.t('help.cost')}
|
|
303
|
-
<
|
|
304
|
-
type="number"
|
|
358
|
+
<select
|
|
305
359
|
aria-label=${this.t('help.costN', { n })}
|
|
306
|
-
min="0"
|
|
307
|
-
max="100"
|
|
308
|
-
step="5"
|
|
309
|
-
inputmode="numeric"
|
|
310
360
|
data-help=${`cost-${index}`}
|
|
311
|
-
.value=${live(percentOf(hint.cost))}
|
|
312
361
|
@change=${(e: Event) => {
|
|
313
|
-
const
|
|
314
|
-
|
|
315
|
-
const cost = percent === 0 ? null : String(Math.round(percent) / 100);
|
|
362
|
+
const value = inputValue(e);
|
|
363
|
+
const cost = value === '0' ? null : value;
|
|
316
364
|
this.#write((h) => ({
|
|
317
365
|
...h,
|
|
318
366
|
hints: h.hints.map((x, i) => (i === index ? { ...x, cost } : x)),
|
|
319
367
|
}));
|
|
320
368
|
}}
|
|
321
|
-
|
|
369
|
+
>
|
|
370
|
+
${this.#costs(hint.cost, points).map(
|
|
371
|
+
({ value, label }) =>
|
|
372
|
+
html`<option value=${value} ?selected=${value === costOf(hint.cost)}>${label}</option>`,
|
|
373
|
+
)}
|
|
374
|
+
</select>
|
|
322
375
|
</label>
|
|
323
376
|
<button type="button" aria-label=${this.t('help.upN', { n })} aria-disabled=${String(index === 0)}
|
|
324
377
|
@click=${() => this.#move(index, index - 1)}>${this.t('help.up')}</button>
|
|
@@ -390,7 +443,11 @@ export class AstlHelpForm extends AuthoringElement {
|
|
|
390
443
|
<fieldset aria-describedby="hints-note">
|
|
391
444
|
<legend>${this.t('help.hints')}</legend>
|
|
392
445
|
<p class="note" id="hints-note">${this.t('help.hintsNote')}</p>
|
|
393
|
-
${
|
|
446
|
+
${
|
|
447
|
+
help.hints.length === 0
|
|
448
|
+
? nothing
|
|
449
|
+
: html`<ol>${help.hints.map((_, i) => this.#hint(help, i, this.#pointsOf(current.html)))}</ol>`
|
|
450
|
+
}
|
|
394
451
|
<div class="row">
|
|
395
452
|
<button type="button" data-help="add-hint"
|
|
396
453
|
@click=${() => {
|
|
@@ -924,17 +924,17 @@ export class AstlInspector extends AuthoringElement {
|
|
|
924
924
|
}`;
|
|
925
925
|
} else {
|
|
926
926
|
// The heading says the type; the id is beside it in a chip, outside the heading.
|
|
927
|
-
// A graded element's help for students: a form of its own, loaded on first use.
|
|
927
|
+
// A graded element's help for students heads the card, before its fields: a form of its own, loaded on first use.
|
|
928
928
|
const manifest = authoring.descriptor(model.tag)?.manifest;
|
|
929
929
|
if (manifest?.graded === true) void loadHelpForm().catch(() => {});
|
|
930
930
|
body = html`${this.#head(model)}${this.#issues(model)}
|
|
931
|
-
<div class="fields" data-tag=${model.tag}>${model.fields.map((f, i) => this.#field(f, i))}</div>
|
|
932
931
|
${
|
|
933
932
|
manifest?.graded === true
|
|
934
933
|
? html`<astl-help-form .authoring=${authoring} .adapter=${adapter} .element=${this.#shown}
|
|
935
934
|
?inline=${manifest.display === 'inline'}></astl-help-form>`
|
|
936
935
|
: nothing
|
|
937
|
-
}
|
|
936
|
+
}
|
|
937
|
+
<div class="fields" data-tag=${model.tag}>${model.fields.map((f, i) => this.#field(f, i))}</div>`;
|
|
938
938
|
}
|
|
939
939
|
return html`<section class="kit" part="root" lang=${lang} dir=${dir} aria-labelledby="title">${body}${this.#styleSection()}</section>`;
|
|
940
940
|
}
|
package/src/messages/en.json
CHANGED
|
@@ -252,5 +252,19 @@
|
|
|
252
252
|
"help.when.omitted": "Skipped",
|
|
253
253
|
"help.costLabel": "Cost of the hint",
|
|
254
254
|
"help.whenLabel": "For the result",
|
|
255
|
-
"surface.helpRemove": "{kind, select, hint {Remove the hint} explanation {Remove the explanation} other {Remove the feedback}}"
|
|
255
|
+
"surface.helpRemove": "{kind, select, hint {Remove the hint} explanation {Remove the explanation} other {Remove the feedback}}",
|
|
256
|
+
"surface.pageCheck": "Check this page",
|
|
257
|
+
"surface.pageCheckOn": "Page {page} has a Check of its own now.",
|
|
258
|
+
"surface.pageCheckOff": "Page {page} has no Check of its own now.",
|
|
259
|
+
"help.costFree": "Free",
|
|
260
|
+
"surface.hintPageCost": "Costs {percent}%: a page's hints are free now.",
|
|
261
|
+
"surface.hintMakeFree": "Make it free",
|
|
262
|
+
"surface.moveTo": "Move to question...",
|
|
263
|
+
"surface.moveLabel": "Move the {kind, select, hint {hint} other {explanation}} into a question",
|
|
264
|
+
"surface.moveTarget": "{name} ({id})",
|
|
265
|
+
"surface.moveTargetFull": "{name}: has an explanation",
|
|
266
|
+
"surface.moved": "Moved into {name}.",
|
|
267
|
+
"surface.moveNone": "No question on this page",
|
|
268
|
+
"surface.pagesCheckOn": "Every page has a Check of its own now.",
|
|
269
|
+
"surface.pagesCheckOff": "No page has a Check of its own now."
|
|
256
270
|
}
|
|
@@ -3,8 +3,10 @@
|
|
|
3
3
|
"help.hints": "Hints",
|
|
4
4
|
"help.hintsNote": "Students ask for them one at a time, in this order. A cost is the share of the question's points a student loses for using that hint.",
|
|
5
5
|
"help.hintN": "Hint {n}",
|
|
6
|
-
"help.cost": "Cost
|
|
7
|
-
"help.costN": "Hint {n}: cost
|
|
6
|
+
"help.cost": "Cost",
|
|
7
|
+
"help.costN": "Hint {n}: cost",
|
|
8
|
+
"help.costShare": "-{percent}% of this question's points",
|
|
9
|
+
"help.costPoints": "-{percent}%: -{points} of {max, plural, one {# point} other {# points}}",
|
|
8
10
|
"help.addHint": "Add a hint",
|
|
9
11
|
"help.up": "Up",
|
|
10
12
|
"help.down": "Down",
|
|
@@ -3,8 +3,10 @@
|
|
|
3
3
|
"help.hints": "Podpowiedzi",
|
|
4
4
|
"help.hintsNote": "Uczeń prosi o nie po kolei, w tej kolejności. Koszt to część punktów za to pytanie, którą uczeń traci, gdy użyje podpowiedzi.",
|
|
5
5
|
"help.hintN": "Podpowiedź {n}",
|
|
6
|
-
"help.cost": "Koszt
|
|
7
|
-
"help.costN": "Podpowiedź {n}: koszt
|
|
6
|
+
"help.cost": "Koszt",
|
|
7
|
+
"help.costN": "Podpowiedź {n}: koszt",
|
|
8
|
+
"help.costShare": "-{percent}% punktów za to pytanie",
|
|
9
|
+
"help.costPoints": "-{percent}%: -{points} z {max, plural, one {# punktu} few {# punktów} many {# punktów} other {# punktu}}",
|
|
8
10
|
"help.addHint": "Dodaj podpowiedź",
|
|
9
11
|
"help.up": "W górę",
|
|
10
12
|
"help.down": "W dół",
|
package/src/messages/pl.json
CHANGED
|
@@ -252,5 +252,19 @@
|
|
|
252
252
|
"help.when.omitted": "Pominięte",
|
|
253
253
|
"help.costLabel": "Koszt podpowiedzi",
|
|
254
254
|
"help.whenLabel": "Dla wyniku",
|
|
255
|
-
"surface.helpRemove": "{kind, select, hint {Usuń podpowiedź} explanation {Usuń wyjaśnienie} other {Usuń informację zwrotną}}"
|
|
255
|
+
"surface.helpRemove": "{kind, select, hint {Usuń podpowiedź} explanation {Usuń wyjaśnienie} other {Usuń informację zwrotną}}",
|
|
256
|
+
"surface.pageCheck": "Sprawdź tę stronę",
|
|
257
|
+
"surface.pageCheckOn": "Strona {page} ma teraz własne sprawdzanie.",
|
|
258
|
+
"surface.pageCheckOff": "Strona {page} nie ma już własnego sprawdzania.",
|
|
259
|
+
"help.costFree": "Bez kosztu",
|
|
260
|
+
"surface.hintPageCost": "Kosztuje {percent}%: podpowiedzi strony są teraz bez kosztu.",
|
|
261
|
+
"surface.hintMakeFree": "Ustaw bez kosztu",
|
|
262
|
+
"surface.moveTo": "Przenieś do pytania...",
|
|
263
|
+
"surface.moveLabel": "Przenieś {kind, select, hint {podpowiedź} other {wyjaśnienie}} do pytania",
|
|
264
|
+
"surface.moveTarget": "{name} ({id})",
|
|
265
|
+
"surface.moveTargetFull": "{name}: ma już wyjaśnienie",
|
|
266
|
+
"surface.moved": "Przeniesiono do: {name}.",
|
|
267
|
+
"surface.moveNone": "Na tej stronie nie ma pytań",
|
|
268
|
+
"surface.pagesCheckOn": "Każda strona ma teraz własne sprawdzanie.",
|
|
269
|
+
"surface.pagesCheckOff": "Żadna strona nie ma już własnego sprawdzania."
|
|
256
270
|
}
|
package/src/pages.ts
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Page breaks, new pages and
|
|
3
|
-
* `splitPage`, `addPage` and `
|
|
4
|
-
* everything around an edit stays as written.
|
|
2
|
+
* Page breaks, new pages, joins and a page's own check as edits of the source text, for text-based adapters (the
|
|
3
|
+
* textarea adapter's `splitPage`, `addPage`, `mergePage` and `setPageCheck`) and for `Authoring.setPageCheck`: the rules
|
|
4
|
+
* of `EditorAdapter`, on the element ranges of `scan.ts`, so everything around an edit stays as written.
|
|
5
5
|
*/
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
CLASS_ATTRIBUTE,
|
|
8
|
+
CONTENT_ATTRIBUTES,
|
|
9
|
+
DOC_TAG,
|
|
10
|
+
PAGE_CHECK_ATTRIBUTE,
|
|
11
|
+
PAGE_TAG,
|
|
12
|
+
STYLE_TAG,
|
|
13
|
+
} from '@astl/core';
|
|
7
14
|
import { attributeValue, type ElementRange, elementTree, tokenize, usedIds } from './scan.js';
|
|
8
15
|
|
|
9
16
|
/** A source after a page edit, and the offset of the caret in it. */
|
|
@@ -156,3 +163,52 @@ export function mergePageSource(source: string, id: string): PageEdit | null {
|
|
|
156
163
|
const left = source.slice(0, end.start) + source.slice(end.end, start.start);
|
|
157
164
|
return { source: left + source.slice(start.end), caret: left.length };
|
|
158
165
|
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* `source` with `check` set (`check: true`) or cleared on the page `page`, or on every page when `page` is left out
|
|
169
|
+
* (`EditorAdapter.setPageCheck`, `Authoring.setPageCheck`). In a document without pages, setting it makes the content
|
|
170
|
+
* one page with a fresh id (`page-<n>`) and `check`, after the named styles at its head; clearing it there changes
|
|
171
|
+
* nothing, and clearing it on a page keeps the page (a document that became one page stays one). Null when nothing
|
|
172
|
+
* changes: set already, cleared already, or no page with that id. The caret stays where it was, moved with the text.
|
|
173
|
+
*/
|
|
174
|
+
export function setPageCheckSource(
|
|
175
|
+
source: string,
|
|
176
|
+
check: boolean,
|
|
177
|
+
caret: number,
|
|
178
|
+
page?: string,
|
|
179
|
+
): PageEdit | null {
|
|
180
|
+
const doc = documentOf(source);
|
|
181
|
+
if (doc.pages.length === 0) {
|
|
182
|
+
if (!check || page !== undefined || doc.blocks.length === 0) return null;
|
|
183
|
+
const open = `<astl-page id="${freshPage(usedIds(source))}" ${PAGE_CHECK_ATTRIBUTE}>`;
|
|
184
|
+
const close = '</astl-page>';
|
|
185
|
+
const next = `${source.slice(0, doc.start)}${open}${source.slice(doc.start, doc.end)}${close}${source.slice(doc.end)}`;
|
|
186
|
+
return {
|
|
187
|
+
source: next,
|
|
188
|
+
caret: caret <= doc.start ? caret : caret + open.length + (caret > doc.end ? close.length : 0),
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
const edits: { readonly start: number; readonly end: number; readonly text: string }[] = [];
|
|
192
|
+
for (const target of doc.pages) {
|
|
193
|
+
if (page !== undefined && attributeValue(target.startTag, 'id') !== page) continue;
|
|
194
|
+
const written = target.startTag.attributes.find((a) => a.name === PAGE_CHECK_ATTRIBUTE);
|
|
195
|
+
if (check && written === undefined) {
|
|
196
|
+
// Last in the start tag, before its `>`.
|
|
197
|
+
const at =
|
|
198
|
+
source.charAt(target.startTag.end - 1) === '>' ? target.startTag.end - 1 : target.startTag.end;
|
|
199
|
+
edits.push({ start: at, end: at, text: ` ${PAGE_CHECK_ATTRIBUTE}` });
|
|
200
|
+
} else if (!check && written !== undefined) {
|
|
201
|
+
let start = written.start;
|
|
202
|
+
while (start > 0 && /\s/.test(source.charAt(start - 1))) start--;
|
|
203
|
+
edits.push({ start, end: written.end, text: '' });
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
if (edits.length === 0) return null;
|
|
207
|
+
let next = source;
|
|
208
|
+
let moved = caret;
|
|
209
|
+
for (const e of [...edits].sort((a, b) => b.start - a.start)) {
|
|
210
|
+
next = next.slice(0, e.start) + e.text + next.slice(e.end);
|
|
211
|
+
if (caret >= e.end) moved += e.text.length - (e.end - e.start);
|
|
212
|
+
}
|
|
213
|
+
return { source: next, caret: moved };
|
|
214
|
+
}
|
package/src/textarea.ts
CHANGED
|
@@ -3,7 +3,13 @@
|
|
|
3
3
|
* edits are string splices, so the author's formatting outside the edited element is never touched.
|
|
4
4
|
*/
|
|
5
5
|
import { DOC_TAG, type EditorAdapter, type EditorSelection, PAGE_TAG } from '@astl/core';
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
addPageSource,
|
|
8
|
+
mergePageSource,
|
|
9
|
+
type PageEdit,
|
|
10
|
+
setPageCheckSource,
|
|
11
|
+
splitPageSource,
|
|
12
|
+
} from './pages.js';
|
|
7
13
|
import { type ScannedElement, scanElements, tokenize } from './scan.js';
|
|
8
14
|
|
|
9
15
|
export interface TextareaAdapter extends EditorAdapter {
|
|
@@ -13,6 +19,8 @@ export interface TextareaAdapter extends EditorAdapter {
|
|
|
13
19
|
addPage(after?: string): string;
|
|
14
20
|
/** The page `id` joined to the page before it, in the source text (`EditorAdapter.mergePage`). */
|
|
15
21
|
mergePage(id: string): boolean;
|
|
22
|
+
/** `check` set or cleared on a page or on every page, in the source text (`EditorAdapter.setPageCheck`). */
|
|
23
|
+
setPageCheck(check: boolean, page?: string): boolean;
|
|
16
24
|
/** Removes the textarea listeners and every subscription. */
|
|
17
25
|
destroy(): void;
|
|
18
26
|
}
|
|
@@ -165,6 +173,11 @@ export function createTextareaAdapter(textarea: HTMLTextAreaElement): TextareaAd
|
|
|
165
173
|
if (edit !== null) apply(edit);
|
|
166
174
|
return edit !== null;
|
|
167
175
|
},
|
|
176
|
+
setPageCheck(check, page) {
|
|
177
|
+
const edit = setPageCheckSource(textarea.value, check, textarea.selectionStart, page);
|
|
178
|
+
if (edit !== null) apply(edit);
|
|
179
|
+
return edit !== null;
|
|
180
|
+
},
|
|
168
181
|
onChange(listener) {
|
|
169
182
|
changes.add(listener);
|
|
170
183
|
return () => changes.delete(listener);
|