@pdfme/schemas 6.1.0 → 6.1.1-dev.5
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/dist/{builtins-C0BvXHWr.js → builtins-BpOyUs31.js} +257 -36
- package/dist/builtins-BpOyUs31.js.map +1 -0
- package/dist/builtins.js +1 -1
- package/dist/{dynamicTemplate-Dsrw11aL.js → dynamicTemplate-DslOH4FZ.js} +17 -356
- package/dist/dynamicTemplate-DslOH4FZ.js.map +1 -0
- package/dist/helper-6FilIoVM.js +379 -0
- package/dist/helper-6FilIoVM.js.map +1 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.js +817 -162
- package/dist/index.js.map +1 -1
- package/dist/list/constants.d.ts +10 -0
- package/dist/list/dynamicTemplate.d.ts +2 -0
- package/dist/list/helper.d.ts +15 -0
- package/dist/list/index.d.ts +4 -0
- package/dist/list/pdfRender.d.ts +3 -0
- package/dist/list/propPanel.d.ts +3 -0
- package/dist/list/types.d.ts +36 -0
- package/dist/list/uiRender.d.ts +3 -0
- package/dist/lists-BmAAx0lx.js +117 -0
- package/dist/lists-BmAAx0lx.js.map +1 -0
- package/dist/lists.d.ts +3 -0
- package/dist/lists.js +2 -0
- package/dist/tables/dynamicTemplate.d.ts +2 -1
- package/dist/tables.d.ts +1 -1
- package/dist/tables.js +2 -2
- package/dist/text/linkAnnotation.d.ts +14 -0
- package/dist/text/richTextPdfRender.d.ts +2 -1
- package/dist/text/types.d.ts +1 -0
- package/dist/utils.js +1 -1
- package/package.json +6 -1
- package/dist/builtins-C0BvXHWr.js.map +0 -1
- package/dist/dynamicTemplate-Dsrw11aL.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as mapVerticalAlignToFlex, c as Formatter, d as isInlineMarkdownTextSchema, f as resolveFontVariant, i as makeElementPlainTextContentEditable, l as getExtraFormatterSchema, m as parseInlineMarkdown, n as textSchema, o as uiRender$
|
|
1
|
+
import { D as PLACEHOLDER_FONT_COLOR, N as VERTICAL_ALIGN_MIDDLE, O as SYNTHETIC_BOLD_CSS_TEXT_SHADOW, a as getFontKitFont, g as DEFAULT_ALIGNMENT, m as CODE_BACKGROUND_COLOR, v as DEFAULT_FONT_COLOR } from "./helper-6FilIoVM.js";
|
|
2
|
+
import { a as mapVerticalAlignToFlex, c as Formatter, d as isInlineMarkdownTextSchema, f as resolveFontVariant, i as makeElementPlainTextContentEditable, l as getExtraFormatterSchema, m as parseInlineMarkdown, n as textSchema, o as uiRender$4, p as escapeInlineMarkdown, r as buildStyledTextContainer, s as propPanel$3, t as builtInPlugins, u as pdfRender$4 } from "./builtins-BpOyUs31.js";
|
|
3
|
+
import { a as getCellPropPanelSchema, c as HEX_COLOR_PATTERN, i as getBodyWithRange, l as createSingleTable, n as getDynamicLayoutForTable, o as getColumnStylesPropPanelSchema, r as getBody, s as getDefaultCellStyles, t as getDynamicHeightsForTable } from "./dynamicTemplate-DslOH4FZ.js";
|
|
3
4
|
import { addAlphaToHex, convertForPdfLayoutProps, createErrorElm, createSvgStr, hex2PrintingColor, isEditable, readFile, rotatePoint } from "./utils.js";
|
|
5
|
+
import { a as normalizeListItems, c as LIST_STYLE_BULLET, i as normalizeListItemEntries, l as LIST_STYLE_ORDERED, n as calculateListLayout, o as serializeListItems, s as DEFAULT_LIST_STYLE, t as getDynamicLayoutForList } from "./lists-BmAAx0lx.js";
|
|
4
6
|
import "./tables.js";
|
|
5
7
|
import { DEFAULT_FONT_NAME, ZOOM, b64toUint8Array, getDefaultFont, getFallbackFontName, mm2pt, px2mm } from "@pdfme/common";
|
|
6
8
|
import { Buffer as Buffer$1 } from "buffer";
|
|
7
9
|
import { toRadians } from "@pdfme/pdf-lib";
|
|
8
|
-
import { Barcode, Calendar, CalendarClock, ChevronDown, Circle, CircleDot, Clock, Image, Minus, QrCode, Route, Square, SquareCheck, Table, Type } from "lucide";
|
|
10
|
+
import { Barcode, Calendar, CalendarClock, ChevronDown, Circle, CircleDot, Clock, Image, List, Minus, QrCode, Route, Square, SquareCheck, Table, Type } from "lucide";
|
|
9
11
|
import DOMPurify from "dompurify";
|
|
10
12
|
import bwipjs from "bwip-js";
|
|
11
13
|
import AirDatepicker from "air-datepicker";
|
|
@@ -71,10 +73,10 @@ var validateVariables = (value, schema) => {
|
|
|
71
73
|
};
|
|
72
74
|
//#endregion
|
|
73
75
|
//#region src/multiVariableText/pdfRender.ts
|
|
74
|
-
var pdfRender$
|
|
76
|
+
var pdfRender$3 = async (arg) => {
|
|
75
77
|
const { value, schema, ...rest } = arg;
|
|
76
78
|
if (!validateVariables(value, schema)) return;
|
|
77
|
-
await pdfRender$
|
|
79
|
+
await pdfRender$4({
|
|
78
80
|
value: isInlineMarkdownTextSchema(schema) ? substituteVariablesAsInlineMarkdownLiterals(schema.text || "", value) : substituteVariables(schema.text || "", value),
|
|
79
81
|
schema,
|
|
80
82
|
...rest
|
|
@@ -184,10 +186,10 @@ var mapDynamicVariables = (props) => {
|
|
|
184
186
|
rootElement.appendChild(para);
|
|
185
187
|
}
|
|
186
188
|
};
|
|
187
|
-
var propPanel$
|
|
189
|
+
var propPanel$2 = {
|
|
188
190
|
schema: (propPanelProps) => {
|
|
189
|
-
if (typeof propPanel$
|
|
190
|
-
const parentSchema = typeof propPanel$
|
|
191
|
+
if (typeof propPanel$3.schema !== "function") throw new Error("Oops, is text schema no longer a function?");
|
|
192
|
+
const parentSchema = typeof propPanel$3.schema === "function" ? propPanel$3.schema(propPanelProps) : {};
|
|
191
193
|
const i18n = propPanelProps.i18n;
|
|
192
194
|
return {
|
|
193
195
|
...parentSchema,
|
|
@@ -225,11 +227,11 @@ var propPanel$1 = {
|
|
|
225
227
|
};
|
|
226
228
|
},
|
|
227
229
|
widgets: {
|
|
228
|
-
...propPanel$
|
|
230
|
+
...propPanel$3.widgets,
|
|
229
231
|
mapDynamicVariables
|
|
230
232
|
},
|
|
231
233
|
defaultSchema: {
|
|
232
|
-
...propPanel$
|
|
234
|
+
...propPanel$3.defaultSchema,
|
|
233
235
|
readOnly: false,
|
|
234
236
|
type: "multiVariableText",
|
|
235
237
|
text: "Add text here using {} for variables ",
|
|
@@ -262,7 +264,7 @@ var updateVariablesFromText = (text, variables) => {
|
|
|
262
264
|
};
|
|
263
265
|
//#endregion
|
|
264
266
|
//#region src/multiVariableText/uiRender.ts
|
|
265
|
-
var uiRender$
|
|
267
|
+
var uiRender$3 = async (arg) => {
|
|
266
268
|
const { value, schema, rootElement, mode, onChange, ...rest } = arg;
|
|
267
269
|
let text = schema.text;
|
|
268
270
|
let numVariables = schema.variables.length;
|
|
@@ -271,7 +273,7 @@ var uiRender$2 = async (arg) => {
|
|
|
271
273
|
return;
|
|
272
274
|
}
|
|
273
275
|
const renderValue = isInlineMarkdownTextSchema(schema) ? substituteVariablesAsInlineMarkdownLiterals(text, value) : substituteVariables(text, value);
|
|
274
|
-
await uiRender$
|
|
276
|
+
await uiRender$4({
|
|
275
277
|
value: isEditable(mode, schema) ? text : renderValue,
|
|
276
278
|
schema,
|
|
277
279
|
mode: mode === "form" ? "viewer" : mode,
|
|
@@ -373,7 +375,9 @@ var applyInlineMarkdownStyle = (arg) => {
|
|
|
373
375
|
element.style.textShadow = SYNTHETIC_BOLD_CSS_TEXT_SHADOW;
|
|
374
376
|
}
|
|
375
377
|
if (resolvedFont.syntheticItalic) element.style.fontStyle = "italic";
|
|
376
|
-
|
|
378
|
+
const textDecorations = [];
|
|
379
|
+
if (run.strikethrough) textDecorations.push("line-through");
|
|
380
|
+
if (textDecorations.length > 0) element.style.textDecoration = textDecorations.join(" ");
|
|
377
381
|
if (run.code) {
|
|
378
382
|
element.style.backgroundColor = CODE_BACKGROUND_COLOR;
|
|
379
383
|
element.style.borderRadius = "2px";
|
|
@@ -470,11 +474,775 @@ var keyPressShouldBeChecked = (event) => {
|
|
|
470
474
|
//#endregion
|
|
471
475
|
//#region src/multiVariableText/index.ts
|
|
472
476
|
var schema$1 = {
|
|
477
|
+
pdf: pdfRender$3,
|
|
478
|
+
ui: uiRender$3,
|
|
479
|
+
propPanel: propPanel$2,
|
|
480
|
+
icon: createSvgStr(Type),
|
|
481
|
+
uninterruptedEditMode: true
|
|
482
|
+
};
|
|
483
|
+
//#endregion
|
|
484
|
+
//#region src/shapes/rectAndEllipse.ts
|
|
485
|
+
var shape = {
|
|
486
|
+
ui: (arg) => {
|
|
487
|
+
const { schema, rootElement } = arg;
|
|
488
|
+
const div = document.createElement("div");
|
|
489
|
+
div.style.width = "100%";
|
|
490
|
+
div.style.height = "100%";
|
|
491
|
+
div.style.boxSizing = "border-box";
|
|
492
|
+
if (schema.type === "ellipse") div.style.borderRadius = "50%";
|
|
493
|
+
else if (schema.radius && schema.radius > 0) div.style.borderRadius = `${schema.radius}mm`;
|
|
494
|
+
div.style.borderWidth = `${schema.borderWidth ?? 0}mm`;
|
|
495
|
+
div.style.borderStyle = schema.borderWidth && schema.borderColor ? "solid" : "none";
|
|
496
|
+
div.style.borderColor = schema.borderColor ?? "transparent";
|
|
497
|
+
div.style.backgroundColor = schema.color ?? "transparent";
|
|
498
|
+
rootElement.appendChild(div);
|
|
499
|
+
},
|
|
500
|
+
pdf: (arg) => {
|
|
501
|
+
const { schema, page, options } = arg;
|
|
502
|
+
if (!schema.color && !schema.borderColor) return;
|
|
503
|
+
const { colorType } = options;
|
|
504
|
+
const cArg = {
|
|
505
|
+
schema,
|
|
506
|
+
pageHeight: page.getHeight()
|
|
507
|
+
};
|
|
508
|
+
const { position, width, height, rotate, opacity } = convertForPdfLayoutProps(cArg);
|
|
509
|
+
const { position: { x: x4Ellipse, y: y4Ellipse } } = convertForPdfLayoutProps({
|
|
510
|
+
...cArg,
|
|
511
|
+
applyRotateTranslate: false
|
|
512
|
+
});
|
|
513
|
+
const borderWidth = schema.borderWidth ? mm2pt(schema.borderWidth) : 0;
|
|
514
|
+
const drawOptions = {
|
|
515
|
+
rotate,
|
|
516
|
+
borderWidth,
|
|
517
|
+
borderColor: hex2PrintingColor(schema.borderColor, colorType),
|
|
518
|
+
color: hex2PrintingColor(schema.color, colorType),
|
|
519
|
+
opacity,
|
|
520
|
+
borderOpacity: opacity
|
|
521
|
+
};
|
|
522
|
+
if (schema.type === "ellipse") page.drawEllipse({
|
|
523
|
+
x: x4Ellipse + width / 2,
|
|
524
|
+
y: y4Ellipse + height / 2,
|
|
525
|
+
xScale: width / 2 - borderWidth / 2,
|
|
526
|
+
yScale: height / 2 - borderWidth / 2,
|
|
527
|
+
...drawOptions
|
|
528
|
+
});
|
|
529
|
+
else if (schema.type === "rectangle") {
|
|
530
|
+
const radius = schema.radius ?? 0;
|
|
531
|
+
page.drawRectangle({
|
|
532
|
+
x: position.x + borderWidth * ((1 - Math.sin(toRadians(rotate))) / 2) + Math.tan(toRadians(rotate)) * Math.PI ** 2,
|
|
533
|
+
y: position.y + borderWidth * ((1 + Math.sin(toRadians(rotate))) / 2) + Math.tan(toRadians(rotate)) * Math.PI ** 2,
|
|
534
|
+
width: width - borderWidth,
|
|
535
|
+
height: height - borderWidth,
|
|
536
|
+
...radius ? { radius: mm2pt(radius) } : {},
|
|
537
|
+
...drawOptions
|
|
538
|
+
});
|
|
539
|
+
}
|
|
540
|
+
},
|
|
541
|
+
propPanel: {
|
|
542
|
+
schema: ({ i18n }) => ({
|
|
543
|
+
borderWidth: {
|
|
544
|
+
title: i18n("schemas.borderWidth"),
|
|
545
|
+
type: "number",
|
|
546
|
+
widget: "inputNumber",
|
|
547
|
+
props: {
|
|
548
|
+
min: 0,
|
|
549
|
+
step: 1
|
|
550
|
+
},
|
|
551
|
+
span: 12
|
|
552
|
+
},
|
|
553
|
+
borderColor: {
|
|
554
|
+
title: i18n("schemas.borderColor"),
|
|
555
|
+
type: "string",
|
|
556
|
+
widget: "color",
|
|
557
|
+
props: { disabledAlpha: true },
|
|
558
|
+
rules: [{
|
|
559
|
+
pattern: HEX_COLOR_PATTERN,
|
|
560
|
+
message: i18n("validation.hexColor")
|
|
561
|
+
}],
|
|
562
|
+
span: 12
|
|
563
|
+
},
|
|
564
|
+
color: {
|
|
565
|
+
title: i18n("schemas.color"),
|
|
566
|
+
type: "string",
|
|
567
|
+
widget: "color",
|
|
568
|
+
props: { disabledAlpha: true },
|
|
569
|
+
rules: [{
|
|
570
|
+
pattern: HEX_COLOR_PATTERN,
|
|
571
|
+
message: i18n("validation.hexColor")
|
|
572
|
+
}]
|
|
573
|
+
},
|
|
574
|
+
radius: {
|
|
575
|
+
title: i18n("schemas.radius"),
|
|
576
|
+
type: "number",
|
|
577
|
+
widget: "inputNumber",
|
|
578
|
+
props: {
|
|
579
|
+
min: 0,
|
|
580
|
+
step: 1
|
|
581
|
+
},
|
|
582
|
+
span: 12
|
|
583
|
+
}
|
|
584
|
+
}),
|
|
585
|
+
defaultSchema: {
|
|
586
|
+
name: "",
|
|
587
|
+
type: "rectangle",
|
|
588
|
+
position: {
|
|
589
|
+
x: 0,
|
|
590
|
+
y: 0
|
|
591
|
+
},
|
|
592
|
+
width: 62.5,
|
|
593
|
+
height: 37.5,
|
|
594
|
+
rotate: 0,
|
|
595
|
+
opacity: 1,
|
|
596
|
+
borderWidth: 1,
|
|
597
|
+
borderColor: "#000000",
|
|
598
|
+
color: "",
|
|
599
|
+
readOnly: true,
|
|
600
|
+
radius: 0
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
};
|
|
604
|
+
var getPropPanelSchema = (type) => ({
|
|
605
|
+
...shape.propPanel,
|
|
606
|
+
defaultSchema: {
|
|
607
|
+
...shape.propPanel.defaultSchema,
|
|
608
|
+
type
|
|
609
|
+
}
|
|
610
|
+
});
|
|
611
|
+
var rectangle = {
|
|
612
|
+
...shape,
|
|
613
|
+
propPanel: getPropPanelSchema("rectangle"),
|
|
614
|
+
icon: createSvgStr(Square)
|
|
615
|
+
};
|
|
616
|
+
var ellipse = {
|
|
617
|
+
...shape,
|
|
618
|
+
propPanel: getPropPanelSchema("ellipse"),
|
|
619
|
+
icon: createSvgStr(Circle)
|
|
620
|
+
};
|
|
621
|
+
//#endregion
|
|
622
|
+
//#region src/list/pdfRender.ts
|
|
623
|
+
var rectanglePdfRender$2 = rectangle.pdf;
|
|
624
|
+
var pdfRender$2 = async (arg) => {
|
|
625
|
+
const { schema, value } = arg;
|
|
626
|
+
const items = normalizeListItems(value);
|
|
627
|
+
const range = schema.__itemRange ?? {
|
|
628
|
+
start: 0,
|
|
629
|
+
end: items.length
|
|
630
|
+
};
|
|
631
|
+
const visibleItems = items.slice(range.start, range.end);
|
|
632
|
+
if (visibleItems.length === 0) return;
|
|
633
|
+
const layout = await calculateListLayout({
|
|
634
|
+
schema,
|
|
635
|
+
items: visibleItems,
|
|
636
|
+
markerItems: items,
|
|
637
|
+
startIndex: range.start,
|
|
638
|
+
options: arg.options,
|
|
639
|
+
_cache: arg._cache
|
|
640
|
+
});
|
|
641
|
+
if (schema.backgroundColor) await rectanglePdfRender$2({
|
|
642
|
+
...arg,
|
|
643
|
+
schema: {
|
|
644
|
+
...schema,
|
|
645
|
+
type: "rectangle",
|
|
646
|
+
borderWidth: 0,
|
|
647
|
+
borderColor: "",
|
|
648
|
+
color: schema.backgroundColor
|
|
649
|
+
}
|
|
650
|
+
});
|
|
651
|
+
let y = schema.position.y;
|
|
652
|
+
for (const item of layout.items) {
|
|
653
|
+
await pdfRender$4({
|
|
654
|
+
...arg,
|
|
655
|
+
value: item.marker,
|
|
656
|
+
schema: {
|
|
657
|
+
...schema,
|
|
658
|
+
type: "text",
|
|
659
|
+
position: {
|
|
660
|
+
x: schema.position.x + item.markerX,
|
|
661
|
+
y
|
|
662
|
+
},
|
|
663
|
+
width: layout.markerWidth,
|
|
664
|
+
height: item.height,
|
|
665
|
+
backgroundColor: "",
|
|
666
|
+
alignment: "right",
|
|
667
|
+
verticalAlignment: "top",
|
|
668
|
+
dynamicFontSize: void 0
|
|
669
|
+
}
|
|
670
|
+
});
|
|
671
|
+
await pdfRender$4({
|
|
672
|
+
...arg,
|
|
673
|
+
value: item.item,
|
|
674
|
+
schema: {
|
|
675
|
+
...schema,
|
|
676
|
+
type: "text",
|
|
677
|
+
position: {
|
|
678
|
+
x: schema.position.x + item.bodyX,
|
|
679
|
+
y
|
|
680
|
+
},
|
|
681
|
+
width: item.bodyWidth,
|
|
682
|
+
height: item.height,
|
|
683
|
+
backgroundColor: "",
|
|
684
|
+
verticalAlignment: "top",
|
|
685
|
+
dynamicFontSize: void 0
|
|
686
|
+
}
|
|
687
|
+
});
|
|
688
|
+
y += item.height;
|
|
689
|
+
}
|
|
690
|
+
};
|
|
691
|
+
//#endregion
|
|
692
|
+
//#region src/list/propPanel.ts
|
|
693
|
+
var propPanel$1 = {
|
|
694
|
+
schema: (propPanelProps) => {
|
|
695
|
+
if (typeof propPanel$3.schema !== "function") throw new Error("Oops, is text schema no longer a function?");
|
|
696
|
+
const parentSchema = propPanel$3.schema(propPanelProps);
|
|
697
|
+
const i18n = propPanelProps.i18n;
|
|
698
|
+
const listSchema = { ...parentSchema };
|
|
699
|
+
delete listSchema.useDynamicFontSize;
|
|
700
|
+
delete listSchema.dynamicFontSize;
|
|
701
|
+
return {
|
|
702
|
+
...listSchema,
|
|
703
|
+
"-------": {
|
|
704
|
+
type: "void",
|
|
705
|
+
widget: "Divider"
|
|
706
|
+
},
|
|
707
|
+
listStyle: {
|
|
708
|
+
title: i18n("schemas.list.listStyle"),
|
|
709
|
+
type: "string",
|
|
710
|
+
widget: "select",
|
|
711
|
+
props: { options: [{
|
|
712
|
+
label: i18n("schemas.list.bullet"),
|
|
713
|
+
value: LIST_STYLE_BULLET
|
|
714
|
+
}, {
|
|
715
|
+
label: i18n("schemas.list.ordered"),
|
|
716
|
+
value: LIST_STYLE_ORDERED
|
|
717
|
+
}] },
|
|
718
|
+
span: 24
|
|
719
|
+
},
|
|
720
|
+
markerWidth: {
|
|
721
|
+
title: i18n("schemas.list.markerWidth"),
|
|
722
|
+
type: "number",
|
|
723
|
+
widget: "inputNumber",
|
|
724
|
+
props: { min: 0 },
|
|
725
|
+
span: 6
|
|
726
|
+
},
|
|
727
|
+
markerGap: {
|
|
728
|
+
title: i18n("schemas.list.markerGap"),
|
|
729
|
+
type: "number",
|
|
730
|
+
widget: "inputNumber",
|
|
731
|
+
props: { min: 0 },
|
|
732
|
+
span: 6
|
|
733
|
+
},
|
|
734
|
+
indentSize: {
|
|
735
|
+
title: i18n("schemas.list.indentSize"),
|
|
736
|
+
type: "number",
|
|
737
|
+
widget: "inputNumber",
|
|
738
|
+
props: { min: 0 },
|
|
739
|
+
span: 6
|
|
740
|
+
},
|
|
741
|
+
itemSpacing: {
|
|
742
|
+
title: i18n("schemas.list.itemSpacing"),
|
|
743
|
+
type: "number",
|
|
744
|
+
widget: "inputNumber",
|
|
745
|
+
props: { min: 0 },
|
|
746
|
+
span: 6
|
|
747
|
+
}
|
|
748
|
+
};
|
|
749
|
+
},
|
|
750
|
+
widgets: propPanel$3.widgets,
|
|
751
|
+
defaultSchema: {
|
|
752
|
+
...propPanel$3.defaultSchema,
|
|
753
|
+
type: "list",
|
|
754
|
+
content: JSON.stringify(["First item", "Second item"]),
|
|
755
|
+
width: 80,
|
|
756
|
+
height: 20,
|
|
757
|
+
listStyle: DEFAULT_LIST_STYLE,
|
|
758
|
+
markerWidth: 6,
|
|
759
|
+
markerGap: 2,
|
|
760
|
+
indentSize: 6,
|
|
761
|
+
itemSpacing: 1,
|
|
762
|
+
dynamicFontSize: void 0,
|
|
763
|
+
verticalAlignment: "top"
|
|
764
|
+
}
|
|
765
|
+
};
|
|
766
|
+
//#endregion
|
|
767
|
+
//#region src/list/uiRender.ts
|
|
768
|
+
var focusDataKey = "pdfmeListFocusIndex";
|
|
769
|
+
var actionDataKey = "pdfmeListAction";
|
|
770
|
+
var internalFocusDataKey = "pdfmeListInternalFocus";
|
|
771
|
+
var caretMarker = "";
|
|
772
|
+
var pendingFocusIndexes = /* @__PURE__ */ new Map();
|
|
773
|
+
var getListFocusKey = (schema) => schema.id || schema.name;
|
|
774
|
+
var isComposingKeyboardEvent = (event) => event.isComposing || event.keyCode === 229;
|
|
775
|
+
var getText = (element) => {
|
|
776
|
+
const rawText = element.innerText;
|
|
777
|
+
const hasCaretMarker = rawText.includes(caretMarker);
|
|
778
|
+
let text = rawText.replace(/\u200B/g, "");
|
|
779
|
+
if (!hasCaretMarker && text.endsWith("\n")) text = text.slice(0, -1);
|
|
780
|
+
return text;
|
|
781
|
+
};
|
|
782
|
+
var setStyles = (element, styles) => {
|
|
783
|
+
Object.assign(element.style, styles);
|
|
784
|
+
};
|
|
785
|
+
var focusBody = (body) => {
|
|
786
|
+
body.focus();
|
|
787
|
+
const selection = window.getSelection();
|
|
788
|
+
const range = document.createRange();
|
|
789
|
+
if (selection && range) {
|
|
790
|
+
range.selectNodeContents(body);
|
|
791
|
+
range.collapse(false);
|
|
792
|
+
selection.removeAllRanges();
|
|
793
|
+
selection.addRange(range);
|
|
794
|
+
}
|
|
795
|
+
};
|
|
796
|
+
var getCaretRangeFromPoint = (x, y) => {
|
|
797
|
+
const documentWithCaret = document;
|
|
798
|
+
if (documentWithCaret.caretRangeFromPoint) return documentWithCaret.caretRangeFromPoint(x, y);
|
|
799
|
+
const caretPosition = documentWithCaret.caretPositionFromPoint?.(x, y);
|
|
800
|
+
if (!caretPosition) return null;
|
|
801
|
+
const range = document.createRange();
|
|
802
|
+
range.setStart(caretPosition.offsetNode, caretPosition.offset);
|
|
803
|
+
range.collapse(true);
|
|
804
|
+
return range;
|
|
805
|
+
};
|
|
806
|
+
var focusBodyFromMouseEvent = (body, event) => {
|
|
807
|
+
body.focus();
|
|
808
|
+
const range = getCaretRangeFromPoint(event.clientX, event.clientY);
|
|
809
|
+
if (!range || !body.contains(range.startContainer)) return;
|
|
810
|
+
const selection = window.getSelection();
|
|
811
|
+
if (!selection) return;
|
|
812
|
+
selection.removeAllRanges();
|
|
813
|
+
selection.addRange(range);
|
|
814
|
+
};
|
|
815
|
+
var getBodyEditor = (body) => body.querySelector("[contenteditable], [tabindex]");
|
|
816
|
+
var insertLineBreakAtSelection = (element) => {
|
|
817
|
+
const fallbackText = getText(element);
|
|
818
|
+
const selection = window.getSelection();
|
|
819
|
+
if (!selection?.rangeCount) {
|
|
820
|
+
element.innerText = `${fallbackText}\n${caretMarker}`;
|
|
821
|
+
focusBody(element);
|
|
822
|
+
return true;
|
|
823
|
+
}
|
|
824
|
+
const range = selection.getRangeAt(0);
|
|
825
|
+
if (!element.contains(range.commonAncestorContainer)) {
|
|
826
|
+
element.innerText = `${fallbackText}\n${caretMarker}`;
|
|
827
|
+
focusBody(element);
|
|
828
|
+
return true;
|
|
829
|
+
}
|
|
830
|
+
selection.deleteFromDocument();
|
|
831
|
+
const fragment = document.createDocumentFragment();
|
|
832
|
+
const lineBreak = document.createElement("br");
|
|
833
|
+
const marker = document.createTextNode(caretMarker);
|
|
834
|
+
fragment.append(lineBreak, marker);
|
|
835
|
+
range.insertNode(fragment);
|
|
836
|
+
range.setStart(marker, marker.length);
|
|
837
|
+
range.collapse(true);
|
|
838
|
+
selection.removeAllRanges();
|
|
839
|
+
selection.addRange(range);
|
|
840
|
+
if (!element.innerText.includes(caretMarker)) {
|
|
841
|
+
element.innerText = `${fallbackText}\n${caretMarker}`;
|
|
842
|
+
focusBody(element);
|
|
843
|
+
}
|
|
844
|
+
return true;
|
|
845
|
+
};
|
|
846
|
+
var createActionButton = (arg) => {
|
|
847
|
+
const button = document.createElement("button");
|
|
848
|
+
button.type = "button";
|
|
849
|
+
button.innerText = arg.label;
|
|
850
|
+
button.setAttribute("aria-label", arg.ariaLabel);
|
|
851
|
+
button.disabled = Boolean(arg.disabled);
|
|
852
|
+
setStyles(button, {
|
|
853
|
+
width: "18px",
|
|
854
|
+
height: "18px",
|
|
855
|
+
display: "inline-flex",
|
|
856
|
+
alignItems: "center",
|
|
857
|
+
justifyContent: "center",
|
|
858
|
+
padding: "0",
|
|
859
|
+
border: "1px solid #d9d9d9",
|
|
860
|
+
borderRadius: "3px",
|
|
861
|
+
background: "#ffffff",
|
|
862
|
+
color: "#333333",
|
|
863
|
+
fontSize: "11px",
|
|
864
|
+
lineHeight: "1",
|
|
865
|
+
cursor: arg.disabled ? "not-allowed" : "pointer",
|
|
866
|
+
opacity: arg.disabled ? .45 : 1
|
|
867
|
+
});
|
|
868
|
+
button.addEventListener("pointerdown", (event) => {
|
|
869
|
+
arg.onPressStart?.();
|
|
870
|
+
event.stopPropagation();
|
|
871
|
+
});
|
|
872
|
+
button.addEventListener("mousedown", (event) => {
|
|
873
|
+
arg.onPressStart?.();
|
|
874
|
+
event.preventDefault();
|
|
875
|
+
event.stopPropagation();
|
|
876
|
+
});
|
|
877
|
+
button.addEventListener("click", (event) => {
|
|
878
|
+
event.preventDefault();
|
|
879
|
+
event.stopPropagation();
|
|
880
|
+
if (!arg.disabled) arg.onClick();
|
|
881
|
+
});
|
|
882
|
+
return button;
|
|
883
|
+
};
|
|
884
|
+
var uiRender$2 = async (arg) => {
|
|
885
|
+
const { rootElement, schema, value, mode, onChange, stopEditing, tabIndex, placeholder } = arg;
|
|
886
|
+
const focusKey = getListFocusKey(schema);
|
|
887
|
+
const editable = isEditable(mode, schema);
|
|
888
|
+
const showControls = editable && (mode === "form" || mode === "designer");
|
|
889
|
+
const usePlaceholder = editable && !value && Boolean(placeholder);
|
|
890
|
+
const items = normalizeListItems(usePlaceholder ? placeholder || "" : value);
|
|
891
|
+
const originalItems = normalizeListItemEntries(value);
|
|
892
|
+
const range = schema.__itemRange ?? {
|
|
893
|
+
start: 0,
|
|
894
|
+
end: items.length
|
|
895
|
+
};
|
|
896
|
+
const visibleItems = items.slice(range.start, range.end);
|
|
897
|
+
const renderItems = visibleItems;
|
|
898
|
+
rootElement.innerHTML = "";
|
|
899
|
+
setStyles(rootElement, {
|
|
900
|
+
position: "relative",
|
|
901
|
+
width: "100%",
|
|
902
|
+
height: "100%",
|
|
903
|
+
backgroundColor: schema.backgroundColor || "transparent",
|
|
904
|
+
overflow: "visible"
|
|
905
|
+
});
|
|
906
|
+
const layout = await calculateListLayout({
|
|
907
|
+
schema,
|
|
908
|
+
items: renderItems,
|
|
909
|
+
markerItems: items,
|
|
910
|
+
startIndex: range.start,
|
|
911
|
+
options: arg.options,
|
|
912
|
+
_cache: arg._cache
|
|
913
|
+
});
|
|
914
|
+
const bodyElements = [];
|
|
915
|
+
const getEditedItems = () => layout.items.map((item, index) => ({
|
|
916
|
+
level: item.level,
|
|
917
|
+
text: getText(bodyElements[index])
|
|
918
|
+
}));
|
|
919
|
+
const getNextItems = () => {
|
|
920
|
+
const editedItems = getEditedItems();
|
|
921
|
+
if (usePlaceholder) return editedItems;
|
|
922
|
+
const nextItems = [...originalItems];
|
|
923
|
+
nextItems.splice(range.start, visibleItems.length, ...editedItems);
|
|
924
|
+
return nextItems;
|
|
925
|
+
};
|
|
926
|
+
const commitItems = (nextItems, focusIndex) => {
|
|
927
|
+
if (!onChange) return;
|
|
928
|
+
if (focusIndex !== void 0) {
|
|
929
|
+
rootElement.dataset[focusDataKey] = String(focusIndex);
|
|
930
|
+
pendingFocusIndexes.set(focusKey, focusIndex);
|
|
931
|
+
}
|
|
932
|
+
onChange({
|
|
933
|
+
key: "content",
|
|
934
|
+
value: serializeListItems(nextItems)
|
|
935
|
+
});
|
|
936
|
+
};
|
|
937
|
+
const commitHeight = async (focusIndex) => {
|
|
938
|
+
if (!onChange) return;
|
|
939
|
+
if (focusIndex !== void 0) {
|
|
940
|
+
rootElement.dataset[focusDataKey] = String(focusIndex);
|
|
941
|
+
pendingFocusIndexes.set(focusKey, focusIndex);
|
|
942
|
+
}
|
|
943
|
+
const rawItems = normalizeListItems(serializeListItems(getNextItems()));
|
|
944
|
+
const nextLayout = await calculateListLayout({
|
|
945
|
+
schema,
|
|
946
|
+
items: rawItems.slice(range.start, range.end),
|
|
947
|
+
markerItems: rawItems,
|
|
948
|
+
startIndex: range.start,
|
|
949
|
+
options: arg.options,
|
|
950
|
+
_cache: arg._cache
|
|
951
|
+
});
|
|
952
|
+
if (schema.height !== nextLayout.totalHeight) onChange({
|
|
953
|
+
key: "height",
|
|
954
|
+
value: nextLayout.totalHeight
|
|
955
|
+
});
|
|
956
|
+
};
|
|
957
|
+
const preserveEditingForAction = () => {
|
|
958
|
+
rootElement.dataset[actionDataKey] = "true";
|
|
959
|
+
};
|
|
960
|
+
const updateItems = (rowIndex, mutate) => {
|
|
961
|
+
const nextItems = getNextItems();
|
|
962
|
+
if (nextItems.length === 0) nextItems.push({
|
|
963
|
+
level: 0,
|
|
964
|
+
text: ""
|
|
965
|
+
});
|
|
966
|
+
const focusIndex = mutate(nextItems, Math.min(Math.max(range.start + rowIndex, 0), nextItems.length - 1));
|
|
967
|
+
preserveEditingForAction();
|
|
968
|
+
commitItems(nextItems, focusIndex);
|
|
969
|
+
};
|
|
970
|
+
const preserveEditingForInternalFocus = () => {
|
|
971
|
+
rootElement.dataset[internalFocusDataKey] = "true";
|
|
972
|
+
};
|
|
973
|
+
const preserveEditingForKeyboardCommit = () => {
|
|
974
|
+
preserveEditingForInternalFocus();
|
|
975
|
+
setTimeout(() => {
|
|
976
|
+
if (rootElement.dataset[internalFocusDataKey] === "true") delete rootElement.dataset[internalFocusDataKey];
|
|
977
|
+
});
|
|
978
|
+
};
|
|
979
|
+
const handleInternalFocusPointer = (event) => {
|
|
980
|
+
preserveEditingForInternalFocus();
|
|
981
|
+
event.stopPropagation();
|
|
982
|
+
};
|
|
983
|
+
const handleBodyMouseDown = (body, event) => {
|
|
984
|
+
handleInternalFocusPointer(event);
|
|
985
|
+
focusBodyFromMouseEvent(body, event);
|
|
986
|
+
};
|
|
987
|
+
const appendEmptyListControls = () => {
|
|
988
|
+
const controls = document.createElement("div");
|
|
989
|
+
controls.addEventListener("pointerdown", preserveEditingForAction);
|
|
990
|
+
controls.addEventListener("mousedown", preserveEditingForAction);
|
|
991
|
+
setStyles(controls, {
|
|
992
|
+
position: "absolute",
|
|
993
|
+
top: "0mm",
|
|
994
|
+
right: "-20px",
|
|
995
|
+
display: "flex",
|
|
996
|
+
gap: "2px"
|
|
997
|
+
});
|
|
998
|
+
controls.appendChild(createActionButton({
|
|
999
|
+
label: "+",
|
|
1000
|
+
ariaLabel: arg.i18n("schemas.list.addItem"),
|
|
1001
|
+
onPressStart: preserveEditingForAction,
|
|
1002
|
+
onClick: () => {
|
|
1003
|
+
const nextItems = [...originalItems];
|
|
1004
|
+
nextItems.splice(range.start, 0, {
|
|
1005
|
+
level: 0,
|
|
1006
|
+
text: ""
|
|
1007
|
+
});
|
|
1008
|
+
commitItems(nextItems, range.start);
|
|
1009
|
+
}
|
|
1010
|
+
}));
|
|
1011
|
+
rootElement.appendChild(controls);
|
|
1012
|
+
};
|
|
1013
|
+
let offsetY = 0;
|
|
1014
|
+
for (let index = 0; index < layout.items.length; index += 1) {
|
|
1015
|
+
const item = layout.items[index];
|
|
1016
|
+
const row = document.createElement("div");
|
|
1017
|
+
setStyles(row, {
|
|
1018
|
+
position: "absolute",
|
|
1019
|
+
top: `${offsetY}mm`,
|
|
1020
|
+
left: "0mm",
|
|
1021
|
+
width: `${schema.width}mm`,
|
|
1022
|
+
height: `${item.height}mm`
|
|
1023
|
+
});
|
|
1024
|
+
const marker = document.createElement("div");
|
|
1025
|
+
setStyles(marker, {
|
|
1026
|
+
position: "absolute",
|
|
1027
|
+
top: "0mm",
|
|
1028
|
+
left: `${item.markerX}mm`,
|
|
1029
|
+
width: `${layout.markerWidth}mm`,
|
|
1030
|
+
height: "100%",
|
|
1031
|
+
backgroundColor: "transparent",
|
|
1032
|
+
cursor: "default"
|
|
1033
|
+
});
|
|
1034
|
+
const body = document.createElement("div");
|
|
1035
|
+
setStyles(body, {
|
|
1036
|
+
position: "absolute",
|
|
1037
|
+
top: "0mm",
|
|
1038
|
+
left: `${item.bodyX}mm`,
|
|
1039
|
+
width: `${item.bodyWidth}mm`,
|
|
1040
|
+
height: `${item.height}mm`,
|
|
1041
|
+
backgroundColor: "transparent",
|
|
1042
|
+
cursor: editable ? "text" : "default"
|
|
1043
|
+
});
|
|
1044
|
+
const schemaForUI = schema;
|
|
1045
|
+
const textSchema = {
|
|
1046
|
+
...schema,
|
|
1047
|
+
id: `${schemaForUI.id || schema.name}-list-item-${item.itemIndex}`,
|
|
1048
|
+
name: `${schema.name}-list-item-${item.itemIndex}`,
|
|
1049
|
+
type: "text",
|
|
1050
|
+
content: item.item,
|
|
1051
|
+
position: {
|
|
1052
|
+
x: 0,
|
|
1053
|
+
y: 0
|
|
1054
|
+
},
|
|
1055
|
+
width: item.bodyWidth,
|
|
1056
|
+
height: item.height,
|
|
1057
|
+
alignment: schema.alignment ?? "left",
|
|
1058
|
+
fontSize: schema.fontSize ?? 13,
|
|
1059
|
+
lineHeight: schema.lineHeight ?? 1,
|
|
1060
|
+
characterSpacing: schema.characterSpacing ?? 0,
|
|
1061
|
+
fontColor: usePlaceholder ? PLACEHOLDER_FONT_COLOR : schema.fontColor || "#000000",
|
|
1062
|
+
backgroundColor: ""
|
|
1063
|
+
};
|
|
1064
|
+
const markerTextSchema = {
|
|
1065
|
+
...textSchema,
|
|
1066
|
+
id: `${schemaForUI.id || schema.name}-list-marker-${item.itemIndex}`,
|
|
1067
|
+
name: `${schema.name}-list-marker-${item.itemIndex}`,
|
|
1068
|
+
content: item.marker,
|
|
1069
|
+
width: layout.markerWidth,
|
|
1070
|
+
height: item.height,
|
|
1071
|
+
alignment: "right",
|
|
1072
|
+
fontColor: schema.fontColor || "#000000"
|
|
1073
|
+
};
|
|
1074
|
+
await uiRender$4({
|
|
1075
|
+
...arg,
|
|
1076
|
+
rootElement: marker,
|
|
1077
|
+
schema: markerTextSchema,
|
|
1078
|
+
value: item.marker,
|
|
1079
|
+
mode: "viewer",
|
|
1080
|
+
placeholder: "",
|
|
1081
|
+
onChange: void 0,
|
|
1082
|
+
stopEditing: void 0
|
|
1083
|
+
});
|
|
1084
|
+
await uiRender$4({
|
|
1085
|
+
...arg,
|
|
1086
|
+
rootElement: body,
|
|
1087
|
+
schema: textSchema,
|
|
1088
|
+
value: item.item,
|
|
1089
|
+
placeholder: "",
|
|
1090
|
+
onChange: void 0,
|
|
1091
|
+
stopEditing: void 0
|
|
1092
|
+
});
|
|
1093
|
+
if (editable) {
|
|
1094
|
+
const editor = getBodyEditor(body);
|
|
1095
|
+
if (!editor) throw new Error("Unable to find list item text editor");
|
|
1096
|
+
editor.tabIndex = tabIndex || 0;
|
|
1097
|
+
body.addEventListener("pointerdown", handleInternalFocusPointer);
|
|
1098
|
+
body.addEventListener("mousedown", (event) => {
|
|
1099
|
+
handleBodyMouseDown(editor, event);
|
|
1100
|
+
});
|
|
1101
|
+
body.addEventListener("click", (event) => {
|
|
1102
|
+
event.stopPropagation();
|
|
1103
|
+
focusBodyFromMouseEvent(editor, event);
|
|
1104
|
+
});
|
|
1105
|
+
editor.addEventListener("focus", () => {
|
|
1106
|
+
if (usePlaceholder) {
|
|
1107
|
+
editor.innerText = "";
|
|
1108
|
+
editor.style.color = schema.fontColor || "#000000";
|
|
1109
|
+
}
|
|
1110
|
+
});
|
|
1111
|
+
body.addEventListener("blur", (event) => {
|
|
1112
|
+
const isListAction = rootElement.dataset[actionDataKey] === "true";
|
|
1113
|
+
const relatedTarget = event.relatedTarget;
|
|
1114
|
+
const isInternalFocus = rootElement.dataset[internalFocusDataKey] === "true" || relatedTarget instanceof Node && rootElement.contains(relatedTarget);
|
|
1115
|
+
delete rootElement.dataset[internalFocusDataKey];
|
|
1116
|
+
if (isListAction || isInternalFocus) return;
|
|
1117
|
+
if (!onChange) return;
|
|
1118
|
+
commitItems(getNextItems());
|
|
1119
|
+
if (stopEditing) stopEditing();
|
|
1120
|
+
}, true);
|
|
1121
|
+
editor.addEventListener("keydown", (event) => {
|
|
1122
|
+
if (event.key === "Enter") {
|
|
1123
|
+
if (isComposingKeyboardEvent(event)) return;
|
|
1124
|
+
event.preventDefault();
|
|
1125
|
+
if (insertLineBreakAtSelection(editor)) {
|
|
1126
|
+
preserveEditingForKeyboardCommit();
|
|
1127
|
+
if (mode === "form") commitHeight(range.start + index);
|
|
1128
|
+
else commitItems(getNextItems(), range.start + index);
|
|
1129
|
+
}
|
|
1130
|
+
} else if (event.key === "Tab") {
|
|
1131
|
+
event.preventDefault();
|
|
1132
|
+
updateItems(index, (nextItems, itemIndex) => {
|
|
1133
|
+
const itemToUpdate = nextItems[itemIndex];
|
|
1134
|
+
itemToUpdate.level = event.shiftKey ? Math.max(itemToUpdate.level - 1, 0) : Math.min(itemToUpdate.level + 1, 8);
|
|
1135
|
+
return itemIndex;
|
|
1136
|
+
});
|
|
1137
|
+
} else if (event.key === "Backspace" && getText(editor) === "") {
|
|
1138
|
+
event.preventDefault();
|
|
1139
|
+
updateItems(index, (nextItems, itemIndex) => {
|
|
1140
|
+
if (nextItems.length <= 1) {
|
|
1141
|
+
nextItems.splice(0);
|
|
1142
|
+
return;
|
|
1143
|
+
}
|
|
1144
|
+
nextItems.splice(itemIndex, 1);
|
|
1145
|
+
return Math.min(itemIndex, nextItems.length - 1);
|
|
1146
|
+
});
|
|
1147
|
+
}
|
|
1148
|
+
});
|
|
1149
|
+
bodyElements.push(editor);
|
|
1150
|
+
}
|
|
1151
|
+
row.appendChild(marker);
|
|
1152
|
+
row.appendChild(body);
|
|
1153
|
+
if (showControls) {
|
|
1154
|
+
const controls = document.createElement("div");
|
|
1155
|
+
controls.addEventListener("pointerdown", preserveEditingForAction);
|
|
1156
|
+
controls.addEventListener("mousedown", preserveEditingForAction);
|
|
1157
|
+
setStyles(controls, {
|
|
1158
|
+
position: "absolute",
|
|
1159
|
+
top: "0mm",
|
|
1160
|
+
right: "-82px",
|
|
1161
|
+
display: "flex",
|
|
1162
|
+
gap: "2px"
|
|
1163
|
+
});
|
|
1164
|
+
controls.appendChild(createActionButton({
|
|
1165
|
+
label: "+",
|
|
1166
|
+
ariaLabel: arg.i18n("schemas.list.addItem"),
|
|
1167
|
+
onPressStart: preserveEditingForAction,
|
|
1168
|
+
onClick: () => {
|
|
1169
|
+
updateItems(index, (nextItems, itemIndex) => {
|
|
1170
|
+
nextItems.splice(itemIndex + 1, 0, {
|
|
1171
|
+
level: nextItems[itemIndex]?.level ?? 0,
|
|
1172
|
+
text: ""
|
|
1173
|
+
});
|
|
1174
|
+
return itemIndex + 1;
|
|
1175
|
+
});
|
|
1176
|
+
}
|
|
1177
|
+
}));
|
|
1178
|
+
controls.appendChild(createActionButton({
|
|
1179
|
+
label: "-",
|
|
1180
|
+
ariaLabel: arg.i18n("schemas.list.removeItem"),
|
|
1181
|
+
onPressStart: preserveEditingForAction,
|
|
1182
|
+
onClick: () => {
|
|
1183
|
+
updateItems(index, (nextItems, itemIndex) => {
|
|
1184
|
+
if (nextItems.length <= 1) {
|
|
1185
|
+
nextItems.splice(0);
|
|
1186
|
+
return;
|
|
1187
|
+
}
|
|
1188
|
+
nextItems.splice(itemIndex, 1);
|
|
1189
|
+
return Math.min(itemIndex, nextItems.length - 1);
|
|
1190
|
+
});
|
|
1191
|
+
}
|
|
1192
|
+
}));
|
|
1193
|
+
controls.appendChild(createActionButton({
|
|
1194
|
+
label: "<",
|
|
1195
|
+
ariaLabel: arg.i18n("schemas.list.outdentItem"),
|
|
1196
|
+
disabled: item.level === 0,
|
|
1197
|
+
onPressStart: preserveEditingForAction,
|
|
1198
|
+
onClick: () => {
|
|
1199
|
+
updateItems(index, (nextItems, itemIndex) => {
|
|
1200
|
+
nextItems[itemIndex].level = Math.max(nextItems[itemIndex].level - 1, 0);
|
|
1201
|
+
return itemIndex;
|
|
1202
|
+
});
|
|
1203
|
+
}
|
|
1204
|
+
}));
|
|
1205
|
+
controls.appendChild(createActionButton({
|
|
1206
|
+
label: ">",
|
|
1207
|
+
ariaLabel: arg.i18n("schemas.list.indentItem"),
|
|
1208
|
+
disabled: item.level >= 8,
|
|
1209
|
+
onPressStart: preserveEditingForAction,
|
|
1210
|
+
onClick: () => {
|
|
1211
|
+
updateItems(index, (nextItems, itemIndex) => {
|
|
1212
|
+
nextItems[itemIndex].level = Math.min(nextItems[itemIndex].level + 1, 8);
|
|
1213
|
+
return itemIndex;
|
|
1214
|
+
});
|
|
1215
|
+
}
|
|
1216
|
+
}));
|
|
1217
|
+
row.appendChild(controls);
|
|
1218
|
+
}
|
|
1219
|
+
rootElement.appendChild(row);
|
|
1220
|
+
offsetY += item.height;
|
|
1221
|
+
}
|
|
1222
|
+
if (showControls && visibleItems.length === 0) appendEmptyListControls();
|
|
1223
|
+
const pendingFocusIndex = pendingFocusIndexes.get(focusKey);
|
|
1224
|
+
if (pendingFocusIndex !== void 0) pendingFocusIndexes.delete(focusKey);
|
|
1225
|
+
const requestedFocusIndex = Number(rootElement.dataset[focusDataKey] ?? pendingFocusIndex);
|
|
1226
|
+
delete rootElement.dataset[focusDataKey];
|
|
1227
|
+
delete rootElement.dataset[actionDataKey];
|
|
1228
|
+
delete rootElement.dataset[internalFocusDataKey];
|
|
1229
|
+
const relativeFocusIndex = requestedFocusIndex - range.start;
|
|
1230
|
+
if (editable && Number.isFinite(requestedFocusIndex) && bodyElements[relativeFocusIndex]) setTimeout(() => focusBody(bodyElements[relativeFocusIndex]));
|
|
1231
|
+
else if (editable && mode === "designer" && bodyElements[0]) setTimeout(() => {
|
|
1232
|
+
if (!rootElement.contains(document.activeElement)) focusBody(bodyElements[0]);
|
|
1233
|
+
});
|
|
1234
|
+
if (schema.height !== layout.totalHeight && onChange) onChange({
|
|
1235
|
+
key: "height",
|
|
1236
|
+
value: layout.totalHeight
|
|
1237
|
+
});
|
|
1238
|
+
};
|
|
1239
|
+
//#endregion
|
|
1240
|
+
//#region src/list/index.ts
|
|
1241
|
+
var listSchema = {
|
|
473
1242
|
pdf: pdfRender$2,
|
|
474
1243
|
ui: uiRender$2,
|
|
475
1244
|
propPanel: propPanel$1,
|
|
476
|
-
icon: createSvgStr(
|
|
477
|
-
uninterruptedEditMode: true
|
|
1245
|
+
icon: createSvgStr(List)
|
|
478
1246
|
};
|
|
479
1247
|
//#endregion
|
|
480
1248
|
//#region src/graphics/imagehelper.ts
|
|
@@ -1534,144 +2302,6 @@ var lineSchema = {
|
|
|
1534
2302
|
icon: createSvgStr(Minus)
|
|
1535
2303
|
};
|
|
1536
2304
|
//#endregion
|
|
1537
|
-
//#region src/shapes/rectAndEllipse.ts
|
|
1538
|
-
var shape = {
|
|
1539
|
-
ui: (arg) => {
|
|
1540
|
-
const { schema, rootElement } = arg;
|
|
1541
|
-
const div = document.createElement("div");
|
|
1542
|
-
div.style.width = "100%";
|
|
1543
|
-
div.style.height = "100%";
|
|
1544
|
-
div.style.boxSizing = "border-box";
|
|
1545
|
-
if (schema.type === "ellipse") div.style.borderRadius = "50%";
|
|
1546
|
-
else if (schema.radius && schema.radius > 0) div.style.borderRadius = `${schema.radius}mm`;
|
|
1547
|
-
div.style.borderWidth = `${schema.borderWidth ?? 0}mm`;
|
|
1548
|
-
div.style.borderStyle = schema.borderWidth && schema.borderColor ? "solid" : "none";
|
|
1549
|
-
div.style.borderColor = schema.borderColor ?? "transparent";
|
|
1550
|
-
div.style.backgroundColor = schema.color ?? "transparent";
|
|
1551
|
-
rootElement.appendChild(div);
|
|
1552
|
-
},
|
|
1553
|
-
pdf: (arg) => {
|
|
1554
|
-
const { schema, page, options } = arg;
|
|
1555
|
-
if (!schema.color && !schema.borderColor) return;
|
|
1556
|
-
const { colorType } = options;
|
|
1557
|
-
const cArg = {
|
|
1558
|
-
schema,
|
|
1559
|
-
pageHeight: page.getHeight()
|
|
1560
|
-
};
|
|
1561
|
-
const { position, width, height, rotate, opacity } = convertForPdfLayoutProps(cArg);
|
|
1562
|
-
const { position: { x: x4Ellipse, y: y4Ellipse } } = convertForPdfLayoutProps({
|
|
1563
|
-
...cArg,
|
|
1564
|
-
applyRotateTranslate: false
|
|
1565
|
-
});
|
|
1566
|
-
const borderWidth = schema.borderWidth ? mm2pt(schema.borderWidth) : 0;
|
|
1567
|
-
const drawOptions = {
|
|
1568
|
-
rotate,
|
|
1569
|
-
borderWidth,
|
|
1570
|
-
borderColor: hex2PrintingColor(schema.borderColor, colorType),
|
|
1571
|
-
color: hex2PrintingColor(schema.color, colorType),
|
|
1572
|
-
opacity,
|
|
1573
|
-
borderOpacity: opacity
|
|
1574
|
-
};
|
|
1575
|
-
if (schema.type === "ellipse") page.drawEllipse({
|
|
1576
|
-
x: x4Ellipse + width / 2,
|
|
1577
|
-
y: y4Ellipse + height / 2,
|
|
1578
|
-
xScale: width / 2 - borderWidth / 2,
|
|
1579
|
-
yScale: height / 2 - borderWidth / 2,
|
|
1580
|
-
...drawOptions
|
|
1581
|
-
});
|
|
1582
|
-
else if (schema.type === "rectangle") {
|
|
1583
|
-
const radius = schema.radius ?? 0;
|
|
1584
|
-
page.drawRectangle({
|
|
1585
|
-
x: position.x + borderWidth * ((1 - Math.sin(toRadians(rotate))) / 2) + Math.tan(toRadians(rotate)) * Math.PI ** 2,
|
|
1586
|
-
y: position.y + borderWidth * ((1 + Math.sin(toRadians(rotate))) / 2) + Math.tan(toRadians(rotate)) * Math.PI ** 2,
|
|
1587
|
-
width: width - borderWidth,
|
|
1588
|
-
height: height - borderWidth,
|
|
1589
|
-
...radius ? { radius: mm2pt(radius) } : {},
|
|
1590
|
-
...drawOptions
|
|
1591
|
-
});
|
|
1592
|
-
}
|
|
1593
|
-
},
|
|
1594
|
-
propPanel: {
|
|
1595
|
-
schema: ({ i18n }) => ({
|
|
1596
|
-
borderWidth: {
|
|
1597
|
-
title: i18n("schemas.borderWidth"),
|
|
1598
|
-
type: "number",
|
|
1599
|
-
widget: "inputNumber",
|
|
1600
|
-
props: {
|
|
1601
|
-
min: 0,
|
|
1602
|
-
step: 1
|
|
1603
|
-
},
|
|
1604
|
-
span: 12
|
|
1605
|
-
},
|
|
1606
|
-
borderColor: {
|
|
1607
|
-
title: i18n("schemas.borderColor"),
|
|
1608
|
-
type: "string",
|
|
1609
|
-
widget: "color",
|
|
1610
|
-
props: { disabledAlpha: true },
|
|
1611
|
-
rules: [{
|
|
1612
|
-
pattern: HEX_COLOR_PATTERN,
|
|
1613
|
-
message: i18n("validation.hexColor")
|
|
1614
|
-
}],
|
|
1615
|
-
span: 12
|
|
1616
|
-
},
|
|
1617
|
-
color: {
|
|
1618
|
-
title: i18n("schemas.color"),
|
|
1619
|
-
type: "string",
|
|
1620
|
-
widget: "color",
|
|
1621
|
-
props: { disabledAlpha: true },
|
|
1622
|
-
rules: [{
|
|
1623
|
-
pattern: HEX_COLOR_PATTERN,
|
|
1624
|
-
message: i18n("validation.hexColor")
|
|
1625
|
-
}]
|
|
1626
|
-
},
|
|
1627
|
-
radius: {
|
|
1628
|
-
title: i18n("schemas.radius"),
|
|
1629
|
-
type: "number",
|
|
1630
|
-
widget: "inputNumber",
|
|
1631
|
-
props: {
|
|
1632
|
-
min: 0,
|
|
1633
|
-
step: 1
|
|
1634
|
-
},
|
|
1635
|
-
span: 12
|
|
1636
|
-
}
|
|
1637
|
-
}),
|
|
1638
|
-
defaultSchema: {
|
|
1639
|
-
name: "",
|
|
1640
|
-
type: "rectangle",
|
|
1641
|
-
position: {
|
|
1642
|
-
x: 0,
|
|
1643
|
-
y: 0
|
|
1644
|
-
},
|
|
1645
|
-
width: 62.5,
|
|
1646
|
-
height: 37.5,
|
|
1647
|
-
rotate: 0,
|
|
1648
|
-
opacity: 1,
|
|
1649
|
-
borderWidth: 1,
|
|
1650
|
-
borderColor: "#000000",
|
|
1651
|
-
color: "",
|
|
1652
|
-
readOnly: true,
|
|
1653
|
-
radius: 0
|
|
1654
|
-
}
|
|
1655
|
-
}
|
|
1656
|
-
};
|
|
1657
|
-
var getPropPanelSchema = (type) => ({
|
|
1658
|
-
...shape.propPanel,
|
|
1659
|
-
defaultSchema: {
|
|
1660
|
-
...shape.propPanel.defaultSchema,
|
|
1661
|
-
type
|
|
1662
|
-
}
|
|
1663
|
-
});
|
|
1664
|
-
var rectangle = {
|
|
1665
|
-
...shape,
|
|
1666
|
-
propPanel: getPropPanelSchema("rectangle"),
|
|
1667
|
-
icon: createSvgStr(Square)
|
|
1668
|
-
};
|
|
1669
|
-
var ellipse = {
|
|
1670
|
-
...shape,
|
|
1671
|
-
propPanel: getPropPanelSchema("ellipse"),
|
|
1672
|
-
icon: createSvgStr(Circle)
|
|
1673
|
-
};
|
|
1674
|
-
//#endregion
|
|
1675
2305
|
//#region src/tables/cell.ts
|
|
1676
2306
|
var linePdfRender = lineSchema.pdf;
|
|
1677
2307
|
var rectanglePdfRender$1 = rectangle.pdf;
|
|
@@ -1743,7 +2373,7 @@ var cellSchema = {
|
|
|
1743
2373
|
y: position.y
|
|
1744
2374
|
}, borderWidth.left, height)
|
|
1745
2375
|
]);
|
|
1746
|
-
await pdfRender$
|
|
2376
|
+
await pdfRender$4({
|
|
1747
2377
|
...arg,
|
|
1748
2378
|
schema: {
|
|
1749
2379
|
...schema,
|
|
@@ -1763,7 +2393,7 @@ var cellSchema = {
|
|
|
1763
2393
|
const { borderWidth, width, height, borderColor, backgroundColor } = schema;
|
|
1764
2394
|
rootElement.style.backgroundColor = backgroundColor;
|
|
1765
2395
|
const textDiv = createTextDiv(schema);
|
|
1766
|
-
await uiRender$
|
|
2396
|
+
await uiRender$4({
|
|
1767
2397
|
...arg,
|
|
1768
2398
|
schema: {
|
|
1769
2399
|
...schema,
|
|
@@ -1898,17 +2528,38 @@ var pdfRender = async (arg) => {
|
|
|
1898
2528
|
};
|
|
1899
2529
|
//#endregion
|
|
1900
2530
|
//#region src/tables/uiRender.ts
|
|
1901
|
-
var buttonSize =
|
|
2531
|
+
var buttonSize = 18;
|
|
1902
2532
|
function createButton(options) {
|
|
1903
2533
|
const button = document.createElement("button");
|
|
2534
|
+
button.type = "button";
|
|
2535
|
+
button.innerText = options.text;
|
|
2536
|
+
if (options.ariaLabel) button.setAttribute("aria-label", options.ariaLabel);
|
|
1904
2537
|
button.style.width = `${options.width}px`;
|
|
1905
2538
|
button.style.height = `${options.height}px`;
|
|
1906
2539
|
button.style.position = "absolute";
|
|
1907
2540
|
button.style.top = options.top;
|
|
2541
|
+
button.style.display = "inline-flex";
|
|
2542
|
+
button.style.alignItems = "center";
|
|
2543
|
+
button.style.justifyContent = "center";
|
|
2544
|
+
button.style.padding = "0";
|
|
2545
|
+
button.style.border = "1px solid #d9d9d9";
|
|
2546
|
+
button.style.borderRadius = "3px";
|
|
2547
|
+
button.style.background = "#ffffff";
|
|
2548
|
+
button.style.color = "#333333";
|
|
2549
|
+
button.style.fontSize = "11px";
|
|
2550
|
+
button.style.lineHeight = "1";
|
|
2551
|
+
button.style.cursor = "pointer";
|
|
2552
|
+
button.style.zIndex = "20";
|
|
1908
2553
|
if (options.left !== void 0) button.style.left = options.left;
|
|
1909
2554
|
if (options.right !== void 0) button.style.right = options.right;
|
|
1910
|
-
button.
|
|
1911
|
-
|
|
2555
|
+
button.addEventListener("mousedown", (event) => {
|
|
2556
|
+
event.preventDefault();
|
|
2557
|
+
});
|
|
2558
|
+
button.addEventListener("click", (event) => {
|
|
2559
|
+
event.preventDefault();
|
|
2560
|
+
event.stopPropagation();
|
|
2561
|
+
options.onClick(event);
|
|
2562
|
+
});
|
|
1912
2563
|
return button;
|
|
1913
2564
|
}
|
|
1914
2565
|
var cellUiRender = cellSchema.ui;
|
|
@@ -2078,6 +2729,7 @@ var uiRender = async (arg) => {
|
|
|
2078
2729
|
top: `${table.getHeight()}mm`,
|
|
2079
2730
|
left: `calc(50% - ${buttonSize / 2}px)`,
|
|
2080
2731
|
text: "+",
|
|
2732
|
+
ariaLabel: "Add row",
|
|
2081
2733
|
onClick: () => {
|
|
2082
2734
|
const newRow = Array(schema.head.length).fill("");
|
|
2083
2735
|
if (onChange) onChange({
|
|
@@ -2096,6 +2748,7 @@ var uiRender = async (arg) => {
|
|
|
2096
2748
|
top: `${offsetY - px2mm(buttonSize)}mm`,
|
|
2097
2749
|
right: `-${buttonSize}px`,
|
|
2098
2750
|
text: "-",
|
|
2751
|
+
ariaLabel: "Remove row",
|
|
2099
2752
|
onClick: () => {
|
|
2100
2753
|
const newTableBody = body.filter((_, j) => j !== i + (schema.__bodyRange?.start ?? 0));
|
|
2101
2754
|
if (onChange) onChange({
|
|
@@ -2117,6 +2770,7 @@ var uiRender = async (arg) => {
|
|
|
2117
2770
|
top: `${(showHead ? table.getHeadHeight() : 0) - px2mm(buttonSize)}mm`,
|
|
2118
2771
|
right: `-${buttonSize}px`,
|
|
2119
2772
|
text: "+",
|
|
2773
|
+
ariaLabel: "Add column",
|
|
2120
2774
|
onClick: (e) => {
|
|
2121
2775
|
e.preventDefault();
|
|
2122
2776
|
const newColumnWidthPercentage = 25;
|
|
@@ -2152,6 +2806,7 @@ var uiRender = async (arg) => {
|
|
|
2152
2806
|
top: `${-buttonSize}px`,
|
|
2153
2807
|
left: `${offsetX - px2mm(buttonSize)}mm`,
|
|
2154
2808
|
text: "-",
|
|
2809
|
+
ariaLabel: "Remove column",
|
|
2155
2810
|
onClick: () => {
|
|
2156
2811
|
const totalWidthMinusRemoved = schema.headWidthPercentages.reduce((sum, width, j) => j !== i ? sum + width : sum, 0);
|
|
2157
2812
|
onChange([
|
|
@@ -5318,13 +5973,13 @@ var schema$3 = {
|
|
|
5318
5973
|
propPanel: {
|
|
5319
5974
|
...textSchema.propPanel,
|
|
5320
5975
|
widgets: {
|
|
5321
|
-
...propPanel$
|
|
5976
|
+
...propPanel$3.widgets,
|
|
5322
5977
|
addOptions
|
|
5323
5978
|
},
|
|
5324
5979
|
schema: (propPanelProps) => {
|
|
5325
|
-
if (typeof propPanel$
|
|
5980
|
+
if (typeof propPanel$3.schema !== "function") throw Error("Oops, is text schema no longer a function?");
|
|
5326
5981
|
return {
|
|
5327
|
-
...propPanel$
|
|
5982
|
+
...propPanel$3.schema(propPanelProps),
|
|
5328
5983
|
"-------": {
|
|
5329
5984
|
type: "void",
|
|
5330
5985
|
widget: "Divider"
|
|
@@ -5506,6 +6161,6 @@ var schema = {
|
|
|
5506
6161
|
icon: getCheckedIcon()
|
|
5507
6162
|
};
|
|
5508
6163
|
//#endregion
|
|
5509
|
-
export { barcodes, builtInPlugins, schema as checkbox, date_default as date, dateTime_default as dateTime, ellipse, getDynamicHeightsForTable, imageSchema as image, lineSchema as line, schema$1 as multiVariableText, schema$2 as radioGroup, rectangle, schema$3 as select, signature, svgSchema as svg, tableSchema as table, textSchema as text, time_default as time };
|
|
6164
|
+
export { barcodes, builtInPlugins, schema as checkbox, date_default as date, dateTime_default as dateTime, ellipse, getDynamicHeightsForTable, getDynamicLayoutForList, getDynamicLayoutForTable, imageSchema as image, lineSchema as line, listSchema as list, schema$1 as multiVariableText, schema$2 as radioGroup, rectangle, schema$3 as select, signature, svgSchema as svg, tableSchema as table, textSchema as text, time_default as time };
|
|
5510
6165
|
|
|
5511
6166
|
//# sourceMappingURL=index.js.map
|