@cosmicdrift/kumiko-samples 0.418.0 → 0.420.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/package.json +1 -1
- package/packages/bundled-features/package.json +11 -1
- package/packages/bundled-features/src/shared/index.ts +6 -0
- package/packages/bundled-features/src/shared/tenant-scoped-subject.ts +28 -0
- package/packages/bundled-features/src/signature/changes.json +6 -0
- package/packages/bundled-features/src/signature/feature.ts +1 -1
- package/packages/bundled-features/src/signature/grant.ts +13 -14
- package/packages/bundled-features/src/signature/png.ts +33 -12
- package/packages/bundled-features/src/template-resolver/api.ts +17 -7
- package/packages/bundled-features/src/template-resolver/changes.json +62 -0
- package/packages/bundled-features/src/template-resolver/compile-document-body.ts +10 -9
- package/packages/bundled-features/src/template-resolver/compile-document-styles.ts +170 -0
- package/packages/bundled-features/src/template-resolver/document-frames.ts +68 -0
- package/packages/bundled-features/src/template-resolver/document-op-blocks.ts +682 -0
- package/packages/bundled-features/src/template-resolver/document-ops.ts +170 -128
- package/packages/bundled-features/src/template-resolver/document-print-only.ts +65 -0
- package/packages/bundled-features/src/template-resolver/document-sanitizer.ts +53 -19
- package/packages/bundled-features/src/template-resolver/feature.ts +15 -0
- package/packages/bundled-features/src/template-resolver/handlers/apply-layout.write.ts +137 -0
- package/packages/bundled-features/src/template-resolver/handlers/create-layout.write.ts +87 -0
- package/packages/bundled-features/src/template-resolver/handlers/document-base.ts +2 -2
- package/packages/bundled-features/src/template-resolver/handlers/document-blocks.query.ts +13 -8
- package/packages/bundled-features/src/template-resolver/handlers/document-region.ts +47 -0
- package/packages/bundled-features/src/template-resolver/handlers/failure-reason.ts +13 -0
- package/packages/bundled-features/src/template-resolver/handlers/import-bundle-system.write.ts +3 -0
- package/packages/bundled-features/src/template-resolver/handlers/layout-source.query.ts +17 -5
- package/packages/bundled-features/src/template-resolver/handlers/overview.query.ts +16 -4
- package/packages/bundled-features/src/template-resolver/handlers/patch-draft.write.ts +20 -6
- package/packages/bundled-features/src/template-resolver/handlers/publish-templates.write.ts +69 -0
- package/packages/bundled-features/src/template-resolver/handlers/set.write.ts +7 -0
- package/packages/bundled-features/src/template-resolver/handlers/template-write.ts +15 -3
- package/packages/bundled-features/src/template-resolver/handlers/tenant-settings.ts +159 -0
- package/packages/bundled-features/src/template-resolver/handlers/toggle-status.write.ts +25 -10
- package/packages/bundled-features/src/template-resolver/handlers/upsert-system.write.ts +7 -3
- package/packages/bundled-features/src/template-resolver/handlers/usage.query.ts +131 -18
- package/packages/bundled-features/src/template-resolver/handlers/validate.query.ts +10 -0
- package/packages/bundled-features/src/template-resolver/i18n.ts +3 -0
- package/packages/bundled-features/src/template-resolver/index.ts +39 -0
- package/packages/bundled-features/src/template-resolver/layout-regions.ts +54 -16
- package/packages/bundled-features/src/template-resolver/print-document.ts +3 -1
- package/packages/bundled-features/src/template-resolver/seeding.ts +4 -0
- package/packages/bundled-features/src/template-resolver/template-delivery-policy.ts +11 -1
- package/packages/bundled-features/src/template-resolver/template-edit-policy.ts +37 -1
- package/packages/bundled-features/src/template-resolver/template-meta.ts +31 -6
- package/packages/bundled-features/src/template-resolver/template-preview.ts +29 -9
- package/packages/bundled-features/src/template-resolver/template-validation.ts +10 -3
- package/packages/bundled-features/src/template-resolver/web/constants.ts +33 -0
- package/packages/bundled-features/src/template-resolver/web/document-blocks.ts +5 -0
- package/packages/bundled-features/src/template-resolver/web/document-editor-extensions.ts +93 -25
- package/packages/bundled-features/src/template-resolver/web/document-editor-fonts.ts +13 -0
- package/packages/bundled-features/src/template-resolver/web/document-editor.tsx +4 -1
- package/packages/bundled-features/src/template-resolver/web/document-fonts.ts +21 -0
- package/packages/bundled-features/src/template-resolver/web/document-frame-control.ts +428 -0
- package/packages/bundled-features/src/template-resolver/web/document-frame-node-view.tsx +207 -0
- package/packages/bundled-features/src/template-resolver/web/document-print-decorations.ts +246 -0
- package/packages/bundled-features/src/template-resolver/web/document-print-defaults.ts +59 -0
- package/packages/bundled-features/src/template-resolver/web/document-print-style.ts +381 -0
- package/packages/bundled-features/src/template-resolver/web/document-repeat-strip.ts +80 -0
- package/packages/bundled-features/src/template-resolver/web/document-schema.ts +87 -19
- package/packages/bundled-features/src/template-resolver/web/document-style-css.ts +214 -0
- package/packages/bundled-features/src/template-resolver/web/document-tiptap-bubble.tsx +185 -16
- package/packages/bundled-features/src/template-resolver/web/document-tiptap-content.tsx +70 -7
- package/packages/bundled-features/src/template-resolver/web/document-tiptap-context.ts +13 -1
- package/packages/bundled-features/src/template-resolver/web/document-tiptap-editor.tsx +25 -4
- package/packages/bundled-features/src/template-resolver/web/document-tiptap-helpers.ts +276 -23
- package/packages/bundled-features/src/template-resolver/web/document-tiptap-toolbar-groups.tsx +449 -10
- package/packages/bundled-features/src/template-resolver/web/document-tiptap-toolbar.tsx +108 -17
- package/packages/bundled-features/src/template-resolver/web/document-toolbar-blocks.ts +20 -0
- package/packages/bundled-features/src/template-resolver/web/fontsource-css.d.ts +2 -0
- package/packages/bundled-features/src/template-resolver/web/i18n.ts +32 -0
- package/packages/bundled-features/src/template-resolver/web/index.ts +38 -0
- package/packages/bundled-features/src/template-resolver/web/pdf-constants.ts +16 -0
- package/packages/bundled-features/src/template-resolver/web/placeholder-text.ts +6 -3
- package/packages/bundled-features/src/template-resolver/web/qualified-names.ts +7 -0
- package/packages/bundled-features/src/template-resolver/web/use-document-tiptap-model.ts +74 -5
- package/packages/bundled-features/src/tenant/company-config.ts +48 -0
- package/packages/bundled-features/src/tenant/feature.ts +11 -0
- package/packages/bundled-features/src/tenant/i18n.ts +14 -0
- package/samples/apps/ui-walkthrough/src/app/auth-constants.ts +51 -0
- package/samples/apps/ui-walkthrough/src/app/seed-print-editor-tenants.ts +118 -0
- package/samples/apps/ui-walkthrough/src/app/seed-templates.ts +2 -0
- package/samples/apps/ui-walkthrough/src/app/server.ts +9 -1
- package/samples/apps/ui-walkthrough/src/app/template-seed-data.ts +27 -1
- package/samples/apps/ui-walkthrough/src/features/rental/i18n.ts +8 -0
- package/samples/apps/ui-walkthrough/src/features/rental/screens.ts +1 -0
- package/samples/apps/ui-walkthrough/src/run-config.ts +1 -0
- package/samples/apps/use-all-bundled/feature-manifest.json +236 -0
- package/samples/recipes/pdf-letterhead/README.md +23 -0
- package/samples/recipes/pdf-letterhead/package.json +12 -0
- package/samples/recipes/pdf-letterhead/src/letterhead.ts +92 -0
|
@@ -4,15 +4,27 @@
|
|
|
4
4
|
// collection is rendered. Variables are inserted as `variable` nodes only,
|
|
5
5
|
// never as `{{name}}` text, so the sanitizer's schema keeps them.
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
TextareaContentEditor,
|
|
9
|
+
useLocale,
|
|
10
|
+
usePrimitives,
|
|
11
|
+
useTranslation,
|
|
12
|
+
} from "@cosmicdrift/kumiko-renderer";
|
|
8
13
|
import { type ReactNode, useEffect } from "react";
|
|
14
|
+
import { printDefaultLabelsOf } from "./document-print-defaults.ts";
|
|
9
15
|
import { renderEditorContent } from "./document-tiptap-content.tsx";
|
|
10
16
|
import { buildTiptapContext } from "./document-tiptap-context.ts";
|
|
11
|
-
import { NO_LABELS, NO_NAMES, NO_PREVIEWS } from "./document-tiptap-helpers.ts";
|
|
17
|
+
import { NO_LABELS, NO_NAMES, NO_PREVIEWS, printModeOf } from "./document-tiptap-helpers.ts";
|
|
12
18
|
import { renderHostedEditor, renderInlineEditor } from "./document-tiptap-layout.tsx";
|
|
13
|
-
import {
|
|
19
|
+
import {
|
|
20
|
+
type DocumentEditorProps,
|
|
21
|
+
type DocumentLayoutValues,
|
|
22
|
+
MAIL_DOCUMENT_BLOCKS,
|
|
23
|
+
} from "./document-toolbar-blocks.ts";
|
|
14
24
|
import { useDocumentTiptapModel } from "./use-document-tiptap-model.ts";
|
|
15
25
|
|
|
26
|
+
const NO_LAYOUT_VALUES: DocumentLayoutValues = {};
|
|
27
|
+
|
|
16
28
|
export default function DocumentTiptapEditor({
|
|
17
29
|
id,
|
|
18
30
|
value,
|
|
@@ -25,16 +37,21 @@ export default function DocumentTiptapEditor({
|
|
|
25
37
|
systemVariables = NO_NAMES,
|
|
26
38
|
resourcePreviews = NO_PREVIEWS,
|
|
27
39
|
chrome = "default",
|
|
40
|
+
layoutValues = NO_LAYOUT_VALUES,
|
|
28
41
|
toolbar = "full",
|
|
29
42
|
renderPaper,
|
|
30
43
|
toolbarHost,
|
|
31
44
|
onEditorReady,
|
|
45
|
+
onFrameControlChange,
|
|
46
|
+
formatting,
|
|
32
47
|
}: DocumentEditorProps): ReactNode {
|
|
33
48
|
const t = useTranslation();
|
|
49
|
+
const locale = useLocale().locale();
|
|
34
50
|
const { ActionOverflowMenu, Button, Field, Input } = usePrimitives();
|
|
35
51
|
const canvas = chrome === "canvas";
|
|
36
52
|
const compact = toolbar === "compact" && !canvas;
|
|
37
53
|
const hosted = toolbarHost !== undefined;
|
|
54
|
+
const print = printModeOf(configuredBlocks, hosted, canvas);
|
|
38
55
|
// A photo block needs an images variable to bind to; without one the button would open an empty panel.
|
|
39
56
|
const blocks =
|
|
40
57
|
imageVariables.length === 0
|
|
@@ -48,6 +65,8 @@ export default function DocumentTiptapEditor({
|
|
|
48
65
|
onChange,
|
|
49
66
|
readOnly,
|
|
50
67
|
onEditorReady,
|
|
68
|
+
onFrameControlChange,
|
|
69
|
+
print,
|
|
51
70
|
variableLabels,
|
|
52
71
|
systemVariables,
|
|
53
72
|
resourcePreviews,
|
|
@@ -94,6 +113,8 @@ export default function DocumentTiptapEditor({
|
|
|
94
113
|
canvas,
|
|
95
114
|
compact,
|
|
96
115
|
hosted,
|
|
116
|
+
print,
|
|
117
|
+
printDefaults: printDefaultLabelsOf(t, locale, layoutValues),
|
|
97
118
|
labels: model.labels,
|
|
98
119
|
activeState: model.activeState,
|
|
99
120
|
openPanel: model.openPanel,
|
|
@@ -108,7 +129,7 @@ export default function DocumentTiptapEditor({
|
|
|
108
129
|
variableLabels,
|
|
109
130
|
stableLabels: model.stableLabels,
|
|
110
131
|
});
|
|
111
|
-
const editorContent = renderEditorContent(editor, canvas, hosted);
|
|
132
|
+
const editorContent = renderEditorContent(editor, canvas, hosted, print, formatting === "text");
|
|
112
133
|
|
|
113
134
|
if (hosted) return renderHostedEditor(context, toolbarHost, editorContent);
|
|
114
135
|
|
|
@@ -1,7 +1,21 @@
|
|
|
1
1
|
import type { usePrimitives } from "@cosmicdrift/kumiko-renderer";
|
|
2
2
|
import { isOneOf } from "@cosmicdrift/kumiko-types/type-guards";
|
|
3
3
|
import type { Editor, JSONContent } from "@tiptap/core";
|
|
4
|
-
import type {
|
|
4
|
+
import type { Node as ProseMirrorNode } from "@tiptap/pm/model";
|
|
5
|
+
import {
|
|
6
|
+
addressFrameContent,
|
|
7
|
+
columnsTableContent,
|
|
8
|
+
insertFrame,
|
|
9
|
+
textFrameContent,
|
|
10
|
+
} from "./document-frame-control.ts";
|
|
11
|
+
import { readRowLineAttributes } from "./document-print-style.ts";
|
|
12
|
+
import type { DocumentRowLine } from "./document-style-css.ts";
|
|
13
|
+
import type {
|
|
14
|
+
DocumentPrintBlock,
|
|
15
|
+
DocumentPrintMode,
|
|
16
|
+
DocumentResourcePreview,
|
|
17
|
+
DocumentToolbarBlock,
|
|
18
|
+
} from "./document-toolbar-blocks.ts";
|
|
5
19
|
|
|
6
20
|
export const NO_LABELS: Readonly<Record<string, string>> = {};
|
|
7
21
|
export const NO_NAMES: readonly string[] = [];
|
|
@@ -35,12 +49,216 @@ export const BLOCK_PANEL: Partial<Record<DocumentToolbarBlock, PanelKind>> = {
|
|
|
35
49
|
images: "images",
|
|
36
50
|
};
|
|
37
51
|
|
|
52
|
+
// PDF kinds are the ones whose block set carries a page break; a hosted toolbar means a layout region.
|
|
53
|
+
export function printModeOf(
|
|
54
|
+
blocks: readonly DocumentToolbarBlock[],
|
|
55
|
+
hosted: boolean,
|
|
56
|
+
canvas: boolean,
|
|
57
|
+
): DocumentPrintMode {
|
|
58
|
+
if (!blocks.includes("pageBreak")) return "none";
|
|
59
|
+
return canvas && !hosted ? "page" : "flow";
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export const FONT_SIZES_PT = [6, 7, 8, 9, 10, 11, 12, 14, 16, 18, 24, 36] as const;
|
|
63
|
+
export const LINE_HEIGHTS = [1, 1.15, 1.2, 1.25, 1.5, 2] as const;
|
|
64
|
+
export const PARAGRAPH_SPACES_PT = [0, 3, 6, 8, 12, 18, 24] as const;
|
|
65
|
+
|
|
66
|
+
export type PrintTextStyleState = {
|
|
67
|
+
readonly font: string | null;
|
|
68
|
+
readonly sizePt: number | null;
|
|
69
|
+
readonly color: string | null;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export type PrintBlockStyleState = {
|
|
73
|
+
readonly lineHeight: number | null;
|
|
74
|
+
readonly spaceBeforePt: number | null;
|
|
75
|
+
readonly spaceAfterPt: number | null;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
export type PrintTableState = {
|
|
79
|
+
readonly bordersOff: boolean;
|
|
80
|
+
readonly cellBackground: string | null;
|
|
81
|
+
readonly cellPaddingMm: number | null;
|
|
82
|
+
readonly widthMm: number | null;
|
|
83
|
+
readonly align: string | null;
|
|
84
|
+
readonly lineAbove: DocumentRowLine | null;
|
|
85
|
+
readonly lineBelow: DocumentRowLine | null;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
export const DEFAULT_ROW_LINE: DocumentRowLine = { color: "#000000", weightPt: 0.5 };
|
|
89
|
+
|
|
90
|
+
const TEXT_STYLE_MARK = "documentTextStyle";
|
|
91
|
+
|
|
92
|
+
function stringOrNull(value: unknown): string | null {
|
|
93
|
+
return typeof value === "string" ? value : null;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function numberOrNull(value: unknown): number | null {
|
|
97
|
+
return typeof value === "number" ? value : null;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function printTextStyleOf(e: Editor): PrintTextStyleState {
|
|
101
|
+
const attrs = e.getAttributes(TEXT_STYLE_MARK);
|
|
102
|
+
return {
|
|
103
|
+
font: stringOrNull(attrs["font"]),
|
|
104
|
+
sizePt: numberOrNull(attrs["sizePt"]),
|
|
105
|
+
color: stringOrNull(attrs["color"]),
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function printBlockStyleOf(e: Editor): PrintBlockStyleState {
|
|
110
|
+
const attrs = e.getAttributes(e.isActive("heading") ? "heading" : "paragraph");
|
|
111
|
+
return {
|
|
112
|
+
lineHeight: numberOrNull(attrs["lineHeight"]),
|
|
113
|
+
spaceBeforePt: numberOrNull(attrs["spaceBeforePt"]),
|
|
114
|
+
spaceAfterPt: numberOrNull(attrs["spaceAfterPt"]),
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
type TableLocation = { readonly pos: number; readonly attrs: Record<string, unknown> };
|
|
119
|
+
|
|
120
|
+
function tableLocationOf(e: Editor): TableLocation | null {
|
|
121
|
+
const { $from } = e.state.selection;
|
|
122
|
+
for (let depth = $from.depth; depth > 0; depth--) {
|
|
123
|
+
const node = $from.node(depth);
|
|
124
|
+
if (node.type.name === "table") return { pos: $from.before(depth), attrs: node.attrs };
|
|
125
|
+
}
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function printTableOf(e: Editor): PrintTableState | null {
|
|
130
|
+
const table = tableLocationOf(e);
|
|
131
|
+
if (table === null) return null;
|
|
132
|
+
const { $from } = e.state.selection;
|
|
133
|
+
let cellBackground: string | null = null;
|
|
134
|
+
for (let depth = $from.depth; depth > 0; depth--) {
|
|
135
|
+
const node = $from.node(depth);
|
|
136
|
+
if (node.type.name === "tableCell" || node.type.name === "tableHeader") {
|
|
137
|
+
cellBackground = stringOrNull(node.attrs["background"]);
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
const row = readRowLineAttributes(rowNodeOf(e)?.attrs ?? {});
|
|
142
|
+
return {
|
|
143
|
+
bordersOff: table.attrs["borders"] === "none",
|
|
144
|
+
cellBackground,
|
|
145
|
+
cellPaddingMm: numberOrNull(table.attrs["cellPaddingMm"]),
|
|
146
|
+
widthMm: numberOrNull(table.attrs["widthMm"]),
|
|
147
|
+
align: stringOrNull(table.attrs["align"]),
|
|
148
|
+
lineAbove: row.lineAbove,
|
|
149
|
+
lineBelow: row.lineBelow,
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function rowNodeOf(e: Editor): ProseMirrorNode | null {
|
|
154
|
+
const { $from } = e.state.selection;
|
|
155
|
+
for (let depth = $from.depth; depth > 0; depth--) {
|
|
156
|
+
if ($from.node(depth).type.name === "tableRow") return $from.node(depth);
|
|
157
|
+
}
|
|
158
|
+
return null;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// The table's own print attributes; an empty field removes the attribute again.
|
|
162
|
+
export function setTableAttributes(
|
|
163
|
+
editor: Editor,
|
|
164
|
+
attributes: Readonly<Record<string, unknown>>,
|
|
165
|
+
): void {
|
|
166
|
+
const table = tableLocationOf(editor);
|
|
167
|
+
if (table === null) return;
|
|
168
|
+
editor
|
|
169
|
+
.chain()
|
|
170
|
+
.focus()
|
|
171
|
+
.command(({ tr }) => {
|
|
172
|
+
tr.setNodeMarkup(table.pos, undefined, { ...table.attrs, ...attributes });
|
|
173
|
+
return true;
|
|
174
|
+
})
|
|
175
|
+
.run();
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export function setRowLine(
|
|
179
|
+
editor: Editor,
|
|
180
|
+
edge: "lineAbove" | "lineBelow",
|
|
181
|
+
line: DocumentRowLine | null,
|
|
182
|
+
): void {
|
|
183
|
+
editor
|
|
184
|
+
.chain()
|
|
185
|
+
.focus()
|
|
186
|
+
.updateAttributes("tableRow", { [edge]: line })
|
|
187
|
+
.run();
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
type TextStylePatch = { readonly [K in keyof PrintTextStyleState]?: PrintTextStyleState[K] };
|
|
191
|
+
|
|
192
|
+
export function setPrintTextStyle(editor: Editor, patch: TextStylePatch): void {
|
|
193
|
+
const next = { ...printTextStyleOf(editor), ...patch };
|
|
194
|
+
const chain = editor.chain().focus();
|
|
195
|
+
if (next.font === null && next.sizePt === null && next.color === null) {
|
|
196
|
+
chain.unsetMark(TEXT_STYLE_MARK).run();
|
|
197
|
+
} else {
|
|
198
|
+
chain.setMark(TEXT_STYLE_MARK, next).run();
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
export function setPrintBlockStyle(editor: Editor, patch: Partial<PrintBlockStyleState>): void {
|
|
203
|
+
editor
|
|
204
|
+
.chain()
|
|
205
|
+
.focus()
|
|
206
|
+
.updateAttributes("paragraph", patch)
|
|
207
|
+
.updateAttributes("heading", patch)
|
|
208
|
+
.run();
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
export function toggleTableBorders(editor: Editor): void {
|
|
212
|
+
const table = tableLocationOf(editor);
|
|
213
|
+
if (table === null) return;
|
|
214
|
+
const borders = table.attrs["borders"] === "none" ? null : "none";
|
|
215
|
+
editor
|
|
216
|
+
.chain()
|
|
217
|
+
.focus()
|
|
218
|
+
.command(({ tr }) => {
|
|
219
|
+
tr.setNodeMarkup(table.pos, undefined, { ...table.attrs, borders });
|
|
220
|
+
return true;
|
|
221
|
+
})
|
|
222
|
+
.run();
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
export function insertPrintBlock(editor: Editor, block: DocumentPrintBlock): void {
|
|
226
|
+
if (block === "address") insertFrame(editor, addressFrameContent());
|
|
227
|
+
else if (block === "textFrame") insertFrame(editor, textFrameContent());
|
|
228
|
+
else editor.chain().focus().insertContent(columnsTableContent()).run();
|
|
229
|
+
}
|
|
230
|
+
|
|
38
231
|
export type RepeatTableState = {
|
|
39
232
|
readonly lists: readonly string[];
|
|
40
233
|
readonly headerRepeats: boolean;
|
|
41
234
|
readonly firstRowPos: number;
|
|
42
235
|
};
|
|
43
236
|
|
|
237
|
+
export function repeatListsOf(table: ProseMirrorNode): string[] {
|
|
238
|
+
const lists: string[] = [];
|
|
239
|
+
table.forEach((row) => {
|
|
240
|
+
const each: unknown = row.attrs["each"];
|
|
241
|
+
if (typeof each === "string" && each !== "" && !lists.includes(each)) lists.push(each);
|
|
242
|
+
});
|
|
243
|
+
return lists;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
export function toggleRepeatHeaderAt(editor: Editor, firstRowPos: number): void {
|
|
247
|
+
editor
|
|
248
|
+
.chain()
|
|
249
|
+
.focus()
|
|
250
|
+
.command(({ tr }) => {
|
|
251
|
+
const row = tr.doc.nodeAt(firstRowPos);
|
|
252
|
+
if (row === null) return false;
|
|
253
|
+
tr.setNodeMarkup(firstRowPos, undefined, {
|
|
254
|
+
...row.attrs,
|
|
255
|
+
repeatHeader: row.attrs["repeatHeader"] !== true,
|
|
256
|
+
});
|
|
257
|
+
return true;
|
|
258
|
+
})
|
|
259
|
+
.run();
|
|
260
|
+
}
|
|
261
|
+
|
|
44
262
|
// print-document moves the leading rows flagged repeatHeader into thead, so the
|
|
45
263
|
// toggle reads and writes the table's first row.
|
|
46
264
|
export function findRepeatTable(editor: Editor): RepeatTableState | null {
|
|
@@ -48,11 +266,7 @@ export function findRepeatTable(editor: Editor): RepeatTableState | null {
|
|
|
48
266
|
for (let depth = $from.depth; depth > 0; depth--) {
|
|
49
267
|
const node = $from.node(depth);
|
|
50
268
|
if (node.type.name !== "table") continue;
|
|
51
|
-
const lists
|
|
52
|
-
node.forEach((row) => {
|
|
53
|
-
const each: unknown = row.attrs["each"];
|
|
54
|
-
if (typeof each === "string" && each !== "" && !lists.includes(each)) lists.push(each);
|
|
55
|
-
});
|
|
269
|
+
const lists = repeatListsOf(node);
|
|
56
270
|
if (lists.length === 0) return null;
|
|
57
271
|
return {
|
|
58
272
|
lists,
|
|
@@ -67,19 +281,7 @@ export function toggleRepeatHeader(editor: Editor): void {
|
|
|
67
281
|
const found = findRepeatTable(editor);
|
|
68
282
|
// skip: the cursor is not inside a repeat table
|
|
69
283
|
if (found === null) return;
|
|
70
|
-
editor
|
|
71
|
-
.chain()
|
|
72
|
-
.focus()
|
|
73
|
-
.command(({ tr }) => {
|
|
74
|
-
const row = tr.doc.nodeAt(found.firstRowPos);
|
|
75
|
-
if (row === null) return false;
|
|
76
|
-
tr.setNodeMarkup(found.firstRowPos, undefined, {
|
|
77
|
-
...row.attrs,
|
|
78
|
-
repeatHeader: !found.headerRepeats,
|
|
79
|
-
});
|
|
80
|
-
return true;
|
|
81
|
-
})
|
|
82
|
-
.run();
|
|
284
|
+
toggleRepeatHeaderAt(editor, found.firstRowPos);
|
|
83
285
|
}
|
|
84
286
|
|
|
85
287
|
const PARAGRAPH_STYLES = ["paragraph", "1", "2", "3"] as const;
|
|
@@ -134,12 +336,38 @@ function blockStyleOf(e: Editor): "1" | "2" | "3" | "paragraph" {
|
|
|
134
336
|
|
|
135
337
|
function selectedBlockOf(e: Editor): SelectedBlock | null {
|
|
136
338
|
if (e.isActive("resource")) {
|
|
137
|
-
|
|
339
|
+
const attrs = e.getAttributes("resource");
|
|
340
|
+
return {
|
|
341
|
+
type: "resource",
|
|
342
|
+
detail: String(attrs["resource"]),
|
|
343
|
+
bleed: attrs["bleed"] === true,
|
|
344
|
+
widthMm: numberOrNull(attrs["widthMm"]),
|
|
345
|
+
align: stringOrNull(attrs["align"]),
|
|
346
|
+
};
|
|
138
347
|
}
|
|
139
348
|
if (e.isActive("button")) {
|
|
140
|
-
return {
|
|
349
|
+
return {
|
|
350
|
+
type: "button",
|
|
351
|
+
detail: String(e.getAttributes("button")["href"]),
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
if (e.isActive("divider")) {
|
|
355
|
+
const attrs = e.getAttributes("divider");
|
|
356
|
+
return {
|
|
357
|
+
type: "divider",
|
|
358
|
+
color: stringOrNull(attrs["color"]),
|
|
359
|
+
weightPt: numberOrNull(attrs["weightPt"]),
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
if (e.isActive("variable")) {
|
|
363
|
+
const attrs = e.getAttributes("variable");
|
|
364
|
+
return {
|
|
365
|
+
type: "variable",
|
|
366
|
+
detail: String(attrs["name"]),
|
|
367
|
+
dateStyle: stringOrNull(attrs["dateStyle"]),
|
|
368
|
+
};
|
|
141
369
|
}
|
|
142
|
-
return null; // skip: no resource or
|
|
370
|
+
return null; // skip: no resource, button, divider or placeholder selected
|
|
143
371
|
}
|
|
144
372
|
|
|
145
373
|
export function activeStateOf(e: Editor, showHtml: boolean) {
|
|
@@ -154,11 +382,36 @@ export function activeStateOf(e: Editor, showHtml: boolean) {
|
|
|
154
382
|
orderedList: e.isActive("orderedList"),
|
|
155
383
|
link: e.isActive("link"),
|
|
156
384
|
repeatTable: findRepeatTable(e),
|
|
385
|
+
textStyle: printTextStyleOf(e),
|
|
386
|
+
paragraphStyle: printBlockStyleOf(e),
|
|
387
|
+
printTable: printTableOf(e),
|
|
157
388
|
};
|
|
158
389
|
}
|
|
159
390
|
|
|
160
391
|
export type Primitives = ReturnType<typeof usePrimitives>;
|
|
161
392
|
|
|
162
|
-
export type
|
|
393
|
+
export type ResourceBlock = {
|
|
394
|
+
readonly type: "resource";
|
|
395
|
+
readonly detail: string;
|
|
396
|
+
readonly bleed: boolean;
|
|
397
|
+
readonly widthMm: number | null;
|
|
398
|
+
readonly align: string | null;
|
|
399
|
+
};
|
|
400
|
+
export type ButtonBlock = { readonly type: "button"; readonly detail: string };
|
|
401
|
+
export type DividerBlock = {
|
|
402
|
+
readonly type: "divider";
|
|
403
|
+
readonly color: string | null;
|
|
404
|
+
readonly weightPt: number | null;
|
|
405
|
+
};
|
|
406
|
+
export type VariableBlock = {
|
|
407
|
+
readonly type: "variable";
|
|
408
|
+
readonly detail: string;
|
|
409
|
+
readonly dateStyle: string | null;
|
|
410
|
+
};
|
|
411
|
+
export type SelectedBlock = ResourceBlock | ButtonBlock | DividerBlock | VariableBlock;
|
|
412
|
+
|
|
413
|
+
export function addPlainRowBelow(editor: Editor): void {
|
|
414
|
+
editor.chain().focus().addRowAfter().run();
|
|
415
|
+
}
|
|
163
416
|
|
|
164
417
|
export type ActiveState = ReturnType<typeof activeStateOf>;
|