@ship-ui/core 0.16.2 → 0.16.3

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.
@@ -1,6 +1,6 @@
1
1
  import * as i0 from '@angular/core';
2
- import { inject, ElementRef, Renderer2, ChangeDetectionStrategy, Component, signal, DestroyRef, InjectionToken, input, computed, viewChild, effect, HostListener, NgModule, Injectable, DOCUMENT, model, output, ApplicationRef, createComponent, isSignal, OutputEmitterRef, PLATFORM_ID, ViewChild, contentChild, contentChildren, afterNextRender, assertInInjectionContext, Injector, HostBinding, TemplateRef, runInInjectionContext, Directive, ChangeDetectorRef, viewChildren, ViewContainerRef, EnvironmentInjector } from '@angular/core';
3
- import { isPlatformBrowser, JsonPipe, DatePipe, NgTemplateOutlet } from '@angular/common';
2
+ import { inject, ElementRef, Renderer2, ChangeDetectionStrategy, Component, signal, DestroyRef, InjectionToken, input, computed, viewChild, effect, HostListener, NgModule, Injectable, DOCUMENT, model, output, ApplicationRef, createComponent, isSignal, OutputEmitterRef, PLATFORM_ID, ViewChild, contentChild, contentChildren, afterNextRender, Injector, HostBinding, TemplateRef, runInInjectionContext, Directive, ChangeDetectorRef, viewChildren, ViewContainerRef, EnvironmentInjector } from '@angular/core';
3
+ import { isPlatformBrowser, JsonPipe, DatePipe, isPlatformServer, NgTemplateOutlet } from '@angular/common';
4
4
  import { NgModel } from '@angular/forms';
5
5
  import { SIGNAL } from '@angular/core/primitives/signals';
6
6
 
@@ -3461,135 +3461,15 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.9", ngImpor
3461
3461
  }]
3462
3462
  }] });
3463
3463
 
3464
- function createInputSignal(input, options) {
3465
- const injector = options?.injector || (assertInInjectionContext(createInputSignal), inject(Injector));
3466
- const { debounce = 0, initialValue = undefined, transform = (value) => value, compare = (a, b) => a === b, forceType = undefined, returnPreviousValue = true, } = options || {};
3467
- const valueSignal = signal(initialValue, ...(ngDevMode ? [{ debugName: "valueSignal" }] : []));
3468
- const destroyRef = injector.get(DestroyRef);
3469
- const inputElementRef = computed(() => {
3470
- const inputElement = input()?.nativeElement;
3471
- if (!(inputElement instanceof HTMLInputElement || inputElement instanceof HTMLTextAreaElement)) {
3472
- return;
3473
- }
3474
- return createCustomInputEventListener(inputElement);
3475
- }, ...(ngDevMode ? [{ debugName: "inputElementRef" }] : []));
3476
- let isUpdating = false;
3477
- let previousValue;
3478
- let timeoutId = null;
3479
- effect(() => {
3480
- const inputElement = inputElementRef();
3481
- if (!inputElement) {
3482
- return valueSignal.set(returnPreviousValue && previousValue ? transform(previousValue) : undefined);
3483
- }
3484
- if (initialValue !== undefined && inputElement.value === '') {
3485
- valueSignal.set(initialValue);
3486
- }
3487
- else if (inputElement.value !== '') {
3488
- syncValueFromInput();
3489
- }
3490
- const inputHandler = (e) => {
3491
- if (timeoutId !== null) {
3492
- clearTimeout(timeoutId);
3493
- }
3494
- timeoutId = setTimeout(() => {
3495
- timeoutId = null;
3496
- syncValueFromInput();
3497
- }, debounce);
3498
- };
3499
- inputElement.addEventListener('input', inputHandler);
3500
- inputElement.addEventListener('inputValueChanged', inputHandler);
3501
- destroyRef.onDestroy(() => {
3502
- inputElement.removeEventListener('input', inputHandler);
3503
- inputElement.removeEventListener('inputValueChanged', inputHandler);
3504
- if (timeoutId !== null) {
3505
- clearTimeout(timeoutId);
3506
- }
3507
- });
3508
- }, { injector });
3509
- effect(() => {
3510
- const inputElement = inputElementRef();
3511
- if (!inputElement)
3512
- return;
3513
- const currentValue = valueSignal() ?? '';
3514
- let domValue = currentValue === null || currentValue === undefined ? '' : String(currentValue);
3515
- if (inputElement.value !== domValue) {
3516
- previousValue = domValue;
3517
- inputElement.value = domValue;
3518
- inputElement.dispatchEvent(new Event('input'));
3519
- }
3520
- }, { injector });
3521
- return valueSignal;
3522
- function syncValueFromInput() {
3523
- if (isUpdating)
3524
- return;
3525
- isUpdating = true;
3526
- try {
3527
- const inputElement = inputElementRef();
3528
- if (!inputElement)
3529
- return;
3530
- const inputValue = inputElement.value;
3531
- const transformedValue = forceType ? forceTransform(inputValue, forceType) : transform(inputValue);
3532
- previousValue = inputValue;
3533
- if (!compare(valueSignal(), transformedValue)) {
3534
- valueSignal.set(transformedValue);
3535
- }
3536
- }
3537
- finally {
3538
- isUpdating = false;
3539
- }
3540
- }
3541
- function createCustomInputEventListener(input) {
3542
- Object.defineProperty(input, 'value', {
3543
- configurable: true,
3544
- get() {
3545
- const descriptor = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(input), 'value'); // Use Object.getPrototypeOf
3546
- return descriptor.get.call(this);
3547
- },
3548
- set(newVal) {
3549
- const descriptor = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(input), 'value'); // Use Object.getPrototypeOf
3550
- descriptor.set.call(this, newVal);
3551
- const inputEvent = new CustomEvent('inputValueChanged', {
3552
- bubbles: true,
3553
- cancelable: true,
3554
- detail: {
3555
- value: newVal,
3556
- },
3557
- });
3558
- this.dispatchEvent(inputEvent);
3559
- return newVal;
3560
- },
3561
- });
3562
- return input;
3563
- }
3564
- function forceTransform(value, type) {
3565
- switch (type) {
3566
- case 'string':
3567
- return value.toString();
3568
- case 'number':
3569
- const num = Number(value);
3570
- return isNaN(num) ? undefined : num;
3571
- case 'boolean':
3572
- return (value.toLowerCase() === 'true'
3573
- ? true
3574
- : value.toLowerCase() === 'false'
3575
- ? false
3576
- : undefined);
3577
- default:
3578
- return value;
3579
- }
3580
- }
3581
- }
3582
-
3583
3464
  function observeFirstChild(parentEl, elementTags) {
3584
3465
  const elementSignal = signal(null, ...(ngDevMode ? [{ debugName: "elementSignal" }] : []));
3585
3466
  const _upperCaseElementTags = elementTags.map((tag) => tag.toUpperCase());
3586
3467
  const injector = inject(Injector);
3587
3468
  const destroyRef = injector.get(DestroyRef);
3588
- if (typeof MutationObserver === 'undefined')
3469
+ if (isPlatformServer(injector.get(PLATFORM_ID)) || typeof MutationObserver === 'undefined')
3589
3470
  return elementSignal.asReadonly();
3590
3471
  const initialElement = _upperCaseElementTags.find((tag) => parentEl.nativeElement.querySelector(tag));
3591
3472
  if (initialElement) {
3592
- console.log('initialElement', initialElement);
3593
3473
  elementSignal.set(new ElementRef(parentEl.nativeElement.querySelector(elementTags[0])));
3594
3474
  return elementSignal.asReadonly();
3595
3475
  }
@@ -3667,6 +3547,89 @@ function observeChildren(parentEl, elementTags) {
3667
3547
  };
3668
3548
  }
3669
3549
 
3550
+ function createFormInputSignal(formEl, elementTags = ['input', 'textarea']) {
3551
+ const elementRefSignal = formEl ? formEl : observeFirstChild(inject(ElementRef), elementTags);
3552
+ const valueSignal = signal(undefined, ...(ngDevMode ? [{ debugName: "valueSignal" }] : []));
3553
+ const injector = inject(Injector);
3554
+ const destroyRef = injector.get(DestroyRef);
3555
+ const firstInputEl = signal(null, ...(ngDevMode ? [{ debugName: "firstInputEl" }] : []));
3556
+ effect((onCleanup) => {
3557
+ const elRef = elementRefSignal();
3558
+ if (!elRef)
3559
+ return;
3560
+ const inputEl = elRef.nativeElement;
3561
+ if (!inputEl)
3562
+ return;
3563
+ createCustomInputEventListener(inputEl);
3564
+ firstInputEl.set(inputEl);
3565
+ valueSignal.set(inputEl.value ?? '');
3566
+ onCleanup(() => {
3567
+ firstInputEl.set(null);
3568
+ });
3569
+ }, { injector });
3570
+ let removeListener = null;
3571
+ effect(() => {
3572
+ const inputEl = firstInputEl();
3573
+ if (!inputEl)
3574
+ return;
3575
+ if (removeListener) {
3576
+ removeListener();
3577
+ removeListener = null;
3578
+ }
3579
+ const inputChangedListener = (event) => {
3580
+ valueSignal.set(event.detail.value);
3581
+ };
3582
+ const inputListener = (event) => {
3583
+ valueSignal.set(event.target.value);
3584
+ };
3585
+ inputEl.addEventListener('input', inputListener);
3586
+ inputEl.addEventListener('inputValueChanged', inputChangedListener);
3587
+ valueSignal.set(inputEl.value);
3588
+ removeListener = () => {
3589
+ inputEl.removeEventListener('input', inputListener);
3590
+ inputEl.removeEventListener('inputValueChanged', inputChangedListener);
3591
+ };
3592
+ destroyRef.onDestroy(() => {
3593
+ if (removeListener)
3594
+ removeListener();
3595
+ });
3596
+ }, { injector });
3597
+ effect(() => {
3598
+ const inputEl = firstInputEl();
3599
+ if (!inputEl)
3600
+ return;
3601
+ const inputValue = valueSignal();
3602
+ if (!inputValue)
3603
+ return;
3604
+ inputEl.value = inputValue;
3605
+ inputEl.dispatchEvent(new Event('input'));
3606
+ }, { injector });
3607
+ return valueSignal;
3608
+ }
3609
+ function createCustomInputEventListener(input) {
3610
+ Object.defineProperty(input, 'value', {
3611
+ configurable: true,
3612
+ get() {
3613
+ const descriptor = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(input), 'value');
3614
+ return descriptor.get.call(this);
3615
+ },
3616
+ set(newVal) {
3617
+ const descriptor = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(input), 'value');
3618
+ descriptor.set.call(this, newVal);
3619
+ const inputEvent = new CustomEvent('inputValueChanged', {
3620
+ bubbles: true,
3621
+ cancelable: true,
3622
+ detail: {
3623
+ value: newVal,
3624
+ },
3625
+ });
3626
+ this.dispatchEvent(inputEvent);
3627
+ return newVal;
3628
+ },
3629
+ });
3630
+ return input;
3631
+ }
3632
+
3670
3633
  class ShipMenu {
3671
3634
  constructor() {
3672
3635
  this.#document = inject(DOCUMENT);
@@ -3685,7 +3648,7 @@ class ShipMenu {
3685
3648
  this.optionsRef = viewChild('optionsRef', ...(ngDevMode ? [{ debugName: "optionsRef" }] : []));
3686
3649
  this.options = observeChildren(this.optionsRef, this.customOptionElementSelectors);
3687
3650
  this.optionsEl = computed(() => this.options.signal().filter((x) => !x.disabled), ...(ngDevMode ? [{ debugName: "optionsEl" }] : []));
3688
- this.inputValue = createInputSignal(this.inputRef);
3651
+ this.inputValue = createFormInputSignal(this.inputRef);
3689
3652
  this.abortController = null;
3690
3653
  this.optionsEffect = effect(() => {
3691
3654
  if (this.abortController !== null) {
@@ -6378,6 +6341,37 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.9", ngImpor
6378
6341
  }]
6379
6342
  }], propDecorators: { viewportRef: [{ type: i0.ViewChild, args: ['viewport', { isSignal: true }] }], itemElements: [{ type: i0.ViewChildren, args: ['item', { isSignal: true }] }] } });
6380
6343
 
6344
+ class ShipFormFieldExperimental {
6345
+ constructor() {
6346
+ this.firstInput = createFormInputSignal();
6347
+ this.hello = effect(() => {
6348
+ console.log('hello', this.firstInput());
6349
+ }, ...(ngDevMode ? [{ debugName: "hello" }] : []));
6350
+ }
6351
+ myClick() {
6352
+ this.firstInput.update((x) => x + 'hello');
6353
+ }
6354
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: ShipFormFieldExperimental, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
6355
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "20.3.9", type: ShipFormFieldExperimental, isStandalone: true, selector: "sh-form-field-experimental", ngImport: i0, template: `
6356
+ <ng-content></ng-content>
6357
+
6358
+ <button (click)="myClick()">hello</button>
6359
+ `, isInline: true, changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
6360
+ }
6361
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: ShipFormFieldExperimental, decorators: [{
6362
+ type: Component,
6363
+ args: [{
6364
+ selector: 'sh-form-field-experimental',
6365
+ imports: [],
6366
+ template: `
6367
+ <ng-content></ng-content>
6368
+
6369
+ <button (click)="myClick()">hello</button>
6370
+ `,
6371
+ changeDetection: ChangeDetectionStrategy.OnPush,
6372
+ }]
6373
+ }] });
6374
+
6381
6375
  class ShipFileDragDrop {
6382
6376
  constructor() {
6383
6377
  this.filesOver = signal(false, ...(ngDevMode ? [{ debugName: "filesOver" }] : []));
@@ -6731,5 +6725,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.9", ngImpor
6731
6725
  * Generated bundle index. Do not edit.
6732
6726
  */
6733
6727
 
6734
- export { GridSortable, SHIP_CONFIG, ShipAlert, ShipAlertContainer, ShipAlertModule, ShipAlertService, ShipBlueprint, ShipButton, ShipButtonGroup, ShipCard, ShipCheckbox, ShipChip, ShipColorPicker, ShipDatepicker, ShipDatepickerInput, ShipDaterangeInput, ShipDialog, ShipDialogService, ShipDivider, ShipEventCard, ShipFileDragDrop, ShipFileUpload, ShipFormField, ShipIcon, ShipInputMask, ShipList, ShipMenu, ShipPopover, ShipPreventWheel, ShipProgressBar, ShipRadio, ShipRangeSlider, ShipResize, ShipSelect, ShipSidenav, ShipSort, ShipSortable, ShipSpinner, ShipStepper, ShipStickyColumns, ShipTable, ShipTabs, ShipToggle, ShipToggleCard, ShipTooltip, ShipTooltipWrapper, ShipVirtualScroll, TEST_NODES, moveIndex, watchHostClass };
6728
+ export { GridSortable, SHIP_CONFIG, ShipAlert, ShipAlertContainer, ShipAlertModule, ShipAlertService, ShipBlueprint, ShipButton, ShipButtonGroup, ShipCard, ShipCheckbox, ShipChip, ShipColorPicker, ShipDatepicker, ShipDatepickerInput, ShipDaterangeInput, ShipDialog, ShipDialogService, ShipDivider, ShipEventCard, ShipFileDragDrop, ShipFileUpload, ShipFormField, ShipFormFieldExperimental, ShipIcon, ShipInputMask, ShipList, ShipMenu, ShipPopover, ShipPreventWheel, ShipProgressBar, ShipRadio, ShipRangeSlider, ShipResize, ShipSelect, ShipSidenav, ShipSort, ShipSortable, ShipSpinner, ShipStepper, ShipStickyColumns, ShipTable, ShipTabs, ShipToggle, ShipToggleCard, ShipTooltip, ShipTooltipWrapper, ShipVirtualScroll, TEST_NODES, moveIndex, watchHostClass };
6735
6729
  //# sourceMappingURL=ship-ui-core.mjs.map