@ship-ui/core 0.16.2 → 0.16.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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
 
@@ -533,7 +533,6 @@ class ShipDialogService {
533
533
  closed?.(arg);
534
534
  }
535
535
  return {
536
- ...this.insertedCompRef.instance,
537
536
  component: this.insertedCompRef.instance,
538
537
  close: closeAction,
539
538
  closed: this.compRef.instance.closed,
@@ -3461,135 +3460,15 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.9", ngImpor
3461
3460
  }]
3462
3461
  }] });
3463
3462
 
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
3463
  function observeFirstChild(parentEl, elementTags) {
3584
3464
  const elementSignal = signal(null, ...(ngDevMode ? [{ debugName: "elementSignal" }] : []));
3585
3465
  const _upperCaseElementTags = elementTags.map((tag) => tag.toUpperCase());
3586
3466
  const injector = inject(Injector);
3587
3467
  const destroyRef = injector.get(DestroyRef);
3588
- if (typeof MutationObserver === 'undefined')
3468
+ if (isPlatformServer(injector.get(PLATFORM_ID)) || typeof MutationObserver === 'undefined')
3589
3469
  return elementSignal.asReadonly();
3590
3470
  const initialElement = _upperCaseElementTags.find((tag) => parentEl.nativeElement.querySelector(tag));
3591
3471
  if (initialElement) {
3592
- console.log('initialElement', initialElement);
3593
3472
  elementSignal.set(new ElementRef(parentEl.nativeElement.querySelector(elementTags[0])));
3594
3473
  return elementSignal.asReadonly();
3595
3474
  }
@@ -3667,6 +3546,89 @@ function observeChildren(parentEl, elementTags) {
3667
3546
  };
3668
3547
  }
3669
3548
 
3549
+ function createFormInputSignal(formEl, elementTags = ['input', 'textarea']) {
3550
+ const elementRefSignal = formEl ? formEl : observeFirstChild(inject(ElementRef), elementTags);
3551
+ const valueSignal = signal(undefined, ...(ngDevMode ? [{ debugName: "valueSignal" }] : []));
3552
+ const injector = inject(Injector);
3553
+ const destroyRef = injector.get(DestroyRef);
3554
+ const firstInputEl = signal(null, ...(ngDevMode ? [{ debugName: "firstInputEl" }] : []));
3555
+ effect((onCleanup) => {
3556
+ const elRef = elementRefSignal();
3557
+ if (!elRef)
3558
+ return;
3559
+ const inputEl = elRef.nativeElement;
3560
+ if (!inputEl)
3561
+ return;
3562
+ createCustomInputEventListener(inputEl);
3563
+ firstInputEl.set(inputEl);
3564
+ valueSignal.set(inputEl.value ?? '');
3565
+ onCleanup(() => {
3566
+ firstInputEl.set(null);
3567
+ });
3568
+ }, { injector });
3569
+ let removeListener = null;
3570
+ effect(() => {
3571
+ const inputEl = firstInputEl();
3572
+ if (!inputEl)
3573
+ return;
3574
+ if (removeListener) {
3575
+ removeListener();
3576
+ removeListener = null;
3577
+ }
3578
+ const inputChangedListener = (event) => {
3579
+ valueSignal.set(event.detail.value);
3580
+ };
3581
+ const inputListener = (event) => {
3582
+ valueSignal.set(event.target.value);
3583
+ };
3584
+ inputEl.addEventListener('input', inputListener);
3585
+ inputEl.addEventListener('inputValueChanged', inputChangedListener);
3586
+ valueSignal.set(inputEl.value);
3587
+ removeListener = () => {
3588
+ inputEl.removeEventListener('input', inputListener);
3589
+ inputEl.removeEventListener('inputValueChanged', inputChangedListener);
3590
+ };
3591
+ destroyRef.onDestroy(() => {
3592
+ if (removeListener)
3593
+ removeListener();
3594
+ });
3595
+ }, { injector });
3596
+ effect(() => {
3597
+ const inputEl = firstInputEl();
3598
+ if (!inputEl)
3599
+ return;
3600
+ const inputValue = valueSignal();
3601
+ if (!inputValue)
3602
+ return;
3603
+ inputEl.value = inputValue;
3604
+ inputEl.dispatchEvent(new Event('input'));
3605
+ }, { injector });
3606
+ return valueSignal;
3607
+ }
3608
+ function createCustomInputEventListener(input) {
3609
+ Object.defineProperty(input, 'value', {
3610
+ configurable: true,
3611
+ get() {
3612
+ const descriptor = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(input), 'value');
3613
+ return descriptor.get.call(this);
3614
+ },
3615
+ set(newVal) {
3616
+ const descriptor = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(input), 'value');
3617
+ descriptor.set.call(this, newVal);
3618
+ const inputEvent = new CustomEvent('inputValueChanged', {
3619
+ bubbles: true,
3620
+ cancelable: true,
3621
+ detail: {
3622
+ value: newVal,
3623
+ },
3624
+ });
3625
+ this.dispatchEvent(inputEvent);
3626
+ return newVal;
3627
+ },
3628
+ });
3629
+ return input;
3630
+ }
3631
+
3670
3632
  class ShipMenu {
3671
3633
  constructor() {
3672
3634
  this.#document = inject(DOCUMENT);
@@ -3685,7 +3647,7 @@ class ShipMenu {
3685
3647
  this.optionsRef = viewChild('optionsRef', ...(ngDevMode ? [{ debugName: "optionsRef" }] : []));
3686
3648
  this.options = observeChildren(this.optionsRef, this.customOptionElementSelectors);
3687
3649
  this.optionsEl = computed(() => this.options.signal().filter((x) => !x.disabled), ...(ngDevMode ? [{ debugName: "optionsEl" }] : []));
3688
- this.inputValue = createInputSignal(this.inputRef);
3650
+ this.inputValue = createFormInputSignal(this.inputRef);
3689
3651
  this.abortController = null;
3690
3652
  this.optionsEffect = effect(() => {
3691
3653
  if (this.abortController !== null) {
@@ -6378,6 +6340,37 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.9", ngImpor
6378
6340
  }]
6379
6341
  }], propDecorators: { viewportRef: [{ type: i0.ViewChild, args: ['viewport', { isSignal: true }] }], itemElements: [{ type: i0.ViewChildren, args: ['item', { isSignal: true }] }] } });
6380
6342
 
6343
+ class ShipFormFieldExperimental {
6344
+ constructor() {
6345
+ this.firstInput = createFormInputSignal();
6346
+ this.hello = effect(() => {
6347
+ console.log('hello', this.firstInput());
6348
+ }, ...(ngDevMode ? [{ debugName: "hello" }] : []));
6349
+ }
6350
+ myClick() {
6351
+ this.firstInput.update((x) => x + 'hello');
6352
+ }
6353
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: ShipFormFieldExperimental, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
6354
+ 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: `
6355
+ <ng-content></ng-content>
6356
+
6357
+ <button (click)="myClick()">hello</button>
6358
+ `, isInline: true, changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
6359
+ }
6360
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: ShipFormFieldExperimental, decorators: [{
6361
+ type: Component,
6362
+ args: [{
6363
+ selector: 'sh-form-field-experimental',
6364
+ imports: [],
6365
+ template: `
6366
+ <ng-content></ng-content>
6367
+
6368
+ <button (click)="myClick()">hello</button>
6369
+ `,
6370
+ changeDetection: ChangeDetectionStrategy.OnPush,
6371
+ }]
6372
+ }] });
6373
+
6381
6374
  class ShipFileDragDrop {
6382
6375
  constructor() {
6383
6376
  this.filesOver = signal(false, ...(ngDevMode ? [{ debugName: "filesOver" }] : []));
@@ -6731,5 +6724,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.9", ngImpor
6731
6724
  * Generated bundle index. Do not edit.
6732
6725
  */
6733
6726
 
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 };
6727
+ 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
6728
  //# sourceMappingURL=ship-ui-core.mjs.map