@astl/editor-tiptap 0.3.2 → 0.4.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 +28 -0
- package/dist/define.d.ts +14 -1
- package/dist/define.d.ts.map +1 -1
- package/dist/define.js.map +1 -1
- package/dist/element.d.ts +27 -1
- package/dist/element.d.ts.map +1 -1
- package/dist/element.js +108 -27
- package/dist/element.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/nodes.d.ts +15 -4
- package/dist/nodes.d.ts.map +1 -1
- package/dist/nodes.js +52 -6
- package/dist/nodes.js.map +1 -1
- package/dist/page-actions.d.ts +14 -0
- package/dist/page-actions.d.ts.map +1 -0
- package/dist/page-actions.js +14 -0
- package/dist/page-actions.js.map +1 -0
- package/dist/surface.d.ts +5 -1
- package/dist/surface.d.ts.map +1 -1
- package/dist/surface.js +9 -4
- package/dist/surface.js.map +1 -1
- package/dist/tiptap.d.ts +2 -0
- package/dist/tiptap.d.ts.map +1 -1
- package/dist/tiptap.js +1 -0
- package/dist/tiptap.js.map +1 -1
- package/package.json +6 -6
- package/src/define.ts +14 -0
- package/src/element.ts +135 -26
- package/src/index.ts +2 -0
- package/src/nodes.ts +56 -7
- package/src/page-actions.ts +20 -0
- package/src/surface.ts +12 -3
- package/src/tiptap.ts +2 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The buttons of a page's head on the TipTap surface. A module of its own: the element's entry must not import TipTap,
|
|
3
|
+
* and the `/tiptap` entry must not import the element.
|
|
4
|
+
*/
|
|
5
|
+
/** A button of a page's head on the TipTap surface, for `pageActions`. */
|
|
6
|
+
export type PageAction = 'add-title' | 'check' | 'join' | 'delete';
|
|
7
|
+
/**
|
|
8
|
+
* Every button of a page's head, in their default order: "Add title" (with "Remove title" beside a page's title),
|
|
9
|
+
* "Check this page", "Join with page N" and "Delete page".
|
|
10
|
+
*/
|
|
11
|
+
export declare const PAGE_ACTIONS: readonly PageAction[];
|
|
12
|
+
/** A host's list as the heads draw it: known actions, each once, in its order. */
|
|
13
|
+
export declare function pageActionsOf(list: readonly string[]): readonly PageAction[];
|
|
14
|
+
//# sourceMappingURL=page-actions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"page-actions.d.ts","sourceRoot":"","sources":["../src/page-actions.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,0EAA0E;AAC1E,MAAM,MAAM,UAAU,GAAG,WAAW,GAAG,OAAO,GAAG,MAAM,GAAG,QAAQ,CAAC;AAEnE;;;GAGG;AACH,eAAO,MAAM,YAAY,EAAE,SAAS,UAAU,EAA6C,CAAC;AAE5F,kFAAkF;AAClF,wBAAgB,aAAa,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,UAAU,EAAE,CAI5E"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The buttons of a page's head on the TipTap surface. A module of its own: the element's entry must not import TipTap,
|
|
3
|
+
* and the `/tiptap` entry must not import the element.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Every button of a page's head, in their default order: "Add title" (with "Remove title" beside a page's title),
|
|
7
|
+
* "Check this page", "Join with page N" and "Delete page".
|
|
8
|
+
*/
|
|
9
|
+
export const PAGE_ACTIONS = ['add-title', 'check', 'join', 'delete'];
|
|
10
|
+
/** A host's list as the heads draw it: known actions, each once, in its order. */
|
|
11
|
+
export function pageActionsOf(list) {
|
|
12
|
+
return PAGE_ACTIONS.filter((action) => list.includes(action)).sort((a, b) => list.indexOf(a) - list.indexOf(b));
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=page-actions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"page-actions.js","sourceRoot":"","sources":["../src/page-actions.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH;;;GAGG;AACH,MAAM,CAAC,MAAM,YAAY,GAA0B,CAAC,WAAW,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;AAE5F,kFAAkF;AAClF,MAAM,UAAU,aAAa,CAAC,IAAuB;IACnD,OAAO,YAAY,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAChE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAC5C,CAAC;AACJ,CAAC"}
|
package/dist/surface.d.ts
CHANGED
|
@@ -8,10 +8,13 @@ import { type Authoring } from '@astl/editor';
|
|
|
8
8
|
import type { LitElement } from 'lit';
|
|
9
9
|
import { type SurfaceChange } from './blocks.js';
|
|
10
10
|
import { type PictureHooks } from './nodes.js';
|
|
11
|
+
import type { PageAction } from './page-actions.js';
|
|
11
12
|
export interface Surface {
|
|
12
13
|
readonly adapter: EditorAdapter;
|
|
13
14
|
/** The authoring its labels come from. */
|
|
14
15
|
readonly authoring: Authoring;
|
|
16
|
+
/** Draws these buttons in the page heads from now on (`pageActions`). */
|
|
17
|
+
setPageActions(actions: readonly PageAction[]): void;
|
|
15
18
|
/** Destroys the editor and removes its element. */
|
|
16
19
|
destroy(): void;
|
|
17
20
|
}
|
|
@@ -19,6 +22,7 @@ export interface Surface {
|
|
|
19
22
|
* A TipTap editor on `source`, appended to `host` (the `<astl-editor>`) in the `surface` slot. `manifests` are every
|
|
20
23
|
* registered type: the schema keeps them all, so content of a type the authoring leaves out is never dropped. `changes`
|
|
21
24
|
* hears of each page added or joined and each block moved or deleted, before the change event of its edit.
|
|
25
|
+
* `pageActions` are the buttons of the page heads.
|
|
22
26
|
*/
|
|
23
|
-
export declare function createSurface(host: LitElement, authoring: Authoring, manifests: readonly ComponentManifest[], source: string, pictures?: PictureHooks, changes?: (change: SurfaceChange) => void): Surface;
|
|
27
|
+
export declare function createSurface(host: LitElement, authoring: Authoring, manifests: readonly ComponentManifest[], source: string, pictures?: PictureHooks, changes?: (change: SurfaceChange) => void, pageActions?: readonly PageAction[]): Surface;
|
|
24
28
|
//# sourceMappingURL=surface.d.ts.map
|
package/dist/surface.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"surface.d.ts","sourceRoot":"","sources":["../src/surface.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AACnE,OAAO,EAAE,KAAK,SAAS,EAAoB,MAAM,cAAc,CAAC;AAGhE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AAEtC,OAAO,EAAgB,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AAC/D,OAAO,EAAoC,KAAK,YAAY,
|
|
1
|
+
{"version":3,"file":"surface.d.ts","sourceRoot":"","sources":["../src/surface.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AACnE,OAAO,EAAE,KAAK,SAAS,EAAoB,MAAM,cAAc,CAAC;AAGhE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AAEtC,OAAO,EAAgB,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AAC/D,OAAO,EAAoC,KAAK,YAAY,EAAkB,MAAM,YAAY,CAAC;AACjG,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAGpD,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAC;IAChC,0CAA0C;IAC1C,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;IAC9B,yEAAyE;IACzE,cAAc,CAAC,OAAO,EAAE,SAAS,UAAU,EAAE,GAAG,IAAI,CAAC;IACrD,mDAAmD;IACnD,OAAO,IAAI,IAAI,CAAC;CACjB;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAC3B,IAAI,EAAE,UAAU,EAChB,SAAS,EAAE,SAAS,EACpB,SAAS,EAAE,SAAS,iBAAiB,EAAE,EACvC,MAAM,EAAE,MAAM,EACd,QAAQ,CAAC,EAAE,YAAY,EACvB,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,aAAa,KAAK,IAAI,EACzC,WAAW,CAAC,EAAE,SAAS,UAAU,EAAE,GAClC,OAAO,CA8ET"}
|
package/dist/surface.js
CHANGED
|
@@ -3,14 +3,15 @@ import { Editor } from '@tiptap/core';
|
|
|
3
3
|
import { EditorState } from '@tiptap/pm/state';
|
|
4
4
|
import { createTiptapAdapter } from './adapter.js';
|
|
5
5
|
import { BLOCK_CHANGE } from './blocks.js';
|
|
6
|
-
import { astrolabeExtensions, PAGE_CHANGE } from './nodes.js';
|
|
6
|
+
import { astrolabeExtensions, PAGE_CHANGE, setPageActions } from './nodes.js';
|
|
7
7
|
import { adoptSurfaceStyles, SURFACE_CLASS } from './styles.js';
|
|
8
8
|
/**
|
|
9
9
|
* A TipTap editor on `source`, appended to `host` (the `<astl-editor>`) in the `surface` slot. `manifests` are every
|
|
10
10
|
* registered type: the schema keeps them all, so content of a type the authoring leaves out is never dropped. `changes`
|
|
11
11
|
* hears of each page added or joined and each block moved or deleted, before the change event of its edit.
|
|
12
|
+
* `pageActions` are the buttons of the page heads.
|
|
12
13
|
*/
|
|
13
|
-
export function createSurface(host, authoring, manifests, source, pictures, changes) {
|
|
14
|
+
export function createSurface(host, authoring, manifests, source, pictures, changes, pageActions) {
|
|
14
15
|
adoptSurfaceStyles(host);
|
|
15
16
|
const mount = document.createElement('div');
|
|
16
17
|
mount.slot = 'surface';
|
|
@@ -42,7 +43,10 @@ export function createSurface(host, authoring, manifests, source, pictures, chan
|
|
|
42
43
|
element: mount,
|
|
43
44
|
// No <style> element: the surface stylesheet is adopted (strict CSP allows it).
|
|
44
45
|
injectCSS: false,
|
|
45
|
-
extensions: astrolabeExtensions(authoring, manifests,
|
|
46
|
+
extensions: astrolabeExtensions(authoring, manifests, {
|
|
47
|
+
...(pictures === undefined ? {} : { pictures }),
|
|
48
|
+
...(pageActions === undefined ? {} : { pageActions }),
|
|
49
|
+
}),
|
|
46
50
|
editorProps: {
|
|
47
51
|
attributes: (state) => ({
|
|
48
52
|
'aria-label': authoring.t(EDITOR_NAMESPACE, 'surface.label'),
|
|
@@ -80,7 +84,8 @@ export function createSurface(host, authoring, manifests, source, pictures, chan
|
|
|
80
84
|
if (toolbar !== null && editor?.isDestroyed === false)
|
|
81
85
|
covered.observe(toolbar);
|
|
82
86
|
});
|
|
83
|
-
|
|
87
|
+
const made = editor;
|
|
88
|
+
return { adapter, authoring, destroy, setPageActions: (actions) => setPageActions(made, actions) };
|
|
84
89
|
}
|
|
85
90
|
catch (error) {
|
|
86
91
|
destroy();
|
package/dist/surface.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"surface.js","sourceRoot":"","sources":["../src/surface.ts"],"names":[],"mappings":"AAMA,OAAO,EAAkB,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChE,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,YAAY,EAAsB,MAAM,aAAa,CAAC;AAC/D,OAAO,EAAE,mBAAmB,EAAE,WAAW,EAAqB,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"surface.js","sourceRoot":"","sources":["../src/surface.ts"],"names":[],"mappings":"AAMA,OAAO,EAAkB,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChE,OAAO,EAAE,MAAM,EAAE,MAAM,cA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,IAAI,CAAC,UAAU,CAAC,aAAa,CAAC,mBAAmB,CAAC,CAAC;YACnE,IAAI,OAAO,KAAK,IAAI,IAAI,MAAM,EAAE,WAAW,KAAK,KAAK;gBAAE,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAClF,CAAC,CAAC,CAAC;QACH,MAAM,IAAI,GAAG,MAAM,CAAC;QACpB,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,cAAc,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,cAAc,CAAC,IAAI,EAAE,OAAO,CAAC,EAAE,CAAC;IACrG,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,EAAE,CAAC;QACV,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC"}
|
package/dist/tiptap.d.ts
CHANGED
|
@@ -7,4 +7,6 @@
|
|
|
7
7
|
export { createTiptapAdapter } from './adapter.js';
|
|
8
8
|
export type { PictureHooks } from './nodes.js';
|
|
9
9
|
export { astrolabeExtensions } from './nodes.js';
|
|
10
|
+
export type { PageAction } from './page-actions.js';
|
|
11
|
+
export { PAGE_ACTIONS } from './page-actions.js';
|
|
10
12
|
//# sourceMappingURL=tiptap.d.ts.map
|
package/dist/tiptap.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tiptap.d.ts","sourceRoot":"","sources":["../src/tiptap.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACnD,YAAY,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"tiptap.d.ts","sourceRoot":"","sources":["../src/tiptap.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACnD,YAAY,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AACjD,YAAY,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC"}
|
package/dist/tiptap.js
CHANGED
package/dist/tiptap.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tiptap.js","sourceRoot":"","sources":["../src/tiptap.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAEnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"tiptap.js","sourceRoot":"","sources":["../src/tiptap.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAEnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEjD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astl/editor-tiptap",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "<astl-editor>: the authoring kit around a TipTap surface, loaded only when no other editor is plugged in through an adapter.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"astrolabe",
|
|
@@ -53,11 +53,11 @@
|
|
|
53
53
|
"access": "public"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@astl/core": "0.
|
|
57
|
-
"@astl/editor": "0.
|
|
58
|
-
"@astl/engine": "0.
|
|
59
|
-
"@astl/player": "0.
|
|
60
|
-
"@astl/tokens": "0.
|
|
56
|
+
"@astl/core": "0.4.0",
|
|
57
|
+
"@astl/editor": "0.4.0",
|
|
58
|
+
"@astl/engine": "0.4.0",
|
|
59
|
+
"@astl/player": "0.4.0",
|
|
60
|
+
"@astl/tokens": "0.4.0",
|
|
61
61
|
"@tiptap/core": "3.32.0",
|
|
62
62
|
"@tiptap/pm": "3.32.0",
|
|
63
63
|
"@tiptap/starter-kit": "3.32.0",
|
package/src/define.ts
CHANGED
|
@@ -4,10 +4,12 @@ import {
|
|
|
4
4
|
type EditorFont,
|
|
5
5
|
type EditorStylePreset,
|
|
6
6
|
type PickPicture,
|
|
7
|
+
type ToolbarLayout,
|
|
7
8
|
type UploadAsset,
|
|
8
9
|
} from '@astl/editor';
|
|
9
10
|
import type { ElementEntry } from '@astl/player';
|
|
10
11
|
import { AstlEditor, register } from './element.js';
|
|
12
|
+
import type { PageAction } from './page-actions.js';
|
|
11
13
|
|
|
12
14
|
/** The same option names, types and meanings as `createEngine` and `definePlayer`; the editor makes its own secret. */
|
|
13
15
|
export interface DefineEditorOptions extends Omit<EngineOptions, 'secret'> {
|
|
@@ -57,6 +59,18 @@ export interface DefineEditorOptions extends Omit<EngineOptions, 'secret'> {
|
|
|
57
59
|
* Default: none.
|
|
58
60
|
*/
|
|
59
61
|
readonly views?: readonly EditorHostView[];
|
|
62
|
+
/**
|
|
63
|
+
* The toolbar's items and their order: groups of item names (`TOOLBAR_ITEMS`), a rule between groups; an item not
|
|
64
|
+
* named is not drawn. A later call's layout replaces it; an element's `toolbarLayout` overrides it. Default:
|
|
65
|
+
* `DEFAULT_TOOLBAR_LAYOUT`.
|
|
66
|
+
*/
|
|
67
|
+
readonly toolbarLayout?: ToolbarLayout;
|
|
68
|
+
/**
|
|
69
|
+
* The buttons of each page's head on the TipTap surface, in order: `add-title`, `check`, `join`, `delete`; one not
|
|
70
|
+
* listed is not drawn. A later call's list replaces it; an element's `pageActions` overrides it. Default:
|
|
71
|
+
* `PAGE_ACTIONS`, all four.
|
|
72
|
+
*/
|
|
73
|
+
readonly pageActions?: readonly PageAction[];
|
|
60
74
|
}
|
|
61
75
|
|
|
62
76
|
/** A host view of `<astl-editor>`: its name (lower-case letters, digits and dashes) and its label in the switch. */
|
package/src/element.ts
CHANGED
|
@@ -31,6 +31,7 @@ import {
|
|
|
31
31
|
createAuthoring,
|
|
32
32
|
DEFAULT_FONTS,
|
|
33
33
|
DEFAULT_STYLES,
|
|
34
|
+
DEFAULT_TOOLBAR_LAYOUT,
|
|
34
35
|
EDITOR_NAMESPACE,
|
|
35
36
|
type EditorFont,
|
|
36
37
|
type EditorStylePreset,
|
|
@@ -40,11 +41,13 @@ import {
|
|
|
40
41
|
type HelpPart,
|
|
41
42
|
type Outline,
|
|
42
43
|
type PickPicture,
|
|
44
|
+
type ToolbarLayout,
|
|
43
45
|
type ToolbarView,
|
|
46
|
+
toolbarButtonParts,
|
|
44
47
|
type UploadAsset,
|
|
45
48
|
} from '@astl/editor';
|
|
46
49
|
import { createEngine } from '@astl/engine';
|
|
47
|
-
import type { ElementEntry } from '@astl/player';
|
|
50
|
+
import type { ElementEntry, HintPosition } from '@astl/player';
|
|
48
51
|
import { type ThemeSetting, tokens, tokensCss } from '@astl/tokens';
|
|
49
52
|
import {
|
|
50
53
|
type CSSResult,
|
|
@@ -61,6 +64,7 @@ import {
|
|
|
61
64
|
import { keyed } from 'lit/directives/keyed.js';
|
|
62
65
|
import type { SurfaceChange } from './blocks.js';
|
|
63
66
|
import type { DefineEditorOptions, EditorHostView } from './define.js';
|
|
67
|
+
import { PAGE_ACTIONS, type PageAction, pageActionsOf } from './page-actions.js';
|
|
64
68
|
import type { Surface } from './surface.js';
|
|
65
69
|
|
|
66
70
|
/**
|
|
@@ -121,11 +125,6 @@ const editorStyles: CSSResultGroup = [
|
|
|
121
125
|
.surface {
|
|
122
126
|
position: relative;
|
|
123
127
|
}
|
|
124
|
-
::slotted(*) {
|
|
125
|
-
box-sizing: border-box;
|
|
126
|
-
inline-size: 100%;
|
|
127
|
-
max-inline-size: 100%;
|
|
128
|
-
}
|
|
129
128
|
.status {
|
|
130
129
|
margin: 0;
|
|
131
130
|
padding: var(--astl-space-4);
|
|
@@ -135,6 +134,14 @@ const editorStyles: CSSResultGroup = [
|
|
|
135
134
|
color: var(--astl-ink-muted);
|
|
136
135
|
}
|
|
137
136
|
`,
|
|
137
|
+
// The host's elements take their column's width; those in the toolbar's ends keep their own, as items of its bar.
|
|
138
|
+
css`
|
|
139
|
+
::slotted(:not([slot='toolbar-start'], [slot='toolbar-end'])) {
|
|
140
|
+
box-sizing: border-box;
|
|
141
|
+
inline-size: 100%;
|
|
142
|
+
max-inline-size: 100%;
|
|
143
|
+
}
|
|
144
|
+
`,
|
|
138
145
|
// The side column and the host's columns in another view, and a host column with nothing slotted: out of the way (the
|
|
139
146
|
// grid keeps no track and no gap for them). The notice line with nothing to say: out of sight, but still in the
|
|
140
147
|
// accessibility tree, so its next message is announced.
|
|
@@ -237,6 +244,10 @@ interface Registered {
|
|
|
237
244
|
readonly featured: readonly string[];
|
|
238
245
|
/** The host's views (`DefineEditorOptions.views`). */
|
|
239
246
|
readonly views: readonly EditorHostView[];
|
|
247
|
+
/** The toolbar's items and their order (`DefineEditorOptions.toolbarLayout`). */
|
|
248
|
+
readonly toolbarLayout: ToolbarLayout;
|
|
249
|
+
/** The buttons of the page heads (`DefineEditorOptions.pageActions`). */
|
|
250
|
+
readonly pageActions: readonly PageAction[];
|
|
240
251
|
/** The insert menus' catalogs (`DefineEditorOptions.menuMessages`). */
|
|
241
252
|
readonly menuMessages: (() => Promise<readonly MessageCatalog[]>) | null;
|
|
242
253
|
/** The engine of every registered component, for editors without a `components` list. */
|
|
@@ -293,6 +304,8 @@ const EMPTY: Lists = {
|
|
|
293
304
|
styles: DEFAULT_STYLES,
|
|
294
305
|
featured: [],
|
|
295
306
|
views: [],
|
|
307
|
+
toolbarLayout: DEFAULT_TOOLBAR_LAYOUT,
|
|
308
|
+
pageActions: PAGE_ACTIONS,
|
|
296
309
|
menuMessages: null,
|
|
297
310
|
};
|
|
298
311
|
|
|
@@ -344,12 +357,14 @@ export function register(options: DefineEditorOptions): void {
|
|
|
344
357
|
styles: options.styles ?? before.styles,
|
|
345
358
|
featured: options.featured ?? before.featured,
|
|
346
359
|
views: options.views ?? before.views,
|
|
360
|
+
toolbarLayout: options.toolbarLayout ?? before.toolbarLayout,
|
|
361
|
+
pageActions: options.pageActions ?? before.pageActions,
|
|
347
362
|
menuMessages: options.menuMessages ?? before.menuMessages,
|
|
348
363
|
};
|
|
349
364
|
// Nothing new (the same objects again): connected editors keep their surface, cursor and undo history.
|
|
350
365
|
const maps = ['components', 'editors', 'elements', 'styleTemplates', 'slotKinds'] as const;
|
|
351
366
|
const profile = (p: Lists['profile']) => JSON.stringify(Object.entries(p).sort());
|
|
352
|
-
|
|
367
|
+
const sameKit =
|
|
353
368
|
registered !== null &&
|
|
354
369
|
maps.every((list) => lists[list].size === before[list].size) &&
|
|
355
370
|
lists.catalogs.length === before.catalogs.length &&
|
|
@@ -360,10 +375,13 @@ export function register(options: DefineEditorOptions): void {
|
|
|
360
375
|
lists.menuMessages === before.menuMessages &&
|
|
361
376
|
JSON.stringify(lists.fonts) === JSON.stringify(before.fonts) &&
|
|
362
377
|
JSON.stringify(lists.styles) === JSON.stringify(before.styles) &&
|
|
363
|
-
lists.
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
378
|
+
profile(lists.profile) === profile(before.profile);
|
|
379
|
+
// Only the toolbar's and the page heads' layout changed: the same authoring, so the editors keep their surfaces.
|
|
380
|
+
if (registered !== null && sameKit) {
|
|
381
|
+
const layout = (r: Lists) => JSON.stringify([r.featured, r.views, r.toolbarLayout, r.pageActions]);
|
|
382
|
+
if (layout(lists) === layout(before)) return;
|
|
383
|
+
registered = { ...registered, ...lists };
|
|
384
|
+
for (const editor of connected) editor.requestUpdate();
|
|
367
385
|
return;
|
|
368
386
|
}
|
|
369
387
|
// The engine and the kit check definitions and descriptors now, not when an editor first renders.
|
|
@@ -409,6 +427,8 @@ interface Notice {
|
|
|
409
427
|
const CHANGE = 'astl-editor-change';
|
|
410
428
|
const READY = 'astl-editor-ready';
|
|
411
429
|
const VIEW = 'astl-editor-view';
|
|
430
|
+
/** The toolbar's block size in px, kept on the element for a host's layout (a sticky toolbar, columns under it). */
|
|
431
|
+
const TOOLBAR_SIZE = '--astl-editor-toolbar-block-size';
|
|
412
432
|
|
|
413
433
|
/** The views of every editor: the surface, and the source as HTML (not for a surface that is the source already). */
|
|
414
434
|
const OWN_VIEWS: readonly string[] = ['visual', 'source'];
|
|
@@ -459,6 +479,25 @@ const KIT_ICONS: readonly string[] = [
|
|
|
459
479
|
const INSPECTOR_PARTS =
|
|
460
480
|
'header: inspector-header, id: inspector-id, actions: inspector-actions, issue: inspector-issue, field: inspector-field, label: inspector-label, style: inspector-style, help: inspector-help, help-toggle: inspector-help-toggle, help-summary: inspector-help-summary, help-body: inspector-help-body, help-add: inspector-help-add, help-move: inspector-help-move, help-remove: inspector-help-remove, check-targets: inspector-check-targets, checked-by: inspector-checked-by';
|
|
461
481
|
|
|
482
|
+
/** The preview player's help parts, forwarded so hosts can restyle its help rows (`::part(preview-hint-cost)`). */
|
|
483
|
+
const PREVIEW_PARTS = [
|
|
484
|
+
'help',
|
|
485
|
+
'check',
|
|
486
|
+
'check-summary',
|
|
487
|
+
'help-actions',
|
|
488
|
+
'check-button',
|
|
489
|
+
'hint-offer',
|
|
490
|
+
'hint-button',
|
|
491
|
+
'hint-cost',
|
|
492
|
+
'hints',
|
|
493
|
+
'help-feedback',
|
|
494
|
+
'help-why',
|
|
495
|
+
'help-problem',
|
|
496
|
+
'help-top',
|
|
497
|
+
]
|
|
498
|
+
.map((name) => `${name}: preview-${name}`)
|
|
499
|
+
.join(', ');
|
|
500
|
+
|
|
462
501
|
/** The built-in surface module, once imported. */
|
|
463
502
|
let surfaces: typeof import('./surface.js') | null = null;
|
|
464
503
|
/** The source view's module, once imported (when the view first opens). */
|
|
@@ -470,9 +509,12 @@ export class AstlEditor extends LitElement {
|
|
|
470
509
|
components: { converter: listAttribute },
|
|
471
510
|
featured: { converter: listAttribute },
|
|
472
511
|
panels: { converter: listAttribute },
|
|
512
|
+
toolbarLayout: { attribute: false },
|
|
513
|
+
pageActions: { attribute: 'page-actions', converter: listAttribute },
|
|
473
514
|
view: {},
|
|
474
515
|
views: { converter: viewsAttribute },
|
|
475
516
|
theme: {},
|
|
517
|
+
hintPosition: { attribute: 'hint-position', reflect: true },
|
|
476
518
|
previewPolicy: { attribute: false },
|
|
477
519
|
adapter: { attribute: false },
|
|
478
520
|
};
|
|
@@ -497,6 +539,18 @@ export class AstlEditor extends LitElement {
|
|
|
497
539
|
* or `<astl-issues>`, wired with `authoring` and `adapter` once the editor is ready.
|
|
498
540
|
*/
|
|
499
541
|
declare panels: readonly string[] | null;
|
|
542
|
+
/**
|
|
543
|
+
* The toolbar's items and their order, for this editor, in place of the `toolbarLayout` of `defineEditor`: groups of
|
|
544
|
+
* item names (`TOOLBAR_ITEMS`), a rule between groups; an item not named is not drawn. Null: the registered layout.
|
|
545
|
+
*/
|
|
546
|
+
declare toolbarLayout: ToolbarLayout | null;
|
|
547
|
+
/**
|
|
548
|
+
* The buttons of each page's head on the TipTap surface, in order (space-separated in the attribute): `add-title`,
|
|
549
|
+
* `check`, `join`, `delete`; one not listed is not drawn, and a change redraws the heads at once. Null: the list
|
|
550
|
+
* `defineEditor` got. The adapter's `addPage`, `mergePage`, `removePage` and `setPageCheck` stay for a host's own
|
|
551
|
+
* controls.
|
|
552
|
+
*/
|
|
553
|
+
declare pageActions: readonly PageAction[] | null;
|
|
500
554
|
/**
|
|
501
555
|
* What the editor shows: `visual` (default) the surface; `source` the document's HTML in a text area, which leaving
|
|
502
556
|
* applies (with errors the editor stays there and lists them, so no text is lost); or the `name` of one of `views`.
|
|
@@ -510,6 +564,12 @@ export class AstlEditor extends LitElement {
|
|
|
510
564
|
declare views: readonly EditorHostView[] | null;
|
|
511
565
|
/** `light`, `dark`, `hc` or `auto` (the system's light or dark), passed on as `data-theme`. */
|
|
512
566
|
declare theme: ThemeSetting | null;
|
|
567
|
+
/**
|
|
568
|
+
* Where the preview's player puts a question's hint (`hint-position`), as on `<astl-player>`: `row`, in its help row
|
|
569
|
+
* after its Check (the default), or `top`, at the top of the question; another value is `row`. Set it as your
|
|
570
|
+
* students' player has it. A change applies at once.
|
|
571
|
+
*/
|
|
572
|
+
declare hintPosition: HintPosition;
|
|
513
573
|
/**
|
|
514
574
|
* The policy the preview plays under: the one the host's students get, when it offers less than practice (no hints,
|
|
515
575
|
* no check of one interaction). Null: `PRACTICE_POLICY`. A change plays a shown preview again.
|
|
@@ -603,9 +663,12 @@ export class AstlEditor extends LitElement {
|
|
|
603
663
|
this.components = null;
|
|
604
664
|
this.featured = null;
|
|
605
665
|
this.panels = null;
|
|
666
|
+
this.toolbarLayout = null;
|
|
667
|
+
this.pageActions = null;
|
|
606
668
|
this.view = 'visual';
|
|
607
669
|
this.views = null;
|
|
608
670
|
this.theme = 'auto';
|
|
671
|
+
this.hintPosition = 'row';
|
|
609
672
|
this.previewPolicy = null;
|
|
610
673
|
this.adapter = null;
|
|
611
674
|
// A value set before the element was defined is an own property that hides the accessor.
|
|
@@ -637,6 +700,27 @@ export class AstlEditor extends LitElement {
|
|
|
637
700
|
return this.#ready;
|
|
638
701
|
}
|
|
639
702
|
|
|
703
|
+
/**
|
|
704
|
+
* The toolbar (`<astl-toolbar>`, `part="toolbar"`) once the editor has rendered, else null: for its box, its
|
|
705
|
+
* `popupOpen` and its `openMenu` and `openStyle`.
|
|
706
|
+
*/
|
|
707
|
+
get toolbar(): AstlToolbar | null {
|
|
708
|
+
return this.shadowRoot?.querySelector<AstlToolbar>('astl-toolbar') ?? null;
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
/** Keeps `--astl-editor-toolbar-block-size` on this element: the toolbar's block size, one row or more. */
|
|
712
|
+
readonly #toolbarSize = new ResizeObserver(([entry]) => {
|
|
713
|
+
const size = entry?.borderBoxSize[0]?.blockSize;
|
|
714
|
+
if (size !== undefined) this.style.setProperty(TOOLBAR_SIZE, `${size}px`);
|
|
715
|
+
});
|
|
716
|
+
|
|
717
|
+
/** Measures the toolbar while connected (the same element across renders). */
|
|
718
|
+
#measureToolbar(): void {
|
|
719
|
+
this.#toolbarSize.disconnect();
|
|
720
|
+
const toolbar = this.isConnected ? this.toolbar : null;
|
|
721
|
+
if (toolbar !== null) this.#toolbarSize.observe(toolbar);
|
|
722
|
+
}
|
|
723
|
+
|
|
640
724
|
/**
|
|
641
725
|
* Compiles the current value and plays it in the preview, as the preview's own button does. Resolves when it plays,
|
|
642
726
|
* or shows why it cannot.
|
|
@@ -665,12 +749,14 @@ export class AstlEditor extends LitElement {
|
|
|
665
749
|
// applied the properties set before the element was defined (an `adapter`).
|
|
666
750
|
if (this.#builtIn === true) void this.#open();
|
|
667
751
|
this.#subscribe();
|
|
752
|
+
this.#measureToolbar();
|
|
668
753
|
}
|
|
669
754
|
|
|
670
755
|
override disconnectedCallback(): void {
|
|
671
756
|
super.disconnectedCallback();
|
|
672
757
|
connected.delete(this);
|
|
673
758
|
clearTimeout(this.#counting);
|
|
759
|
+
this.#measureToolbar();
|
|
674
760
|
this.#readyFor = null;
|
|
675
761
|
this.#subscribe();
|
|
676
762
|
// ProseMirror listens on the document: a removed editor is destroyed, its source kept for a reconnect.
|
|
@@ -682,6 +768,13 @@ export class AstlEditor extends LitElement {
|
|
|
682
768
|
this.adapter = null;
|
|
683
769
|
}
|
|
684
770
|
|
|
771
|
+
/** The page heads' buttons: the element's (also in the attribute's form, a string), else the registered ones. */
|
|
772
|
+
#pageActions(): readonly PageAction[] {
|
|
773
|
+
const given = this.pageActions as readonly string[] | string | null;
|
|
774
|
+
const list = typeof given === 'string' ? given.split(/\s+/) : given;
|
|
775
|
+
return pageActionsOf(Array.isArray(list) ? list : current().pageActions);
|
|
776
|
+
}
|
|
777
|
+
|
|
685
778
|
/** The host's views: the element's, else the registered ones. */
|
|
686
779
|
#hostViews(): readonly EditorHostView[] {
|
|
687
780
|
const views = this.views ?? current().views;
|
|
@@ -774,15 +867,22 @@ export class AstlEditor extends LitElement {
|
|
|
774
867
|
source,
|
|
775
868
|
this.#pictures,
|
|
776
869
|
this.#pages,
|
|
870
|
+
this.#pageActions(),
|
|
777
871
|
);
|
|
778
872
|
this.adapter = this.#surface.adapter;
|
|
779
873
|
}
|
|
780
874
|
this.#subscribe();
|
|
781
875
|
}
|
|
782
876
|
|
|
877
|
+
protected override firstUpdated(): void {
|
|
878
|
+
this.#measureToolbar();
|
|
879
|
+
}
|
|
880
|
+
|
|
783
881
|
protected override updated(changed: PropertyValues<this>): void {
|
|
784
882
|
// The preview reads its theme when it renders.
|
|
785
883
|
if (changed.has('theme')) this.renderRoot.querySelector<LitElement>('astl-preview')?.requestUpdate();
|
|
884
|
+
// The element's list, or a registration's: the heads draw again only when it says something new.
|
|
885
|
+
this.#surface?.setPageActions(this.#pageActions());
|
|
786
886
|
const adapter = this.adapter;
|
|
787
887
|
if (adapter !== null && adapter !== this.#readyFor && this.isConnected) {
|
|
788
888
|
this.#readyFor = adapter;
|
|
@@ -822,6 +922,7 @@ export class AstlEditor extends LitElement {
|
|
|
822
922
|
this.value,
|
|
823
923
|
this.#pictures,
|
|
824
924
|
this.#pages,
|
|
925
|
+
this.#pageActions(),
|
|
825
926
|
);
|
|
826
927
|
this.#pending = null;
|
|
827
928
|
this.adapter = this.#surface.adapter;
|
|
@@ -889,10 +990,28 @@ export class AstlEditor extends LitElement {
|
|
|
889
990
|
typeof value === 'string' ? value.split(/\s+/).filter((name) => name !== '') : value;
|
|
890
991
|
const featured = list(this.featured) ?? current().featured;
|
|
891
992
|
const panels = (list(this.panels) ?? PANELS).filter((name) => PANELS.includes(name));
|
|
993
|
+
const toolbarLayout = Array.isArray(this.toolbarLayout) ? this.toolbarLayout : current().toolbarLayout;
|
|
994
|
+
const t = (key: string, params?: MessageParams) => authoring.t(EDITOR_NAMESPACE, key, params);
|
|
995
|
+
const view = this.#view();
|
|
996
|
+
// A surface that edits the source as text is the HTML already: its one view takes the HTML view's name and
|
|
997
|
+
// description, as it makes that view needless.
|
|
998
|
+
const views: ToolbarView[] = [
|
|
999
|
+
...this.#ownViews().map((name) => {
|
|
1000
|
+
const shown = adapter?.editsSource === true ? 'source' : name;
|
|
1001
|
+
return { name, label: t(`view.${shown}`), description: t(`view.${shown}Hint`) };
|
|
1002
|
+
}),
|
|
1003
|
+
...this.#hostViews(),
|
|
1004
|
+
];
|
|
892
1005
|
const icons = new Set([
|
|
893
1006
|
...KIT_ICONS,
|
|
894
1007
|
...authoring.descriptors.flatMap((d) => [d.icon, ...(d.templates ?? []).map((t) => t.icon ?? d.icon)]),
|
|
895
1008
|
]);
|
|
1009
|
+
// Every button by its name too, so a host restyles one (`::part(toolbar-button-bold)`).
|
|
1010
|
+
const buttons = toolbarButtonParts({
|
|
1011
|
+
featured,
|
|
1012
|
+
wraps: authoring.descriptors.filter((d) => d.wrap !== undefined).map((d) => d.manifest.tag),
|
|
1013
|
+
views: views.map((one) => one.name),
|
|
1014
|
+
});
|
|
896
1015
|
const exported = [
|
|
897
1016
|
'toolbar: toolbar-bar',
|
|
898
1017
|
'button: toolbar-button',
|
|
@@ -908,31 +1027,21 @@ export class AstlEditor extends LitElement {
|
|
|
908
1027
|
'style-panel',
|
|
909
1028
|
]
|
|
910
1029
|
.concat([...icons].map((name) => `icon-${name}`))
|
|
1030
|
+
.concat(buttons.map((name) => `${name}: toolbar-${name}`))
|
|
911
1031
|
.join(', ');
|
|
912
1032
|
const panel = (name: string) =>
|
|
913
1033
|
name === 'issues'
|
|
914
1034
|
? html`<astl-issues part="issues" data-theme=${theme} .authoring=${authoring} .adapter=${adapter}></astl-issues>`
|
|
915
1035
|
: html`<astl-inspector part="inspector" exportparts=${INSPECTOR_PARTS} data-theme=${theme} .authoring=${authoring} .adapter=${adapter}></astl-inspector>`;
|
|
916
|
-
const t = (key: string, params?: MessageParams) => authoring.t(EDITOR_NAMESPACE, key, params);
|
|
917
|
-
const view = this.#view();
|
|
918
|
-
// A surface that edits the source as text is the HTML already: its one view takes the HTML view's name and
|
|
919
|
-
// description, as it makes that view needless.
|
|
920
|
-
const views: ToolbarView[] = [
|
|
921
|
-
...this.#ownViews().map((name) => {
|
|
922
|
-
const shown = adapter?.editsSource === true ? 'source' : name;
|
|
923
|
-
return { name, label: t(`view.${shown}`), description: t(`view.${shown}Hint`) };
|
|
924
|
-
}),
|
|
925
|
-
...this.#hostViews(),
|
|
926
|
-
];
|
|
927
1036
|
// The toolbar spans the editor, as a word processor's: above the text and the side column.
|
|
928
1037
|
// Another view takes the surface's place, without the side column; the notice line stays, the one live region.
|
|
929
1038
|
const away = view !== 'visual';
|
|
930
1039
|
return html`<div class=${panels.length === 0 || away ? 'layout solo' : 'layout'}>
|
|
931
1040
|
<astl-toolbar part="toolbar" exportparts=${exported} data-theme=${theme} .authoring=${authoring}
|
|
932
|
-
.adapter=${adapter} .featured=${featured} .views=${views} .view=${view}
|
|
1041
|
+
.adapter=${adapter} .featured=${featured} .views=${views} .view=${view} .layout=${toolbarLayout}
|
|
933
1042
|
@astl-toolbar-view=${(event: CustomEvent<{ view: string }>) => {
|
|
934
1043
|
this.view = event.detail.view;
|
|
935
|
-
}}></astl-toolbar>
|
|
1044
|
+
}}><slot name="toolbar-start" slot="start"></slot><slot name="toolbar-end" slot="end"></slot></astl-toolbar>
|
|
936
1045
|
${this.#statusLine()}
|
|
937
1046
|
<div class="work" part="work">
|
|
938
1047
|
<div class="start" part="start" ?hidden=${away || !this.#slotted.start}>
|
|
@@ -950,8 +1059,8 @@ export class AstlEditor extends LitElement {
|
|
|
950
1059
|
<slot name="end" @slotchange=${this.#slotChange}></slot>
|
|
951
1060
|
</div>
|
|
952
1061
|
</div>
|
|
953
|
-
<astl-preview part="preview" data-theme=${theme} .authoring=${authoring}
|
|
954
|
-
.policy=${this.previewPolicy ?? PRACTICE_POLICY}></astl-preview>
|
|
1062
|
+
<astl-preview part="preview" exportparts=${PREVIEW_PARTS} data-theme=${theme} .authoring=${authoring}
|
|
1063
|
+
.adapter=${adapter} .policy=${this.previewPolicy ?? PRACTICE_POLICY} .hintPosition=${this.hintPosition}></astl-preview>
|
|
955
1064
|
</div>`;
|
|
956
1065
|
}
|
|
957
1066
|
|
package/src/index.ts
CHANGED
|
@@ -8,3 +8,5 @@
|
|
|
8
8
|
export type { DefineEditorOptions, EditorHostView } from './define.js';
|
|
9
9
|
export { defineEditor } from './define.js';
|
|
10
10
|
export { AstlEditor } from './element.js';
|
|
11
|
+
export type { PageAction } from './page-actions.js';
|
|
12
|
+
export { PAGE_ACTIONS } from './page-actions.js';
|