@codetectonics/mantle 1.0.11 → 1.0.13

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.
@@ -94,9 +94,10 @@ import * as i1$1 from '@citizenobserver/angular-token';
94
94
  import * as i5$1 from '@angular/flex-layout/extended';
95
95
  import * as i3 from '@angular/flex-layout/flex';
96
96
  import { DataSource } from '@angular/cdk/collections';
97
- import Quill from 'quill';
97
+ import Quill, { Delta } from 'quill';
98
98
  import Link from 'quill/formats/link';
99
99
  import { MentionBlot, Mention } from 'quill-mention';
100
+ import Clipboard from 'quill/modules/clipboard';
100
101
  import Highcharts from 'highcharts';
101
102
  import HighchartsItemSeries from 'highcharts/modules/item-series';
102
103
  import HighchartsGantt from 'highcharts/modules/gantt';
@@ -2164,35 +2165,63 @@ class NumberInputComponent {
2164
2165
  registerOnChange(fn) { this.onChange = fn; }
2165
2166
  registerOnTouched(fn) { this.onTouched = fn; }
2166
2167
  ngOnChanges() { }
2168
+ /**
2169
+ * Utility: safely coerce input into number or null
2170
+ */
2171
+ coerceToNumber(value) {
2172
+ if (value === null || value === undefined)
2173
+ return null;
2174
+ if (typeof value === 'number' && !isNaN(value))
2175
+ return value;
2176
+ if (typeof value === 'string') {
2177
+ const trimmed = value.trim();
2178
+ if (trimmed === '')
2179
+ return null;
2180
+ // Match valid numeric string: -12, 3.14, 0, -0.5, 1e5
2181
+ if (/^-?\d+(\.\d+)?([eE][-+]?\d+)?$/.test(trimmed)) {
2182
+ const n = Number(trimmed);
2183
+ return Number.isFinite(n) ? n : null;
2184
+ }
2185
+ return null; // treat non-numeric strings as null
2186
+ }
2187
+ return null;
2188
+ }
2167
2189
  writeValue(newValue) {
2190
+ newValue = this.coerceToNumber(newValue);
2168
2191
  this.value = newValue;
2169
2192
  this.onChange(newValue);
2170
2193
  }
2171
2194
  onValueChanged(event) {
2195
+ this.value = this.coerceToNumber(this.value);
2172
2196
  this.onChange(this.value);
2173
2197
  }
2174
2198
  validate(control) {
2175
- if (control.value === null) {
2199
+ const val = this.coerceToNumber(control.value);
2200
+ // Replace invalid values in form control with null
2201
+ if (val === null) {
2176
2202
  this.errorMessage = this.error;
2177
2203
  return null;
2178
2204
  }
2179
- let errors = {};
2180
- if (this.options.min && control.value < this.options.min)
2205
+ const errors = {};
2206
+ if (this.options.min !== undefined && val < this.options.min) {
2181
2207
  errors.min = `must be greater than or equal to ${this.options.min}`;
2182
- if (this.options.max && control.value > this.options.max)
2208
+ }
2209
+ if (this.options.max !== undefined && val > this.options.max) {
2183
2210
  errors.max = `must be lower than or equal to ${this.options.max}`;
2184
- if (this.options.decimal_places) {
2185
- if (this.options.decimal_places == 0) {
2186
- if ((control.value - Math.floor(control.value)) !== 0)
2187
- errors.decimal_places = 'cannot be a decimal';
2188
- }
2189
- else {
2190
- if ((control.value - control.value.toFixed(2)) !== 0)
2191
- errors.decimal_places = `must have a maximum of ${this.options.decimal_places} decimal places`;
2211
+ }
2212
+ if (this.options.decimal_places !== undefined) {
2213
+ const factor = Math.pow(10, this.options.decimal_places);
2214
+ if (Math.round(val * factor) / factor !== val) {
2215
+ errors.decimal_places =
2216
+ this.options.decimal_places === 0
2217
+ ? 'cannot be a decimal'
2218
+ : `must have a maximum of ${this.options.decimal_places} decimal places`;
2192
2219
  }
2193
2220
  }
2194
- this.errorMessage = [...[this.error], ...Object.values(errors)].filter(item => { return !!item; }).join(', ');
2195
- return errors ? errors : null;
2221
+ this.errorMessage = [this.error, ...Object.values(errors)]
2222
+ .filter(Boolean)
2223
+ .join(', ');
2224
+ return Object.keys(errors).length > 0 ? errors : null;
2196
2225
  }
2197
2226
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.3", ngImport: i0, type: NumberInputComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
2198
2227
  static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "20.1.3", type: NumberInputComponent, isStandalone: false, selector: "mantle-number-input", inputs: { label: "label", tooltip: "tooltip", options: "options", disable: "disable", required: "required", error: "error" }, providers: [
@@ -2516,7 +2545,20 @@ class RichTextMentionBlot extends MentionBlot {
2516
2545
  return element;
2517
2546
  }
2518
2547
  }
2519
- Quill.register({ "blots/mention": RichTextMentionBlot, "modules/mention": Mention, 'formats/link': RichTextLink });
2548
+ class RichTextClipboard extends Clipboard {
2549
+ onPaste(range, { text, html }) {
2550
+ const formats = this.quill.getFormat(range.index);
2551
+ const pastedDelta = this.convert({ text }, formats);
2552
+ const delta = new Delta()
2553
+ .retain(range?.index)
2554
+ .delete(range?.length)
2555
+ .concat(pastedDelta);
2556
+ this.quill.updateContents(delta, Quill.sources.USER);
2557
+ this.quill.setSelection(delta.length() - range.length, Quill.sources.SILENT);
2558
+ this.quill.scrollSelectionIntoView();
2559
+ }
2560
+ }
2561
+ Quill.register({ "blots/mention": RichTextMentionBlot, "modules/mention": Mention, 'formats/link': RichTextLink, 'modules/clipboard': RichTextClipboard });
2520
2562
  class RichTextInputComponent {
2521
2563
  constructor() {
2522
2564
  this.value = '';