您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

deferred-text-input-column.blade.php 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. @php
  2. use Filament\Support\Enums\Alignment;
  3. $isDisabled = $isDisabled();
  4. $state = $getState();
  5. $mask = $getMask();
  6. $batchMode = $getBatchMode();
  7. $alignment = $getAlignment() ?? Alignment::Start;
  8. if (! $alignment instanceof Alignment) {
  9. $alignment = filled($alignment) ? (Alignment::tryFrom($alignment) ?? $alignment) : null;
  10. }
  11. if (filled($mask)) {
  12. $type = 'text';
  13. } else {
  14. $type = $getType();
  15. }
  16. @endphp
  17. <div
  18. x-data="{
  19. error: undefined,
  20. isEditing: false,
  21. isLoading: false,
  22. name: @js($getName()),
  23. recordKey: @js($recordKey),
  24. state: @js($state),
  25. }"
  26. x-init="
  27. () => {
  28. Livewire.hook('commit', ({ component, commit, succeed, fail, respond }) => {
  29. succeed(({ snapshot, effect }) => {
  30. $nextTick(() => {
  31. if (component.id !== @js($this->getId())) {
  32. return
  33. }
  34. if (isEditing) {
  35. return
  36. }
  37. if (! $refs.newState) {
  38. return
  39. }
  40. let newState = $refs.newState.value.replaceAll('\\'+String.fromCharCode(34), String.fromCharCode(34))
  41. if (state === newState) {
  42. return
  43. }
  44. state = newState
  45. })
  46. })
  47. })
  48. }
  49. "
  50. {{
  51. $attributes
  52. ->merge($getExtraAttributes(), escape: false)
  53. ->class([
  54. 'fi-ta-text-input w-full min-w-48',
  55. 'px-3 py-4' => ! $isInline(),
  56. ])
  57. }}
  58. >
  59. <input
  60. type="hidden"
  61. value="{{ str($state)->replace('"', '\\"') }}"
  62. x-ref="newState"
  63. />
  64. <x-filament::input.wrapper
  65. :alpine-disabled="'isLoading || ' . \Illuminate\Support\Js::from($isDisabled)"
  66. alpine-valid="error === undefined"
  67. x-tooltip="
  68. error === undefined
  69. ? false
  70. : {
  71. content: error,
  72. theme: $store.theme,
  73. }
  74. "
  75. x-on:click.stop.prevent=""
  76. >
  77. {{-- format-ignore-start --}}
  78. <x-filament::input
  79. :disabled="$isDisabled"
  80. :input-mode="$getInputMode()"
  81. :placeholder="$getPlaceholder()"
  82. :step="$getStep()"
  83. :type="$type"
  84. :x-bind:disabled="$isDisabled ? null : 'isLoading'"
  85. x-model="state"
  86. x-on:blur="isEditing = false"
  87. x-on:focus="isEditing = true"
  88. :attributes="
  89. \Filament\Support\prepare_inherited_attributes(
  90. $getExtraInputAttributeBag()
  91. ->merge([
  92. 'x-on:change' . ($type === 'number' ? '.debounce.1s' : null) => $batchMode ? '
  93. $wire.dispatch(\'batch-column-changed\', {
  94. data: {
  95. name: name,
  96. recordKey: recordKey,
  97. value: $event.target.value
  98. }
  99. })
  100. ' : '
  101. isLoading = true
  102. const response = await $wire.updateTableColumnState(
  103. name,
  104. recordKey,
  105. $event.target.value,
  106. )
  107. error = response?.error ?? undefined
  108. if (! error) {
  109. state = response
  110. }
  111. isLoading = false
  112. ',
  113. 'x-on:keydown.enter' => $batchMode ? '$wire.dispatch(\'save-batch-changes\')' : '',
  114. 'x-mask' . ($mask instanceof \Filament\Support\RawJs ? ':dynamic' : '') => filled($mask) ? $mask : null,
  115. ])
  116. ->class([
  117. match ($alignment) {
  118. Alignment::Start => 'text-start',
  119. Alignment::Center => 'text-center',
  120. Alignment::End => 'text-end',
  121. Alignment::Left => 'text-left',
  122. Alignment::Right => 'text-right',
  123. Alignment::Justify, Alignment::Between => 'text-justify',
  124. default => $alignment,
  125. },
  126. ])
  127. )
  128. "
  129. />
  130. {{-- format-ignore-end --}}
  131. </x-filament::input.wrapper>
  132. </div>