@pdfme/schemas 6.1.0 → 6.1.1-dev.4
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-CFqn6U5J.js} +58 -25
- package/dist/builtins-CFqn6U5J.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 +814 -161
- 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/richTextPdfRender.d.ts +1 -1
- 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-CFqn6U5J.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,
|
|
@@ -470,11 +472,775 @@ var keyPressShouldBeChecked = (event) => {
|
|
|
470
472
|
//#endregion
|
|
471
473
|
//#region src/multiVariableText/index.ts
|
|
472
474
|
var schema$1 = {
|
|
475
|
+
pdf: pdfRender$3,
|
|
476
|
+
ui: uiRender$3,
|
|
477
|
+
propPanel: propPanel$2,
|
|
478
|
+
icon: createSvgStr(Type),
|
|
479
|
+
uninterruptedEditMode: true
|
|
480
|
+
};
|
|
481
|
+
//#endregion
|
|
482
|
+
//#region src/shapes/rectAndEllipse.ts
|
|
483
|
+
var shape = {
|
|
484
|
+
ui: (arg) => {
|
|
485
|
+
const { schema, rootElement } = arg;
|
|
486
|
+
const div = document.createElement("div");
|
|
487
|
+
div.style.width = "100%";
|
|
488
|
+
div.style.height = "100%";
|
|
489
|
+
div.style.boxSizing = "border-box";
|
|
490
|
+
if (schema.type === "ellipse") div.style.borderRadius = "50%";
|
|
491
|
+
else if (schema.radius && schema.radius > 0) div.style.borderRadius = `${schema.radius}mm`;
|
|
492
|
+
div.style.borderWidth = `${schema.borderWidth ?? 0}mm`;
|
|
493
|
+
div.style.borderStyle = schema.borderWidth && schema.borderColor ? "solid" : "none";
|
|
494
|
+
div.style.borderColor = schema.borderColor ?? "transparent";
|
|
495
|
+
div.style.backgroundColor = schema.color ?? "transparent";
|
|
496
|
+
rootElement.appendChild(div);
|
|
497
|
+
},
|
|
498
|
+
pdf: (arg) => {
|
|
499
|
+
const { schema, page, options } = arg;
|
|
500
|
+
if (!schema.color && !schema.borderColor) return;
|
|
501
|
+
const { colorType } = options;
|
|
502
|
+
const cArg = {
|
|
503
|
+
schema,
|
|
504
|
+
pageHeight: page.getHeight()
|
|
505
|
+
};
|
|
506
|
+
const { position, width, height, rotate, opacity } = convertForPdfLayoutProps(cArg);
|
|
507
|
+
const { position: { x: x4Ellipse, y: y4Ellipse } } = convertForPdfLayoutProps({
|
|
508
|
+
...cArg,
|
|
509
|
+
applyRotateTranslate: false
|
|
510
|
+
});
|
|
511
|
+
const borderWidth = schema.borderWidth ? mm2pt(schema.borderWidth) : 0;
|
|
512
|
+
const drawOptions = {
|
|
513
|
+
rotate,
|
|
514
|
+
borderWidth,
|
|
515
|
+
borderColor: hex2PrintingColor(schema.borderColor, colorType),
|
|
516
|
+
color: hex2PrintingColor(schema.color, colorType),
|
|
517
|
+
opacity,
|
|
518
|
+
borderOpacity: opacity
|
|
519
|
+
};
|
|
520
|
+
if (schema.type === "ellipse") page.drawEllipse({
|
|
521
|
+
x: x4Ellipse + width / 2,
|
|
522
|
+
y: y4Ellipse + height / 2,
|
|
523
|
+
xScale: width / 2 - borderWidth / 2,
|
|
524
|
+
yScale: height / 2 - borderWidth / 2,
|
|
525
|
+
...drawOptions
|
|
526
|
+
});
|
|
527
|
+
else if (schema.type === "rectangle") {
|
|
528
|
+
const radius = schema.radius ?? 0;
|
|
529
|
+
page.drawRectangle({
|
|
530
|
+
x: position.x + borderWidth * ((1 - Math.sin(toRadians(rotate))) / 2) + Math.tan(toRadians(rotate)) * Math.PI ** 2,
|
|
531
|
+
y: position.y + borderWidth * ((1 + Math.sin(toRadians(rotate))) / 2) + Math.tan(toRadians(rotate)) * Math.PI ** 2,
|
|
532
|
+
width: width - borderWidth,
|
|
533
|
+
height: height - borderWidth,
|
|
534
|
+
...radius ? { radius: mm2pt(radius) } : {},
|
|
535
|
+
...drawOptions
|
|
536
|
+
});
|
|
537
|
+
}
|
|
538
|
+
},
|
|
539
|
+
propPanel: {
|
|
540
|
+
schema: ({ i18n }) => ({
|
|
541
|
+
borderWidth: {
|
|
542
|
+
title: i18n("schemas.borderWidth"),
|
|
543
|
+
type: "number",
|
|
544
|
+
widget: "inputNumber",
|
|
545
|
+
props: {
|
|
546
|
+
min: 0,
|
|
547
|
+
step: 1
|
|
548
|
+
},
|
|
549
|
+
span: 12
|
|
550
|
+
},
|
|
551
|
+
borderColor: {
|
|
552
|
+
title: i18n("schemas.borderColor"),
|
|
553
|
+
type: "string",
|
|
554
|
+
widget: "color",
|
|
555
|
+
props: { disabledAlpha: true },
|
|
556
|
+
rules: [{
|
|
557
|
+
pattern: HEX_COLOR_PATTERN,
|
|
558
|
+
message: i18n("validation.hexColor")
|
|
559
|
+
}],
|
|
560
|
+
span: 12
|
|
561
|
+
},
|
|
562
|
+
color: {
|
|
563
|
+
title: i18n("schemas.color"),
|
|
564
|
+
type: "string",
|
|
565
|
+
widget: "color",
|
|
566
|
+
props: { disabledAlpha: true },
|
|
567
|
+
rules: [{
|
|
568
|
+
pattern: HEX_COLOR_PATTERN,
|
|
569
|
+
message: i18n("validation.hexColor")
|
|
570
|
+
}]
|
|
571
|
+
},
|
|
572
|
+
radius: {
|
|
573
|
+
title: i18n("schemas.radius"),
|
|
574
|
+
type: "number",
|
|
575
|
+
widget: "inputNumber",
|
|
576
|
+
props: {
|
|
577
|
+
min: 0,
|
|
578
|
+
step: 1
|
|
579
|
+
},
|
|
580
|
+
span: 12
|
|
581
|
+
}
|
|
582
|
+
}),
|
|
583
|
+
defaultSchema: {
|
|
584
|
+
name: "",
|
|
585
|
+
type: "rectangle",
|
|
586
|
+
position: {
|
|
587
|
+
x: 0,
|
|
588
|
+
y: 0
|
|
589
|
+
},
|
|
590
|
+
width: 62.5,
|
|
591
|
+
height: 37.5,
|
|
592
|
+
rotate: 0,
|
|
593
|
+
opacity: 1,
|
|
594
|
+
borderWidth: 1,
|
|
595
|
+
borderColor: "#000000",
|
|
596
|
+
color: "",
|
|
597
|
+
readOnly: true,
|
|
598
|
+
radius: 0
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
};
|
|
602
|
+
var getPropPanelSchema = (type) => ({
|
|
603
|
+
...shape.propPanel,
|
|
604
|
+
defaultSchema: {
|
|
605
|
+
...shape.propPanel.defaultSchema,
|
|
606
|
+
type
|
|
607
|
+
}
|
|
608
|
+
});
|
|
609
|
+
var rectangle = {
|
|
610
|
+
...shape,
|
|
611
|
+
propPanel: getPropPanelSchema("rectangle"),
|
|
612
|
+
icon: createSvgStr(Square)
|
|
613
|
+
};
|
|
614
|
+
var ellipse = {
|
|
615
|
+
...shape,
|
|
616
|
+
propPanel: getPropPanelSchema("ellipse"),
|
|
617
|
+
icon: createSvgStr(Circle)
|
|
618
|
+
};
|
|
619
|
+
//#endregion
|
|
620
|
+
//#region src/list/pdfRender.ts
|
|
621
|
+
var rectanglePdfRender$2 = rectangle.pdf;
|
|
622
|
+
var pdfRender$2 = async (arg) => {
|
|
623
|
+
const { schema, value } = arg;
|
|
624
|
+
const items = normalizeListItems(value);
|
|
625
|
+
const range = schema.__itemRange ?? {
|
|
626
|
+
start: 0,
|
|
627
|
+
end: items.length
|
|
628
|
+
};
|
|
629
|
+
const visibleItems = items.slice(range.start, range.end);
|
|
630
|
+
if (visibleItems.length === 0) return;
|
|
631
|
+
const layout = await calculateListLayout({
|
|
632
|
+
schema,
|
|
633
|
+
items: visibleItems,
|
|
634
|
+
markerItems: items,
|
|
635
|
+
startIndex: range.start,
|
|
636
|
+
options: arg.options,
|
|
637
|
+
_cache: arg._cache
|
|
638
|
+
});
|
|
639
|
+
if (schema.backgroundColor) await rectanglePdfRender$2({
|
|
640
|
+
...arg,
|
|
641
|
+
schema: {
|
|
642
|
+
...schema,
|
|
643
|
+
type: "rectangle",
|
|
644
|
+
borderWidth: 0,
|
|
645
|
+
borderColor: "",
|
|
646
|
+
color: schema.backgroundColor
|
|
647
|
+
}
|
|
648
|
+
});
|
|
649
|
+
let y = schema.position.y;
|
|
650
|
+
for (const item of layout.items) {
|
|
651
|
+
await pdfRender$4({
|
|
652
|
+
...arg,
|
|
653
|
+
value: item.marker,
|
|
654
|
+
schema: {
|
|
655
|
+
...schema,
|
|
656
|
+
type: "text",
|
|
657
|
+
position: {
|
|
658
|
+
x: schema.position.x + item.markerX,
|
|
659
|
+
y
|
|
660
|
+
},
|
|
661
|
+
width: layout.markerWidth,
|
|
662
|
+
height: item.height,
|
|
663
|
+
backgroundColor: "",
|
|
664
|
+
alignment: "right",
|
|
665
|
+
verticalAlignment: "top",
|
|
666
|
+
dynamicFontSize: void 0
|
|
667
|
+
}
|
|
668
|
+
});
|
|
669
|
+
await pdfRender$4({
|
|
670
|
+
...arg,
|
|
671
|
+
value: item.item,
|
|
672
|
+
schema: {
|
|
673
|
+
...schema,
|
|
674
|
+
type: "text",
|
|
675
|
+
position: {
|
|
676
|
+
x: schema.position.x + item.bodyX,
|
|
677
|
+
y
|
|
678
|
+
},
|
|
679
|
+
width: item.bodyWidth,
|
|
680
|
+
height: item.height,
|
|
681
|
+
backgroundColor: "",
|
|
682
|
+
verticalAlignment: "top",
|
|
683
|
+
dynamicFontSize: void 0
|
|
684
|
+
}
|
|
685
|
+
});
|
|
686
|
+
y += item.height;
|
|
687
|
+
}
|
|
688
|
+
};
|
|
689
|
+
//#endregion
|
|
690
|
+
//#region src/list/propPanel.ts
|
|
691
|
+
var propPanel$1 = {
|
|
692
|
+
schema: (propPanelProps) => {
|
|
693
|
+
if (typeof propPanel$3.schema !== "function") throw new Error("Oops, is text schema no longer a function?");
|
|
694
|
+
const parentSchema = propPanel$3.schema(propPanelProps);
|
|
695
|
+
const i18n = propPanelProps.i18n;
|
|
696
|
+
const listSchema = { ...parentSchema };
|
|
697
|
+
delete listSchema.useDynamicFontSize;
|
|
698
|
+
delete listSchema.dynamicFontSize;
|
|
699
|
+
return {
|
|
700
|
+
...listSchema,
|
|
701
|
+
"-------": {
|
|
702
|
+
type: "void",
|
|
703
|
+
widget: "Divider"
|
|
704
|
+
},
|
|
705
|
+
listStyle: {
|
|
706
|
+
title: i18n("schemas.list.listStyle"),
|
|
707
|
+
type: "string",
|
|
708
|
+
widget: "select",
|
|
709
|
+
props: { options: [{
|
|
710
|
+
label: i18n("schemas.list.bullet"),
|
|
711
|
+
value: LIST_STYLE_BULLET
|
|
712
|
+
}, {
|
|
713
|
+
label: i18n("schemas.list.ordered"),
|
|
714
|
+
value: LIST_STYLE_ORDERED
|
|
715
|
+
}] },
|
|
716
|
+
span: 24
|
|
717
|
+
},
|
|
718
|
+
markerWidth: {
|
|
719
|
+
title: i18n("schemas.list.markerWidth"),
|
|
720
|
+
type: "number",
|
|
721
|
+
widget: "inputNumber",
|
|
722
|
+
props: { min: 0 },
|
|
723
|
+
span: 6
|
|
724
|
+
},
|
|
725
|
+
markerGap: {
|
|
726
|
+
title: i18n("schemas.list.markerGap"),
|
|
727
|
+
type: "number",
|
|
728
|
+
widget: "inputNumber",
|
|
729
|
+
props: { min: 0 },
|
|
730
|
+
span: 6
|
|
731
|
+
},
|
|
732
|
+
indentSize: {
|
|
733
|
+
title: i18n("schemas.list.indentSize"),
|
|
734
|
+
type: "number",
|
|
735
|
+
widget: "inputNumber",
|
|
736
|
+
props: { min: 0 },
|
|
737
|
+
span: 6
|
|
738
|
+
},
|
|
739
|
+
itemSpacing: {
|
|
740
|
+
title: i18n("schemas.list.itemSpacing"),
|
|
741
|
+
type: "number",
|
|
742
|
+
widget: "inputNumber",
|
|
743
|
+
props: { min: 0 },
|
|
744
|
+
span: 6
|
|
745
|
+
}
|
|
746
|
+
};
|
|
747
|
+
},
|
|
748
|
+
widgets: propPanel$3.widgets,
|
|
749
|
+
defaultSchema: {
|
|
750
|
+
...propPanel$3.defaultSchema,
|
|
751
|
+
type: "list",
|
|
752
|
+
content: JSON.stringify(["First item", "Second item"]),
|
|
753
|
+
width: 80,
|
|
754
|
+
height: 20,
|
|
755
|
+
listStyle: DEFAULT_LIST_STYLE,
|
|
756
|
+
markerWidth: 6,
|
|
757
|
+
markerGap: 2,
|
|
758
|
+
indentSize: 6,
|
|
759
|
+
itemSpacing: 1,
|
|
760
|
+
dynamicFontSize: void 0,
|
|
761
|
+
verticalAlignment: "top"
|
|
762
|
+
}
|
|
763
|
+
};
|
|
764
|
+
//#endregion
|
|
765
|
+
//#region src/list/uiRender.ts
|
|
766
|
+
var focusDataKey = "pdfmeListFocusIndex";
|
|
767
|
+
var actionDataKey = "pdfmeListAction";
|
|
768
|
+
var internalFocusDataKey = "pdfmeListInternalFocus";
|
|
769
|
+
var caretMarker = "";
|
|
770
|
+
var pendingFocusIndexes = /* @__PURE__ */ new Map();
|
|
771
|
+
var getListFocusKey = (schema) => schema.id || schema.name;
|
|
772
|
+
var isComposingKeyboardEvent = (event) => event.isComposing || event.keyCode === 229;
|
|
773
|
+
var getText = (element) => {
|
|
774
|
+
const rawText = element.innerText;
|
|
775
|
+
const hasCaretMarker = rawText.includes(caretMarker);
|
|
776
|
+
let text = rawText.replace(/\u200B/g, "");
|
|
777
|
+
if (!hasCaretMarker && text.endsWith("\n")) text = text.slice(0, -1);
|
|
778
|
+
return text;
|
|
779
|
+
};
|
|
780
|
+
var setStyles = (element, styles) => {
|
|
781
|
+
Object.assign(element.style, styles);
|
|
782
|
+
};
|
|
783
|
+
var focusBody = (body) => {
|
|
784
|
+
body.focus();
|
|
785
|
+
const selection = window.getSelection();
|
|
786
|
+
const range = document.createRange();
|
|
787
|
+
if (selection && range) {
|
|
788
|
+
range.selectNodeContents(body);
|
|
789
|
+
range.collapse(false);
|
|
790
|
+
selection.removeAllRanges();
|
|
791
|
+
selection.addRange(range);
|
|
792
|
+
}
|
|
793
|
+
};
|
|
794
|
+
var getCaretRangeFromPoint = (x, y) => {
|
|
795
|
+
const documentWithCaret = document;
|
|
796
|
+
if (documentWithCaret.caretRangeFromPoint) return documentWithCaret.caretRangeFromPoint(x, y);
|
|
797
|
+
const caretPosition = documentWithCaret.caretPositionFromPoint?.(x, y);
|
|
798
|
+
if (!caretPosition) return null;
|
|
799
|
+
const range = document.createRange();
|
|
800
|
+
range.setStart(caretPosition.offsetNode, caretPosition.offset);
|
|
801
|
+
range.collapse(true);
|
|
802
|
+
return range;
|
|
803
|
+
};
|
|
804
|
+
var focusBodyFromMouseEvent = (body, event) => {
|
|
805
|
+
body.focus();
|
|
806
|
+
const range = getCaretRangeFromPoint(event.clientX, event.clientY);
|
|
807
|
+
if (!range || !body.contains(range.startContainer)) return;
|
|
808
|
+
const selection = window.getSelection();
|
|
809
|
+
if (!selection) return;
|
|
810
|
+
selection.removeAllRanges();
|
|
811
|
+
selection.addRange(range);
|
|
812
|
+
};
|
|
813
|
+
var getBodyEditor = (body) => body.querySelector("[contenteditable], [tabindex]");
|
|
814
|
+
var insertLineBreakAtSelection = (element) => {
|
|
815
|
+
const fallbackText = getText(element);
|
|
816
|
+
const selection = window.getSelection();
|
|
817
|
+
if (!selection?.rangeCount) {
|
|
818
|
+
element.innerText = `${fallbackText}\n${caretMarker}`;
|
|
819
|
+
focusBody(element);
|
|
820
|
+
return true;
|
|
821
|
+
}
|
|
822
|
+
const range = selection.getRangeAt(0);
|
|
823
|
+
if (!element.contains(range.commonAncestorContainer)) {
|
|
824
|
+
element.innerText = `${fallbackText}\n${caretMarker}`;
|
|
825
|
+
focusBody(element);
|
|
826
|
+
return true;
|
|
827
|
+
}
|
|
828
|
+
selection.deleteFromDocument();
|
|
829
|
+
const fragment = document.createDocumentFragment();
|
|
830
|
+
const lineBreak = document.createElement("br");
|
|
831
|
+
const marker = document.createTextNode(caretMarker);
|
|
832
|
+
fragment.append(lineBreak, marker);
|
|
833
|
+
range.insertNode(fragment);
|
|
834
|
+
range.setStart(marker, marker.length);
|
|
835
|
+
range.collapse(true);
|
|
836
|
+
selection.removeAllRanges();
|
|
837
|
+
selection.addRange(range);
|
|
838
|
+
if (!element.innerText.includes(caretMarker)) {
|
|
839
|
+
element.innerText = `${fallbackText}\n${caretMarker}`;
|
|
840
|
+
focusBody(element);
|
|
841
|
+
}
|
|
842
|
+
return true;
|
|
843
|
+
};
|
|
844
|
+
var createActionButton = (arg) => {
|
|
845
|
+
const button = document.createElement("button");
|
|
846
|
+
button.type = "button";
|
|
847
|
+
button.innerText = arg.label;
|
|
848
|
+
button.setAttribute("aria-label", arg.ariaLabel);
|
|
849
|
+
button.disabled = Boolean(arg.disabled);
|
|
850
|
+
setStyles(button, {
|
|
851
|
+
width: "18px",
|
|
852
|
+
height: "18px",
|
|
853
|
+
display: "inline-flex",
|
|
854
|
+
alignItems: "center",
|
|
855
|
+
justifyContent: "center",
|
|
856
|
+
padding: "0",
|
|
857
|
+
border: "1px solid #d9d9d9",
|
|
858
|
+
borderRadius: "3px",
|
|
859
|
+
background: "#ffffff",
|
|
860
|
+
color: "#333333",
|
|
861
|
+
fontSize: "11px",
|
|
862
|
+
lineHeight: "1",
|
|
863
|
+
cursor: arg.disabled ? "not-allowed" : "pointer",
|
|
864
|
+
opacity: arg.disabled ? .45 : 1
|
|
865
|
+
});
|
|
866
|
+
button.addEventListener("pointerdown", (event) => {
|
|
867
|
+
arg.onPressStart?.();
|
|
868
|
+
event.stopPropagation();
|
|
869
|
+
});
|
|
870
|
+
button.addEventListener("mousedown", (event) => {
|
|
871
|
+
arg.onPressStart?.();
|
|
872
|
+
event.preventDefault();
|
|
873
|
+
event.stopPropagation();
|
|
874
|
+
});
|
|
875
|
+
button.addEventListener("click", (event) => {
|
|
876
|
+
event.preventDefault();
|
|
877
|
+
event.stopPropagation();
|
|
878
|
+
if (!arg.disabled) arg.onClick();
|
|
879
|
+
});
|
|
880
|
+
return button;
|
|
881
|
+
};
|
|
882
|
+
var uiRender$2 = async (arg) => {
|
|
883
|
+
const { rootElement, schema, value, mode, onChange, stopEditing, tabIndex, placeholder } = arg;
|
|
884
|
+
const focusKey = getListFocusKey(schema);
|
|
885
|
+
const editable = isEditable(mode, schema);
|
|
886
|
+
const showControls = editable && (mode === "form" || mode === "designer");
|
|
887
|
+
const usePlaceholder = editable && !value && Boolean(placeholder);
|
|
888
|
+
const items = normalizeListItems(usePlaceholder ? placeholder || "" : value);
|
|
889
|
+
const originalItems = normalizeListItemEntries(value);
|
|
890
|
+
const range = schema.__itemRange ?? {
|
|
891
|
+
start: 0,
|
|
892
|
+
end: items.length
|
|
893
|
+
};
|
|
894
|
+
const visibleItems = items.slice(range.start, range.end);
|
|
895
|
+
const renderItems = visibleItems;
|
|
896
|
+
rootElement.innerHTML = "";
|
|
897
|
+
setStyles(rootElement, {
|
|
898
|
+
position: "relative",
|
|
899
|
+
width: "100%",
|
|
900
|
+
height: "100%",
|
|
901
|
+
backgroundColor: schema.backgroundColor || "transparent",
|
|
902
|
+
overflow: "visible"
|
|
903
|
+
});
|
|
904
|
+
const layout = await calculateListLayout({
|
|
905
|
+
schema,
|
|
906
|
+
items: renderItems,
|
|
907
|
+
markerItems: items,
|
|
908
|
+
startIndex: range.start,
|
|
909
|
+
options: arg.options,
|
|
910
|
+
_cache: arg._cache
|
|
911
|
+
});
|
|
912
|
+
const bodyElements = [];
|
|
913
|
+
const getEditedItems = () => layout.items.map((item, index) => ({
|
|
914
|
+
level: item.level,
|
|
915
|
+
text: getText(bodyElements[index])
|
|
916
|
+
}));
|
|
917
|
+
const getNextItems = () => {
|
|
918
|
+
const editedItems = getEditedItems();
|
|
919
|
+
if (usePlaceholder) return editedItems;
|
|
920
|
+
const nextItems = [...originalItems];
|
|
921
|
+
nextItems.splice(range.start, visibleItems.length, ...editedItems);
|
|
922
|
+
return nextItems;
|
|
923
|
+
};
|
|
924
|
+
const commitItems = (nextItems, focusIndex) => {
|
|
925
|
+
if (!onChange) return;
|
|
926
|
+
if (focusIndex !== void 0) {
|
|
927
|
+
rootElement.dataset[focusDataKey] = String(focusIndex);
|
|
928
|
+
pendingFocusIndexes.set(focusKey, focusIndex);
|
|
929
|
+
}
|
|
930
|
+
onChange({
|
|
931
|
+
key: "content",
|
|
932
|
+
value: serializeListItems(nextItems)
|
|
933
|
+
});
|
|
934
|
+
};
|
|
935
|
+
const commitHeight = async (focusIndex) => {
|
|
936
|
+
if (!onChange) return;
|
|
937
|
+
if (focusIndex !== void 0) {
|
|
938
|
+
rootElement.dataset[focusDataKey] = String(focusIndex);
|
|
939
|
+
pendingFocusIndexes.set(focusKey, focusIndex);
|
|
940
|
+
}
|
|
941
|
+
const rawItems = normalizeListItems(serializeListItems(getNextItems()));
|
|
942
|
+
const nextLayout = await calculateListLayout({
|
|
943
|
+
schema,
|
|
944
|
+
items: rawItems.slice(range.start, range.end),
|
|
945
|
+
markerItems: rawItems,
|
|
946
|
+
startIndex: range.start,
|
|
947
|
+
options: arg.options,
|
|
948
|
+
_cache: arg._cache
|
|
949
|
+
});
|
|
950
|
+
if (schema.height !== nextLayout.totalHeight) onChange({
|
|
951
|
+
key: "height",
|
|
952
|
+
value: nextLayout.totalHeight
|
|
953
|
+
});
|
|
954
|
+
};
|
|
955
|
+
const preserveEditingForAction = () => {
|
|
956
|
+
rootElement.dataset[actionDataKey] = "true";
|
|
957
|
+
};
|
|
958
|
+
const updateItems = (rowIndex, mutate) => {
|
|
959
|
+
const nextItems = getNextItems();
|
|
960
|
+
if (nextItems.length === 0) nextItems.push({
|
|
961
|
+
level: 0,
|
|
962
|
+
text: ""
|
|
963
|
+
});
|
|
964
|
+
const focusIndex = mutate(nextItems, Math.min(Math.max(range.start + rowIndex, 0), nextItems.length - 1));
|
|
965
|
+
preserveEditingForAction();
|
|
966
|
+
commitItems(nextItems, focusIndex);
|
|
967
|
+
};
|
|
968
|
+
const preserveEditingForInternalFocus = () => {
|
|
969
|
+
rootElement.dataset[internalFocusDataKey] = "true";
|
|
970
|
+
};
|
|
971
|
+
const preserveEditingForKeyboardCommit = () => {
|
|
972
|
+
preserveEditingForInternalFocus();
|
|
973
|
+
setTimeout(() => {
|
|
974
|
+
if (rootElement.dataset[internalFocusDataKey] === "true") delete rootElement.dataset[internalFocusDataKey];
|
|
975
|
+
});
|
|
976
|
+
};
|
|
977
|
+
const handleInternalFocusPointer = (event) => {
|
|
978
|
+
preserveEditingForInternalFocus();
|
|
979
|
+
event.stopPropagation();
|
|
980
|
+
};
|
|
981
|
+
const handleBodyMouseDown = (body, event) => {
|
|
982
|
+
handleInternalFocusPointer(event);
|
|
983
|
+
focusBodyFromMouseEvent(body, event);
|
|
984
|
+
};
|
|
985
|
+
const appendEmptyListControls = () => {
|
|
986
|
+
const controls = document.createElement("div");
|
|
987
|
+
controls.addEventListener("pointerdown", preserveEditingForAction);
|
|
988
|
+
controls.addEventListener("mousedown", preserveEditingForAction);
|
|
989
|
+
setStyles(controls, {
|
|
990
|
+
position: "absolute",
|
|
991
|
+
top: "0mm",
|
|
992
|
+
right: "-20px",
|
|
993
|
+
display: "flex",
|
|
994
|
+
gap: "2px"
|
|
995
|
+
});
|
|
996
|
+
controls.appendChild(createActionButton({
|
|
997
|
+
label: "+",
|
|
998
|
+
ariaLabel: arg.i18n("schemas.list.addItem"),
|
|
999
|
+
onPressStart: preserveEditingForAction,
|
|
1000
|
+
onClick: () => {
|
|
1001
|
+
const nextItems = [...originalItems];
|
|
1002
|
+
nextItems.splice(range.start, 0, {
|
|
1003
|
+
level: 0,
|
|
1004
|
+
text: ""
|
|
1005
|
+
});
|
|
1006
|
+
commitItems(nextItems, range.start);
|
|
1007
|
+
}
|
|
1008
|
+
}));
|
|
1009
|
+
rootElement.appendChild(controls);
|
|
1010
|
+
};
|
|
1011
|
+
let offsetY = 0;
|
|
1012
|
+
for (let index = 0; index < layout.items.length; index += 1) {
|
|
1013
|
+
const item = layout.items[index];
|
|
1014
|
+
const row = document.createElement("div");
|
|
1015
|
+
setStyles(row, {
|
|
1016
|
+
position: "absolute",
|
|
1017
|
+
top: `${offsetY}mm`,
|
|
1018
|
+
left: "0mm",
|
|
1019
|
+
width: `${schema.width}mm`,
|
|
1020
|
+
height: `${item.height}mm`
|
|
1021
|
+
});
|
|
1022
|
+
const marker = document.createElement("div");
|
|
1023
|
+
setStyles(marker, {
|
|
1024
|
+
position: "absolute",
|
|
1025
|
+
top: "0mm",
|
|
1026
|
+
left: `${item.markerX}mm`,
|
|
1027
|
+
width: `${layout.markerWidth}mm`,
|
|
1028
|
+
height: "100%",
|
|
1029
|
+
backgroundColor: "transparent",
|
|
1030
|
+
cursor: "default"
|
|
1031
|
+
});
|
|
1032
|
+
const body = document.createElement("div");
|
|
1033
|
+
setStyles(body, {
|
|
1034
|
+
position: "absolute",
|
|
1035
|
+
top: "0mm",
|
|
1036
|
+
left: `${item.bodyX}mm`,
|
|
1037
|
+
width: `${item.bodyWidth}mm`,
|
|
1038
|
+
height: `${item.height}mm`,
|
|
1039
|
+
backgroundColor: "transparent",
|
|
1040
|
+
cursor: editable ? "text" : "default"
|
|
1041
|
+
});
|
|
1042
|
+
const schemaForUI = schema;
|
|
1043
|
+
const textSchema = {
|
|
1044
|
+
...schema,
|
|
1045
|
+
id: `${schemaForUI.id || schema.name}-list-item-${item.itemIndex}`,
|
|
1046
|
+
name: `${schema.name}-list-item-${item.itemIndex}`,
|
|
1047
|
+
type: "text",
|
|
1048
|
+
content: item.item,
|
|
1049
|
+
position: {
|
|
1050
|
+
x: 0,
|
|
1051
|
+
y: 0
|
|
1052
|
+
},
|
|
1053
|
+
width: item.bodyWidth,
|
|
1054
|
+
height: item.height,
|
|
1055
|
+
alignment: schema.alignment ?? "left",
|
|
1056
|
+
fontSize: schema.fontSize ?? 13,
|
|
1057
|
+
lineHeight: schema.lineHeight ?? 1,
|
|
1058
|
+
characterSpacing: schema.characterSpacing ?? 0,
|
|
1059
|
+
fontColor: usePlaceholder ? PLACEHOLDER_FONT_COLOR : schema.fontColor || "#000000",
|
|
1060
|
+
backgroundColor: ""
|
|
1061
|
+
};
|
|
1062
|
+
const markerTextSchema = {
|
|
1063
|
+
...textSchema,
|
|
1064
|
+
id: `${schemaForUI.id || schema.name}-list-marker-${item.itemIndex}`,
|
|
1065
|
+
name: `${schema.name}-list-marker-${item.itemIndex}`,
|
|
1066
|
+
content: item.marker,
|
|
1067
|
+
width: layout.markerWidth,
|
|
1068
|
+
height: item.height,
|
|
1069
|
+
alignment: "right",
|
|
1070
|
+
fontColor: schema.fontColor || "#000000"
|
|
1071
|
+
};
|
|
1072
|
+
await uiRender$4({
|
|
1073
|
+
...arg,
|
|
1074
|
+
rootElement: marker,
|
|
1075
|
+
schema: markerTextSchema,
|
|
1076
|
+
value: item.marker,
|
|
1077
|
+
mode: "viewer",
|
|
1078
|
+
placeholder: "",
|
|
1079
|
+
onChange: void 0,
|
|
1080
|
+
stopEditing: void 0
|
|
1081
|
+
});
|
|
1082
|
+
await uiRender$4({
|
|
1083
|
+
...arg,
|
|
1084
|
+
rootElement: body,
|
|
1085
|
+
schema: textSchema,
|
|
1086
|
+
value: item.item,
|
|
1087
|
+
placeholder: "",
|
|
1088
|
+
onChange: void 0,
|
|
1089
|
+
stopEditing: void 0
|
|
1090
|
+
});
|
|
1091
|
+
if (editable) {
|
|
1092
|
+
const editor = getBodyEditor(body);
|
|
1093
|
+
if (!editor) throw new Error("Unable to find list item text editor");
|
|
1094
|
+
editor.tabIndex = tabIndex || 0;
|
|
1095
|
+
body.addEventListener("pointerdown", handleInternalFocusPointer);
|
|
1096
|
+
body.addEventListener("mousedown", (event) => {
|
|
1097
|
+
handleBodyMouseDown(editor, event);
|
|
1098
|
+
});
|
|
1099
|
+
body.addEventListener("click", (event) => {
|
|
1100
|
+
event.stopPropagation();
|
|
1101
|
+
focusBodyFromMouseEvent(editor, event);
|
|
1102
|
+
});
|
|
1103
|
+
editor.addEventListener("focus", () => {
|
|
1104
|
+
if (usePlaceholder) {
|
|
1105
|
+
editor.innerText = "";
|
|
1106
|
+
editor.style.color = schema.fontColor || "#000000";
|
|
1107
|
+
}
|
|
1108
|
+
});
|
|
1109
|
+
body.addEventListener("blur", (event) => {
|
|
1110
|
+
const isListAction = rootElement.dataset[actionDataKey] === "true";
|
|
1111
|
+
const relatedTarget = event.relatedTarget;
|
|
1112
|
+
const isInternalFocus = rootElement.dataset[internalFocusDataKey] === "true" || relatedTarget instanceof Node && rootElement.contains(relatedTarget);
|
|
1113
|
+
delete rootElement.dataset[internalFocusDataKey];
|
|
1114
|
+
if (isListAction || isInternalFocus) return;
|
|
1115
|
+
if (!onChange) return;
|
|
1116
|
+
commitItems(getNextItems());
|
|
1117
|
+
if (stopEditing) stopEditing();
|
|
1118
|
+
}, true);
|
|
1119
|
+
editor.addEventListener("keydown", (event) => {
|
|
1120
|
+
if (event.key === "Enter") {
|
|
1121
|
+
if (isComposingKeyboardEvent(event)) return;
|
|
1122
|
+
event.preventDefault();
|
|
1123
|
+
if (insertLineBreakAtSelection(editor)) {
|
|
1124
|
+
preserveEditingForKeyboardCommit();
|
|
1125
|
+
if (mode === "form") commitHeight(range.start + index);
|
|
1126
|
+
else commitItems(getNextItems(), range.start + index);
|
|
1127
|
+
}
|
|
1128
|
+
} else if (event.key === "Tab") {
|
|
1129
|
+
event.preventDefault();
|
|
1130
|
+
updateItems(index, (nextItems, itemIndex) => {
|
|
1131
|
+
const itemToUpdate = nextItems[itemIndex];
|
|
1132
|
+
itemToUpdate.level = event.shiftKey ? Math.max(itemToUpdate.level - 1, 0) : Math.min(itemToUpdate.level + 1, 8);
|
|
1133
|
+
return itemIndex;
|
|
1134
|
+
});
|
|
1135
|
+
} else if (event.key === "Backspace" && getText(editor) === "") {
|
|
1136
|
+
event.preventDefault();
|
|
1137
|
+
updateItems(index, (nextItems, itemIndex) => {
|
|
1138
|
+
if (nextItems.length <= 1) {
|
|
1139
|
+
nextItems.splice(0);
|
|
1140
|
+
return;
|
|
1141
|
+
}
|
|
1142
|
+
nextItems.splice(itemIndex, 1);
|
|
1143
|
+
return Math.min(itemIndex, nextItems.length - 1);
|
|
1144
|
+
});
|
|
1145
|
+
}
|
|
1146
|
+
});
|
|
1147
|
+
bodyElements.push(editor);
|
|
1148
|
+
}
|
|
1149
|
+
row.appendChild(marker);
|
|
1150
|
+
row.appendChild(body);
|
|
1151
|
+
if (showControls) {
|
|
1152
|
+
const controls = document.createElement("div");
|
|
1153
|
+
controls.addEventListener("pointerdown", preserveEditingForAction);
|
|
1154
|
+
controls.addEventListener("mousedown", preserveEditingForAction);
|
|
1155
|
+
setStyles(controls, {
|
|
1156
|
+
position: "absolute",
|
|
1157
|
+
top: "0mm",
|
|
1158
|
+
right: "-82px",
|
|
1159
|
+
display: "flex",
|
|
1160
|
+
gap: "2px"
|
|
1161
|
+
});
|
|
1162
|
+
controls.appendChild(createActionButton({
|
|
1163
|
+
label: "+",
|
|
1164
|
+
ariaLabel: arg.i18n("schemas.list.addItem"),
|
|
1165
|
+
onPressStart: preserveEditingForAction,
|
|
1166
|
+
onClick: () => {
|
|
1167
|
+
updateItems(index, (nextItems, itemIndex) => {
|
|
1168
|
+
nextItems.splice(itemIndex + 1, 0, {
|
|
1169
|
+
level: nextItems[itemIndex]?.level ?? 0,
|
|
1170
|
+
text: ""
|
|
1171
|
+
});
|
|
1172
|
+
return itemIndex + 1;
|
|
1173
|
+
});
|
|
1174
|
+
}
|
|
1175
|
+
}));
|
|
1176
|
+
controls.appendChild(createActionButton({
|
|
1177
|
+
label: "-",
|
|
1178
|
+
ariaLabel: arg.i18n("schemas.list.removeItem"),
|
|
1179
|
+
onPressStart: preserveEditingForAction,
|
|
1180
|
+
onClick: () => {
|
|
1181
|
+
updateItems(index, (nextItems, itemIndex) => {
|
|
1182
|
+
if (nextItems.length <= 1) {
|
|
1183
|
+
nextItems.splice(0);
|
|
1184
|
+
return;
|
|
1185
|
+
}
|
|
1186
|
+
nextItems.splice(itemIndex, 1);
|
|
1187
|
+
return Math.min(itemIndex, nextItems.length - 1);
|
|
1188
|
+
});
|
|
1189
|
+
}
|
|
1190
|
+
}));
|
|
1191
|
+
controls.appendChild(createActionButton({
|
|
1192
|
+
label: "<",
|
|
1193
|
+
ariaLabel: arg.i18n("schemas.list.outdentItem"),
|
|
1194
|
+
disabled: item.level === 0,
|
|
1195
|
+
onPressStart: preserveEditingForAction,
|
|
1196
|
+
onClick: () => {
|
|
1197
|
+
updateItems(index, (nextItems, itemIndex) => {
|
|
1198
|
+
nextItems[itemIndex].level = Math.max(nextItems[itemIndex].level - 1, 0);
|
|
1199
|
+
return itemIndex;
|
|
1200
|
+
});
|
|
1201
|
+
}
|
|
1202
|
+
}));
|
|
1203
|
+
controls.appendChild(createActionButton({
|
|
1204
|
+
label: ">",
|
|
1205
|
+
ariaLabel: arg.i18n("schemas.list.indentItem"),
|
|
1206
|
+
disabled: item.level >= 8,
|
|
1207
|
+
onPressStart: preserveEditingForAction,
|
|
1208
|
+
onClick: () => {
|
|
1209
|
+
updateItems(index, (nextItems, itemIndex) => {
|
|
1210
|
+
nextItems[itemIndex].level = Math.min(nextItems[itemIndex].level + 1, 8);
|
|
1211
|
+
return itemIndex;
|
|
1212
|
+
});
|
|
1213
|
+
}
|
|
1214
|
+
}));
|
|
1215
|
+
row.appendChild(controls);
|
|
1216
|
+
}
|
|
1217
|
+
rootElement.appendChild(row);
|
|
1218
|
+
offsetY += item.height;
|
|
1219
|
+
}
|
|
1220
|
+
if (showControls && visibleItems.length === 0) appendEmptyListControls();
|
|
1221
|
+
const pendingFocusIndex = pendingFocusIndexes.get(focusKey);
|
|
1222
|
+
if (pendingFocusIndex !== void 0) pendingFocusIndexes.delete(focusKey);
|
|
1223
|
+
const requestedFocusIndex = Number(rootElement.dataset[focusDataKey] ?? pendingFocusIndex);
|
|
1224
|
+
delete rootElement.dataset[focusDataKey];
|
|
1225
|
+
delete rootElement.dataset[actionDataKey];
|
|
1226
|
+
delete rootElement.dataset[internalFocusDataKey];
|
|
1227
|
+
const relativeFocusIndex = requestedFocusIndex - range.start;
|
|
1228
|
+
if (editable && Number.isFinite(requestedFocusIndex) && bodyElements[relativeFocusIndex]) setTimeout(() => focusBody(bodyElements[relativeFocusIndex]));
|
|
1229
|
+
else if (editable && mode === "designer" && bodyElements[0]) setTimeout(() => {
|
|
1230
|
+
if (!rootElement.contains(document.activeElement)) focusBody(bodyElements[0]);
|
|
1231
|
+
});
|
|
1232
|
+
if (schema.height !== layout.totalHeight && onChange) onChange({
|
|
1233
|
+
key: "height",
|
|
1234
|
+
value: layout.totalHeight
|
|
1235
|
+
});
|
|
1236
|
+
};
|
|
1237
|
+
//#endregion
|
|
1238
|
+
//#region src/list/index.ts
|
|
1239
|
+
var listSchema = {
|
|
473
1240
|
pdf: pdfRender$2,
|
|
474
1241
|
ui: uiRender$2,
|
|
475
1242
|
propPanel: propPanel$1,
|
|
476
|
-
icon: createSvgStr(
|
|
477
|
-
uninterruptedEditMode: true
|
|
1243
|
+
icon: createSvgStr(List)
|
|
478
1244
|
};
|
|
479
1245
|
//#endregion
|
|
480
1246
|
//#region src/graphics/imagehelper.ts
|
|
@@ -1534,144 +2300,6 @@ var lineSchema = {
|
|
|
1534
2300
|
icon: createSvgStr(Minus)
|
|
1535
2301
|
};
|
|
1536
2302
|
//#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
2303
|
//#region src/tables/cell.ts
|
|
1676
2304
|
var linePdfRender = lineSchema.pdf;
|
|
1677
2305
|
var rectanglePdfRender$1 = rectangle.pdf;
|
|
@@ -1743,7 +2371,7 @@ var cellSchema = {
|
|
|
1743
2371
|
y: position.y
|
|
1744
2372
|
}, borderWidth.left, height)
|
|
1745
2373
|
]);
|
|
1746
|
-
await pdfRender$
|
|
2374
|
+
await pdfRender$4({
|
|
1747
2375
|
...arg,
|
|
1748
2376
|
schema: {
|
|
1749
2377
|
...schema,
|
|
@@ -1763,7 +2391,7 @@ var cellSchema = {
|
|
|
1763
2391
|
const { borderWidth, width, height, borderColor, backgroundColor } = schema;
|
|
1764
2392
|
rootElement.style.backgroundColor = backgroundColor;
|
|
1765
2393
|
const textDiv = createTextDiv(schema);
|
|
1766
|
-
await uiRender$
|
|
2394
|
+
await uiRender$4({
|
|
1767
2395
|
...arg,
|
|
1768
2396
|
schema: {
|
|
1769
2397
|
...schema,
|
|
@@ -1898,17 +2526,38 @@ var pdfRender = async (arg) => {
|
|
|
1898
2526
|
};
|
|
1899
2527
|
//#endregion
|
|
1900
2528
|
//#region src/tables/uiRender.ts
|
|
1901
|
-
var buttonSize =
|
|
2529
|
+
var buttonSize = 18;
|
|
1902
2530
|
function createButton(options) {
|
|
1903
2531
|
const button = document.createElement("button");
|
|
2532
|
+
button.type = "button";
|
|
2533
|
+
button.innerText = options.text;
|
|
2534
|
+
if (options.ariaLabel) button.setAttribute("aria-label", options.ariaLabel);
|
|
1904
2535
|
button.style.width = `${options.width}px`;
|
|
1905
2536
|
button.style.height = `${options.height}px`;
|
|
1906
2537
|
button.style.position = "absolute";
|
|
1907
2538
|
button.style.top = options.top;
|
|
2539
|
+
button.style.display = "inline-flex";
|
|
2540
|
+
button.style.alignItems = "center";
|
|
2541
|
+
button.style.justifyContent = "center";
|
|
2542
|
+
button.style.padding = "0";
|
|
2543
|
+
button.style.border = "1px solid #d9d9d9";
|
|
2544
|
+
button.style.borderRadius = "3px";
|
|
2545
|
+
button.style.background = "#ffffff";
|
|
2546
|
+
button.style.color = "#333333";
|
|
2547
|
+
button.style.fontSize = "11px";
|
|
2548
|
+
button.style.lineHeight = "1";
|
|
2549
|
+
button.style.cursor = "pointer";
|
|
2550
|
+
button.style.zIndex = "20";
|
|
1908
2551
|
if (options.left !== void 0) button.style.left = options.left;
|
|
1909
2552
|
if (options.right !== void 0) button.style.right = options.right;
|
|
1910
|
-
button.
|
|
1911
|
-
|
|
2553
|
+
button.addEventListener("mousedown", (event) => {
|
|
2554
|
+
event.preventDefault();
|
|
2555
|
+
});
|
|
2556
|
+
button.addEventListener("click", (event) => {
|
|
2557
|
+
event.preventDefault();
|
|
2558
|
+
event.stopPropagation();
|
|
2559
|
+
options.onClick(event);
|
|
2560
|
+
});
|
|
1912
2561
|
return button;
|
|
1913
2562
|
}
|
|
1914
2563
|
var cellUiRender = cellSchema.ui;
|
|
@@ -2078,6 +2727,7 @@ var uiRender = async (arg) => {
|
|
|
2078
2727
|
top: `${table.getHeight()}mm`,
|
|
2079
2728
|
left: `calc(50% - ${buttonSize / 2}px)`,
|
|
2080
2729
|
text: "+",
|
|
2730
|
+
ariaLabel: "Add row",
|
|
2081
2731
|
onClick: () => {
|
|
2082
2732
|
const newRow = Array(schema.head.length).fill("");
|
|
2083
2733
|
if (onChange) onChange({
|
|
@@ -2096,6 +2746,7 @@ var uiRender = async (arg) => {
|
|
|
2096
2746
|
top: `${offsetY - px2mm(buttonSize)}mm`,
|
|
2097
2747
|
right: `-${buttonSize}px`,
|
|
2098
2748
|
text: "-",
|
|
2749
|
+
ariaLabel: "Remove row",
|
|
2099
2750
|
onClick: () => {
|
|
2100
2751
|
const newTableBody = body.filter((_, j) => j !== i + (schema.__bodyRange?.start ?? 0));
|
|
2101
2752
|
if (onChange) onChange({
|
|
@@ -2117,6 +2768,7 @@ var uiRender = async (arg) => {
|
|
|
2117
2768
|
top: `${(showHead ? table.getHeadHeight() : 0) - px2mm(buttonSize)}mm`,
|
|
2118
2769
|
right: `-${buttonSize}px`,
|
|
2119
2770
|
text: "+",
|
|
2771
|
+
ariaLabel: "Add column",
|
|
2120
2772
|
onClick: (e) => {
|
|
2121
2773
|
e.preventDefault();
|
|
2122
2774
|
const newColumnWidthPercentage = 25;
|
|
@@ -2152,6 +2804,7 @@ var uiRender = async (arg) => {
|
|
|
2152
2804
|
top: `${-buttonSize}px`,
|
|
2153
2805
|
left: `${offsetX - px2mm(buttonSize)}mm`,
|
|
2154
2806
|
text: "-",
|
|
2807
|
+
ariaLabel: "Remove column",
|
|
2155
2808
|
onClick: () => {
|
|
2156
2809
|
const totalWidthMinusRemoved = schema.headWidthPercentages.reduce((sum, width, j) => j !== i ? sum + width : sum, 0);
|
|
2157
2810
|
onChange([
|
|
@@ -5318,13 +5971,13 @@ var schema$3 = {
|
|
|
5318
5971
|
propPanel: {
|
|
5319
5972
|
...textSchema.propPanel,
|
|
5320
5973
|
widgets: {
|
|
5321
|
-
...propPanel$
|
|
5974
|
+
...propPanel$3.widgets,
|
|
5322
5975
|
addOptions
|
|
5323
5976
|
},
|
|
5324
5977
|
schema: (propPanelProps) => {
|
|
5325
|
-
if (typeof propPanel$
|
|
5978
|
+
if (typeof propPanel$3.schema !== "function") throw Error("Oops, is text schema no longer a function?");
|
|
5326
5979
|
return {
|
|
5327
|
-
...propPanel$
|
|
5980
|
+
...propPanel$3.schema(propPanelProps),
|
|
5328
5981
|
"-------": {
|
|
5329
5982
|
type: "void",
|
|
5330
5983
|
widget: "Divider"
|
|
@@ -5506,6 +6159,6 @@ var schema = {
|
|
|
5506
6159
|
icon: getCheckedIcon()
|
|
5507
6160
|
};
|
|
5508
6161
|
//#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 };
|
|
6162
|
+
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
6163
|
|
|
5511
6164
|
//# sourceMappingURL=index.js.map
|