@ngstarter-ui/components 21.0.59 → 21.0.61

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.
@@ -4447,7 +4447,8 @@
4447
4447
  "ngs-form-builder-field-host",
4448
4448
  "ngs-form-builder-settings-host",
4449
4449
  "ngs-form-logic",
4450
- "ngs-form-renderer"
4450
+ "ngs-form-renderer",
4451
+ "ngs-plain-text-form-builder-settings"
4451
4452
  ],
4452
4453
  "exportedSymbols": [
4453
4454
  "asyncValidatorsFromRules",
@@ -4455,9 +4456,11 @@
4455
4456
  "BasicFormBuilderLayoutSettings",
4456
4457
  "BasicFormBuilderSectionSettings",
4457
4458
  "createDefaultFormBuilderSchema",
4459
+ "DEFAULT_FORM_BUILDER_CALCULATION_ENGINE",
4458
4460
  "DEFAULT_FORM_BUILDER_FIELDS",
4459
4461
  "DEFAULT_FORM_BUILDER_ITEMS",
4460
4462
  "DEFAULT_FORM_BUILDER_VALIDATORS",
4463
+ "FORM_BUILDER_CALCULATION_ENGINE",
4461
4464
  "FORM_BUILDER_FIELD_BASE_SETTINGS_SCHEMA",
4462
4465
  "FORM_BUILDER_FIELDS",
4463
4466
  "FORM_BUILDER_INPUT_FIELD_BASE_SETTINGS_SCHEMA",
@@ -4471,6 +4474,9 @@
4471
4474
  "FORM_BUILDER_UPLOAD_CALLBACK",
4472
4475
  "FORM_BUILDER_VALIDATORS",
4473
4476
  "FormBuilder",
4477
+ "FormBuilderCalculationContext",
4478
+ "FormBuilderCalculationEngine",
4479
+ "FormBuilderCalculationResult",
4474
4480
  "FormBuilderComponentImporter",
4475
4481
  "formBuilderField",
4476
4482
  "FormBuilderField",
@@ -4480,6 +4486,7 @@
4480
4486
  "FormBuilderFieldRenderContext",
4481
4487
  "FormBuilderFieldSettingsContext",
4482
4488
  "FormBuilderFieldWidth",
4489
+ "FormBuilderFlow",
4483
4490
  "formBuilderItem",
4484
4491
  "FormBuilderItemDefinition",
4485
4492
  "FormBuilderItemKind",
@@ -4498,6 +4505,7 @@
4498
4505
  "FormBuilderSettingsHost",
4499
4506
  "FormBuilderSettingsInheritance",
4500
4507
  "FormBuilderSettingsSchemaFactory",
4508
+ "FormBuilderStep",
4501
4509
  "FormBuilderUploadCallback",
4502
4510
  "FormBuilderUploadContext",
4503
4511
  "FormBuilderValidationRule",
@@ -4508,6 +4516,7 @@
4508
4516
  "FormLogic",
4509
4517
  "FormRenderer",
4510
4518
  "mergeFormBuilderValidatorDefinitions",
4519
+ "PlainTextFormBuilderSettings",
4511
4520
  "provideFormBuilder",
4512
4521
  "provideFormBuilderField",
4513
4522
  "provideFormBuilderFields",
@@ -4542,6 +4551,7 @@
4542
4551
  "formReady"
4543
4552
  ],
4544
4553
  "cssTokens": [
4554
+ "--ngs-alert-border-radius",
4545
4555
  "--ngs-avatar-font-weight",
4546
4556
  "--ngs-avatar-size",
4547
4557
  "--ngs-card-padding",
@@ -4555,6 +4565,10 @@
4555
4565
  "--ngs-color-primary-container",
4556
4566
  "--ngs-color-surface",
4557
4567
  "--ngs-color-surface-container-lowest",
4568
+ "--ngs-field-container-height",
4569
+ "--ngs-field-font-size",
4570
+ "--ngs-field-height",
4571
+ "--ngs-field-line-height",
4558
4572
  "--ngs-field-radius",
4559
4573
  "--ngs-font-size-base",
4560
4574
  "--ngs-font-size-lg",
@@ -0,0 +1,150 @@
1
+ import * as i0 from '@angular/core';
2
+ import { input, viewChild, computed, ChangeDetectionStrategy, Component } from '@angular/core';
3
+ import * as i1 from '@angular/forms';
4
+ import { FormsModule } from '@angular/forms';
5
+ import { Button } from '@ngstarter-ui/components/button';
6
+ import { FormField, Error, Hint, Label } from '@ngstarter-ui/components/form-field';
7
+ import { Icon } from '@ngstarter-ui/components/icon';
8
+ import { Input } from '@ngstarter-ui/components/input';
9
+ import { SlideToggle } from '@ngstarter-ui/components/slide-toggle';
10
+
11
+ class PlainTextFormBuilderSettings {
12
+ field = input.required(...(ngDevMode ? [{ debugName: "field" }] : /* istanbul ignore next */ []));
13
+ update = input.required(...(ngDevMode ? [{ debugName: "update" }] : /* istanbul ignore next */ []));
14
+ textInput = viewChild('textInput', ...(ngDevMode ? [{ debugName: "textInput" }] : /* istanbul ignore next */ []));
15
+ expressionEnabled = computed(() => this.field().settings?.['expression'] === true, ...(ngDevMode ? [{ debugName: "expressionEnabled" }] : /* istanbul ignore next */ []));
16
+ expressions = computed(() => normalizeExpressions(this.field().settings?.['expressions']), ...(ngDevMode ? [{ debugName: "expressions" }] : /* istanbul ignore next */ []));
17
+ patchText(text) {
18
+ this.patchSettings({ text });
19
+ }
20
+ patchExpressionEnabled(expression) {
21
+ this.patchSettings({
22
+ expression,
23
+ expressions: expression ? this.expressions() : this.field().settings?.['expressions'] ?? []
24
+ });
25
+ }
26
+ addExpression() {
27
+ const expressions = this.expressions();
28
+ const id = uniqueExpressionId(expressions);
29
+ this.patchSettings({
30
+ expressions: [
31
+ ...expressions,
32
+ {
33
+ id,
34
+ expression: ''
35
+ }
36
+ ]
37
+ });
38
+ }
39
+ updateExpression(index, changes) {
40
+ const expressions = this.expressions();
41
+ const current = expressions[index];
42
+ if (!current) {
43
+ return;
44
+ }
45
+ this.patchSettings({
46
+ expressions: expressions.map((item, itemIndex) => itemIndex === index
47
+ ? {
48
+ ...item,
49
+ ...changes,
50
+ id: changes.id !== undefined ? normalizeExpressionId(changes.id) : item.id
51
+ }
52
+ : item)
53
+ });
54
+ }
55
+ removeExpression(index) {
56
+ this.patchSettings({
57
+ expressions: this.expressions().filter((_, itemIndex) => itemIndex !== index)
58
+ });
59
+ }
60
+ insertToken(id) {
61
+ const token = `{${id}}`;
62
+ const text = stringValue(this.field().settings?.['text']);
63
+ const input = this.textInput()?.nativeElement;
64
+ if (!input) {
65
+ this.patchText(`${text}${token}`);
66
+ return;
67
+ }
68
+ const start = input.selectionStart ?? text.length;
69
+ const end = input.selectionEnd ?? start;
70
+ const nextText = `${text.slice(0, start)}${token}${text.slice(end)}`;
71
+ this.patchText(nextText);
72
+ queueMicrotask(() => {
73
+ input.focus();
74
+ input.setSelectionRange(start + token.length, start + token.length);
75
+ });
76
+ }
77
+ expressionIdError(id) {
78
+ if (!id) {
79
+ return 'ID is required.';
80
+ }
81
+ return /^[A-Za-z_][A-Za-z0-9_-]*$/.test(id)
82
+ ? ''
83
+ : 'Use letters, numbers, underscore, or dash. Start with a letter or underscore.';
84
+ }
85
+ tokenHint(id) {
86
+ return `Inserted into text as {${id || 'id'}}.`;
87
+ }
88
+ patchSettings(changes) {
89
+ this.update()({
90
+ settings: {
91
+ ...this.field().settings,
92
+ ...changes
93
+ }
94
+ });
95
+ }
96
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: PlainTextFormBuilderSettings, deps: [], target: i0.ɵɵFactoryTarget.Component });
97
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.4", type: PlainTextFormBuilderSettings, isStandalone: true, selector: "ngs-plain-text-form-builder-settings", inputs: { field: { classPropertyName: "field", publicName: "field", isSignal: true, isRequired: true, transformFunction: null }, update: { classPropertyName: "update", publicName: "update", isSignal: true, isRequired: true, transformFunction: null } }, host: { classAttribute: "ngs-plain-text-form-builder-settings" }, viewQueries: [{ propertyName: "textInput", first: true, predicate: ["textInput"], descendants: true, isSignal: true }], exportAs: ["ngsPlainTextFormBuilderSettings"], ngImport: i0, template: "<div class=\"plain-text-settings\">\n <ngs-form-field>\n <ngs-label>Text</ngs-label>\n <textarea #textInput\n ngsInput\n rows=\"5\"\n [ngModel]=\"field().settings?.['text'] || ''\"\n [ngModelOptions]=\"{standalone: true}\"\n (ngModelChange)=\"patchText($event)\"></textarea>\n <ngs-hint>Use tokens such as &#123;count_total&#125; when Expression is enabled.</ngs-hint>\n </ngs-form-field>\n\n <div class=\"plain-text-expression-toggle\">\n <ngs-slide-toggle [ngModel]=\"expressionEnabled()\"\n [ngModelOptions]=\"{standalone: true}\"\n (ngModelChange)=\"patchExpressionEnabled($event)\">\n Expression\n </ngs-slide-toggle>\n </div>\n\n @if (expressionEnabled()) {\n <div class=\"plain-text-expression-panel\">\n @if (expressions().length) {\n <div class=\"plain-text-expression-list\">\n @for (expression of expressions(); track $index) {\n <section class=\"plain-text-expression-item\">\n <div class=\"plain-text-expression-item-header\">\n <span>Expression {{ $index + 1 }}</span>\n <div class=\"plain-text-expression-actions\">\n <button ngsIconButton\n type=\"button\"\n aria-label=\"Insert token\"\n [disabled]=\"!!expressionIdError(expression.id)\"\n (click)=\"insertToken(expression.id)\">\n <ngs-icon name=\"fluent:braces-24-regular\"/>\n </button>\n\n <button ngsIconButton\n type=\"button\"\n aria-label=\"Remove expression\"\n (click)=\"removeExpression($index)\">\n <ngs-icon name=\"fluent:delete-24-regular\"/>\n </button>\n </div>\n </div>\n\n <ngs-form-field>\n <ngs-label>ID</ngs-label>\n <input ngsInput\n [ngModel]=\"expression.id\"\n [ngModelOptions]=\"{standalone: true}\"\n (ngModelChange)=\"updateExpression($index, { id: $event })\">\n @if (expressionIdError(expression.id); as error) {\n <ngs-error>{{ error }}</ngs-error>\n }\n <ngs-hint [textContent]=\"tokenHint(expression.id)\"></ngs-hint>\n </ngs-form-field>\n\n <ngs-form-field>\n <ngs-label>Expression</ngs-label>\n <textarea ngsInput\n rows=\"3\"\n [ngModel]=\"expression.expression\"\n [ngModelOptions]=\"{standalone: true}\"\n (ngModelChange)=\"updateExpression($index, { expression: $event })\"></textarea>\n <ngs-hint>Example: ROUND(item_quantity * item_price, 2)</ngs-hint>\n </ngs-form-field>\n </section>\n }\n </div>\n }\n\n <div>\n <button ngsButton=\"outlined\" type=\"button\" (click)=\"addExpression()\">\n <ngs-icon name=\"fluent:add-24-regular\"/>\n Add expression\n </button>\n </div>\n </div>\n }\n</div>\n", styles: [":host{display:block}:host .plain-text-settings{display:flex;flex-direction:column;gap:calc(var(--spacing, .25rem) * 4)}:host .plain-text-expression-toggle{display:flex;align-items:center;justify-content:space-between;gap:calc(var(--spacing, .25rem) * 3)}:host .plain-text-expression-list{display:flex;flex-direction:column;gap:calc(var(--spacing, .25rem) * 3)}:host .plain-text-expression-panel{display:flex;flex-direction:column;gap:calc(var(--spacing, .25rem) * 3)}:host .plain-text-expression-add{display:flex;justify-content:flex-start}:host .plain-text-expression-item{display:flex;flex-direction:column;gap:calc(var(--spacing, .25rem) * 3);border-radius:var(--ngs-radius-md);padding:calc(var(--spacing, .25rem) * 3);outline:1px solid var(--ngs-color-outline-variant)}:host .plain-text-expression-item-header{display:flex;align-items:center;justify-content:space-between;gap:calc(var(--spacing, .25rem) * 2);color:var(--ngs-color-on-surface);font-size:var(--ngs-font-size-sm);font-weight:600}:host .plain-text-expression-actions{display:flex;align-items:center;gap:calc(var(--spacing, .25rem) * 1)}\n/*! tailwindcss v4.2.2 | MIT License | https://tailwindcss.com */\n"], dependencies: [{ kind: "ngmodule", type: FormsModule }, { kind: "directive", type: i1.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { kind: "directive", type: i1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i1.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }, { kind: "component", type: Button, selector: " button[ngsButton], button[ngsIconButton], a[ngsButton], a[ngsIconButton] ", inputs: ["ngsButton", "ngsIconButton", "loading", "disabled", "disabledInteractive", "disableRipple", "reverse", "fullWidth", "hideTextOnMobile"], exportAs: ["ngsButton"] }, { kind: "component", type: FormField, selector: "ngs-form-field", inputs: ["subscriptHiddenIfEmpty", "sameHeightAsButton"], exportAs: ["ngsFormField"] }, { kind: "component", type: Error, selector: "ngs-error", exportAs: ["ngsError"] }, { kind: "component", type: Hint, selector: "ngs-hint", inputs: ["align"], exportAs: ["ngsHint"] }, { kind: "component", type: Icon, selector: "ngs-icon", inputs: ["name"], exportAs: ["ngsIcon"] }, { kind: "directive", type: Input, selector: "input[ngsInput], textarea[ngsInput]", inputs: ["id", "placeholder", "required", "disabled", "readonly", "errorStateMatcher"], exportAs: ["ngsInput"] }, { kind: "component", type: Label, selector: "ngs-label" }, { kind: "component", type: SlideToggle, selector: "ngs-slide-toggle", inputs: ["id", "name", "labelPosition", "aria-label", "aria-labelledby", "aria-describedby", "required", "disabled", "disableRipple", "tabIndex", "hideIcon", "color", "checked"], outputs: ["disabledChange", "checkedChange", "change", "toggleChange"], exportAs: ["ngsSlideToggle"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
98
+ }
99
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: PlainTextFormBuilderSettings, decorators: [{
100
+ type: Component,
101
+ args: [{ selector: 'ngs-plain-text-form-builder-settings', exportAs: 'ngsPlainTextFormBuilderSettings', imports: [
102
+ FormsModule,
103
+ Button,
104
+ FormField,
105
+ Error,
106
+ Hint,
107
+ Icon,
108
+ Input,
109
+ Label,
110
+ SlideToggle
111
+ ], changeDetection: ChangeDetectionStrategy.OnPush, host: {
112
+ 'class': 'ngs-plain-text-form-builder-settings'
113
+ }, template: "<div class=\"plain-text-settings\">\n <ngs-form-field>\n <ngs-label>Text</ngs-label>\n <textarea #textInput\n ngsInput\n rows=\"5\"\n [ngModel]=\"field().settings?.['text'] || ''\"\n [ngModelOptions]=\"{standalone: true}\"\n (ngModelChange)=\"patchText($event)\"></textarea>\n <ngs-hint>Use tokens such as &#123;count_total&#125; when Expression is enabled.</ngs-hint>\n </ngs-form-field>\n\n <div class=\"plain-text-expression-toggle\">\n <ngs-slide-toggle [ngModel]=\"expressionEnabled()\"\n [ngModelOptions]=\"{standalone: true}\"\n (ngModelChange)=\"patchExpressionEnabled($event)\">\n Expression\n </ngs-slide-toggle>\n </div>\n\n @if (expressionEnabled()) {\n <div class=\"plain-text-expression-panel\">\n @if (expressions().length) {\n <div class=\"plain-text-expression-list\">\n @for (expression of expressions(); track $index) {\n <section class=\"plain-text-expression-item\">\n <div class=\"plain-text-expression-item-header\">\n <span>Expression {{ $index + 1 }}</span>\n <div class=\"plain-text-expression-actions\">\n <button ngsIconButton\n type=\"button\"\n aria-label=\"Insert token\"\n [disabled]=\"!!expressionIdError(expression.id)\"\n (click)=\"insertToken(expression.id)\">\n <ngs-icon name=\"fluent:braces-24-regular\"/>\n </button>\n\n <button ngsIconButton\n type=\"button\"\n aria-label=\"Remove expression\"\n (click)=\"removeExpression($index)\">\n <ngs-icon name=\"fluent:delete-24-regular\"/>\n </button>\n </div>\n </div>\n\n <ngs-form-field>\n <ngs-label>ID</ngs-label>\n <input ngsInput\n [ngModel]=\"expression.id\"\n [ngModelOptions]=\"{standalone: true}\"\n (ngModelChange)=\"updateExpression($index, { id: $event })\">\n @if (expressionIdError(expression.id); as error) {\n <ngs-error>{{ error }}</ngs-error>\n }\n <ngs-hint [textContent]=\"tokenHint(expression.id)\"></ngs-hint>\n </ngs-form-field>\n\n <ngs-form-field>\n <ngs-label>Expression</ngs-label>\n <textarea ngsInput\n rows=\"3\"\n [ngModel]=\"expression.expression\"\n [ngModelOptions]=\"{standalone: true}\"\n (ngModelChange)=\"updateExpression($index, { expression: $event })\"></textarea>\n <ngs-hint>Example: ROUND(item_quantity * item_price, 2)</ngs-hint>\n </ngs-form-field>\n </section>\n }\n </div>\n }\n\n <div>\n <button ngsButton=\"outlined\" type=\"button\" (click)=\"addExpression()\">\n <ngs-icon name=\"fluent:add-24-regular\"/>\n Add expression\n </button>\n </div>\n </div>\n }\n</div>\n", styles: [":host{display:block}:host .plain-text-settings{display:flex;flex-direction:column;gap:calc(var(--spacing, .25rem) * 4)}:host .plain-text-expression-toggle{display:flex;align-items:center;justify-content:space-between;gap:calc(var(--spacing, .25rem) * 3)}:host .plain-text-expression-list{display:flex;flex-direction:column;gap:calc(var(--spacing, .25rem) * 3)}:host .plain-text-expression-panel{display:flex;flex-direction:column;gap:calc(var(--spacing, .25rem) * 3)}:host .plain-text-expression-add{display:flex;justify-content:flex-start}:host .plain-text-expression-item{display:flex;flex-direction:column;gap:calc(var(--spacing, .25rem) * 3);border-radius:var(--ngs-radius-md);padding:calc(var(--spacing, .25rem) * 3);outline:1px solid var(--ngs-color-outline-variant)}:host .plain-text-expression-item-header{display:flex;align-items:center;justify-content:space-between;gap:calc(var(--spacing, .25rem) * 2);color:var(--ngs-color-on-surface);font-size:var(--ngs-font-size-sm);font-weight:600}:host .plain-text-expression-actions{display:flex;align-items:center;gap:calc(var(--spacing, .25rem) * 1)}\n/*! tailwindcss v4.2.2 | MIT License | https://tailwindcss.com */\n"] }]
114
+ }], propDecorators: { field: [{ type: i0.Input, args: [{ isSignal: true, alias: "field", required: true }] }], update: [{ type: i0.Input, args: [{ isSignal: true, alias: "update", required: true }] }], textInput: [{ type: i0.ViewChild, args: ['textInput', { isSignal: true }] }] } });
115
+ function normalizeExpressions(value) {
116
+ if (!Array.isArray(value)) {
117
+ return [];
118
+ }
119
+ return value
120
+ .filter(isRecord)
121
+ .map(item => ({
122
+ id: normalizeExpressionId(item['id']),
123
+ expression: stringValue(item['expression'])
124
+ }));
125
+ }
126
+ function uniqueExpressionId(expressions) {
127
+ const existing = new Set(expressions.map(item => item.id));
128
+ let index = expressions.length + 1;
129
+ let id = `expression_${index}`;
130
+ while (existing.has(id)) {
131
+ index += 1;
132
+ id = `expression_${index}`;
133
+ }
134
+ return id;
135
+ }
136
+ function normalizeExpressionId(value) {
137
+ return stringValue(value)
138
+ .trim()
139
+ .replace(/[^\w-]/g, '_')
140
+ .replace(/^[^A-Za-z_]+/, '');
141
+ }
142
+ function stringValue(value) {
143
+ return typeof value === 'string' ? value : '';
144
+ }
145
+ function isRecord(value) {
146
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
147
+ }
148
+
149
+ export { PlainTextFormBuilderSettings };
150
+ //# sourceMappingURL=ngstarter-ui-components-form-builder-plain-text-settings-D_MiuzJL.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ngstarter-ui-components-form-builder-plain-text-settings-D_MiuzJL.mjs","sources":["../../../projects/components/form-builder/src/settings/plain-text-settings/plain-text-settings.ts","../../../projects/components/form-builder/src/settings/plain-text-settings/plain-text-settings.html"],"sourcesContent":["import { ChangeDetectionStrategy, Component, ElementRef, computed, input, viewChild } from '@angular/core';\nimport { FormsModule } from '@angular/forms';\nimport { Button } from '@ngstarter-ui/components/button';\nimport { Error as FormFieldError, FormField, Hint, Label } from '@ngstarter-ui/components/form-field';\nimport { Icon } from '@ngstarter-ui/components/icon';\nimport { Input } from '@ngstarter-ui/components/input';\nimport { SlideToggle } from '@ngstarter-ui/components/slide-toggle';\nimport { FormBuilderField } from '../../types';\n\ninterface PlainTextExpression {\n id: string;\n expression: string;\n}\n\n@Component({\n selector: 'ngs-plain-text-form-builder-settings',\n exportAs: 'ngsPlainTextFormBuilderSettings',\n imports: [\n FormsModule,\n Button,\n FormField,\n FormFieldError,\n Hint,\n Icon,\n Input,\n Label,\n SlideToggle\n ],\n templateUrl: './plain-text-settings.html',\n styleUrl: './plain-text-settings.scss',\n changeDetection: ChangeDetectionStrategy.OnPush,\n host: {\n 'class': 'ngs-plain-text-form-builder-settings'\n }\n})\nexport class PlainTextFormBuilderSettings {\n readonly field = input.required<FormBuilderField>();\n readonly update = input.required<(changes: Partial<FormBuilderField>) => void>();\n\n protected readonly textInput = viewChild<ElementRef<HTMLTextAreaElement>>('textInput');\n protected readonly expressionEnabled = computed(() => this.field().settings?.['expression'] === true);\n protected readonly expressions = computed(() => normalizeExpressions(this.field().settings?.['expressions']));\n\n protected patchText(text: string): void {\n this.patchSettings({ text });\n }\n\n protected patchExpressionEnabled(expression: boolean): void {\n this.patchSettings({\n expression,\n expressions: expression ? this.expressions() : this.field().settings?.['expressions'] ?? []\n });\n }\n\n protected addExpression(): void {\n const expressions = this.expressions();\n const id = uniqueExpressionId(expressions);\n this.patchSettings({\n expressions: [\n ...expressions,\n {\n id,\n expression: ''\n }\n ]\n });\n }\n\n protected updateExpression(index: number, changes: Partial<PlainTextExpression>): void {\n const expressions = this.expressions();\n const current = expressions[index];\n\n if (!current) {\n return;\n }\n\n this.patchSettings({\n expressions: expressions.map((item, itemIndex) =>\n itemIndex === index\n ? {\n ...item,\n ...changes,\n id: changes.id !== undefined ? normalizeExpressionId(changes.id) : item.id\n }\n : item\n )\n });\n }\n\n protected removeExpression(index: number): void {\n this.patchSettings({\n expressions: this.expressions().filter((_, itemIndex) => itemIndex !== index)\n });\n }\n\n protected insertToken(id: string): void {\n const token = `{${id}}`;\n const text = stringValue(this.field().settings?.['text']);\n const input = this.textInput()?.nativeElement;\n\n if (!input) {\n this.patchText(`${text}${token}`);\n return;\n }\n\n const start = input.selectionStart ?? text.length;\n const end = input.selectionEnd ?? start;\n const nextText = `${text.slice(0, start)}${token}${text.slice(end)}`;\n\n this.patchText(nextText);\n queueMicrotask(() => {\n input.focus();\n input.setSelectionRange(start + token.length, start + token.length);\n });\n }\n\n protected expressionIdError(id: string): string {\n if (!id) {\n return 'ID is required.';\n }\n\n return /^[A-Za-z_][A-Za-z0-9_-]*$/.test(id)\n ? ''\n : 'Use letters, numbers, underscore, or dash. Start with a letter or underscore.';\n }\n\n protected tokenHint(id: string): string {\n return `Inserted into text as {${id || 'id'}}.`;\n }\n\n private patchSettings(changes: Record<string, any>): void {\n this.update()({\n settings: {\n ...this.field().settings,\n ...changes\n }\n });\n }\n}\n\nfunction normalizeExpressions(value: unknown): PlainTextExpression[] {\n if (!Array.isArray(value)) {\n return [];\n }\n\n return value\n .filter(isRecord)\n .map(item => ({\n id: normalizeExpressionId(item['id']),\n expression: stringValue(item['expression'])\n }));\n}\n\nfunction uniqueExpressionId(expressions: PlainTextExpression[]): string {\n const existing = new Set(expressions.map(item => item.id));\n let index = expressions.length + 1;\n let id = `expression_${index}`;\n\n while (existing.has(id)) {\n index += 1;\n id = `expression_${index}`;\n }\n\n return id;\n}\n\nfunction normalizeExpressionId(value: unknown): string {\n return stringValue(value)\n .trim()\n .replace(/[^\\w-]/g, '_')\n .replace(/^[^A-Za-z_]+/, '');\n}\n\nfunction stringValue(value: unknown): string {\n return typeof value === 'string' ? value : '';\n}\n\nfunction isRecord(value: unknown): value is Record<string, any> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n","<div class=\"plain-text-settings\">\n <ngs-form-field>\n <ngs-label>Text</ngs-label>\n <textarea #textInput\n ngsInput\n rows=\"5\"\n [ngModel]=\"field().settings?.['text'] || ''\"\n [ngModelOptions]=\"{standalone: true}\"\n (ngModelChange)=\"patchText($event)\"></textarea>\n <ngs-hint>Use tokens such as &#123;count_total&#125; when Expression is enabled.</ngs-hint>\n </ngs-form-field>\n\n <div class=\"plain-text-expression-toggle\">\n <ngs-slide-toggle [ngModel]=\"expressionEnabled()\"\n [ngModelOptions]=\"{standalone: true}\"\n (ngModelChange)=\"patchExpressionEnabled($event)\">\n Expression\n </ngs-slide-toggle>\n </div>\n\n @if (expressionEnabled()) {\n <div class=\"plain-text-expression-panel\">\n @if (expressions().length) {\n <div class=\"plain-text-expression-list\">\n @for (expression of expressions(); track $index) {\n <section class=\"plain-text-expression-item\">\n <div class=\"plain-text-expression-item-header\">\n <span>Expression {{ $index + 1 }}</span>\n <div class=\"plain-text-expression-actions\">\n <button ngsIconButton\n type=\"button\"\n aria-label=\"Insert token\"\n [disabled]=\"!!expressionIdError(expression.id)\"\n (click)=\"insertToken(expression.id)\">\n <ngs-icon name=\"fluent:braces-24-regular\"/>\n </button>\n\n <button ngsIconButton\n type=\"button\"\n aria-label=\"Remove expression\"\n (click)=\"removeExpression($index)\">\n <ngs-icon name=\"fluent:delete-24-regular\"/>\n </button>\n </div>\n </div>\n\n <ngs-form-field>\n <ngs-label>ID</ngs-label>\n <input ngsInput\n [ngModel]=\"expression.id\"\n [ngModelOptions]=\"{standalone: true}\"\n (ngModelChange)=\"updateExpression($index, { id: $event })\">\n @if (expressionIdError(expression.id); as error) {\n <ngs-error>{{ error }}</ngs-error>\n }\n <ngs-hint [textContent]=\"tokenHint(expression.id)\"></ngs-hint>\n </ngs-form-field>\n\n <ngs-form-field>\n <ngs-label>Expression</ngs-label>\n <textarea ngsInput\n rows=\"3\"\n [ngModel]=\"expression.expression\"\n [ngModelOptions]=\"{standalone: true}\"\n (ngModelChange)=\"updateExpression($index, { expression: $event })\"></textarea>\n <ngs-hint>Example: ROUND(item_quantity * item_price, 2)</ngs-hint>\n </ngs-form-field>\n </section>\n }\n </div>\n }\n\n <div>\n <button ngsButton=\"outlined\" type=\"button\" (click)=\"addExpression()\">\n <ngs-icon name=\"fluent:add-24-regular\"/>\n Add expression\n </button>\n </div>\n </div>\n }\n</div>\n"],"names":["FormFieldError"],"mappings":";;;;;;;;;;MAmCa,4BAA4B,CAAA;AAC9B,IAAA,KAAK,GAAG,KAAK,CAAC,QAAQ,2EAAoB;AAC1C,IAAA,MAAM,GAAG,KAAK,CAAC,QAAQ,4EAAgD;AAE7D,IAAA,SAAS,GAAG,SAAS,CAAkC,WAAW,gFAAC;AACnE,IAAA,iBAAiB,GAAG,QAAQ,CAAC,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC,QAAQ,GAAG,YAAY,CAAC,KAAK,IAAI,wFAAC;IAClF,WAAW,GAAG,QAAQ,CAAC,MAAM,oBAAoB,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,QAAQ,GAAG,aAAa,CAAC,CAAC,kFAAC;AAEnG,IAAA,SAAS,CAAC,IAAY,EAAA;AAC9B,QAAA,IAAI,CAAC,aAAa,CAAC,EAAE,IAAI,EAAE,CAAC;IAC9B;AAEU,IAAA,sBAAsB,CAAC,UAAmB,EAAA;QAClD,IAAI,CAAC,aAAa,CAAC;YACjB,UAAU;YACV,WAAW,EAAE,UAAU,GAAG,IAAI,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC,QAAQ,GAAG,aAAa,CAAC,IAAI;AAC1F,SAAA,CAAC;IACJ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