Phase 0: Fundament für Inhaus
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 1m14s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 1m12s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 1m7s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 1m19s
CI / PHP 8.3 / mysql:8.0 (pull_request) Successful in 1m32s
CI / PHP 8.4 / mysql:8.0 (pull_request) Successful in 1m22s
CI / PHP 8.4 / mysql:8.4 (pull_request) Successful in 1m32s
CI / PHP 8.3 / mysql:8.4 (pull_request) Successful in 1m35s
CI / Build-Artefakte aktuell (pull_request) Failing after 1m7s
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 1m14s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 1m12s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 1m7s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 1m19s
CI / PHP 8.3 / mysql:8.0 (pull_request) Successful in 1m32s
CI / PHP 8.4 / mysql:8.0 (pull_request) Successful in 1m22s
CI / PHP 8.4 / mysql:8.4 (pull_request) Successful in 1m32s
CI / PHP 8.3 / mysql:8.4 (pull_request) Successful in 1m35s
CI / Build-Artefakte aktuell (pull_request) Failing after 1m7s
- Laravel 13 mit Filament 5 (Admin), Inertia 3 + Vue 3 + Vuetify 4 (Material 3) - Anmeldung über Fortify (Login, Passwort vergessen/ändern), keine Selbstregistrierung - Profil mit Profilbild (WebP in festen Größen), Personenseiten, Header mit Avatar-Menü - Material-3-Farbschema aus der Primärfarbe, hell/dunkel/System pro Person - Basis-Branding (Portalname, Logo, Primärfarbe) im Admin unter „Erscheinungsbild“ - Benutzerverwaltung im Admin, Zugang vorläufig über is_admin - vendor/ (ohne Dev-Pakete) und Frontend-Build mitversioniert, Dev-Pakete in vendor-dev/ - PHPUnit-Tests gegen MySQL/MariaDB, Forgejo-CI-Matrix, Docker-Entwicklungsumgebung - VERSION, CHANGELOG.md und CONTRIBUTING.md mit Release-Ablauf Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
7197eaebf2
commit
9c0f8de791
15771 changed files with 1564103 additions and 5 deletions
117
vendor/filament/forms/resources/js/components/checkbox-list.js
vendored
Normal file
117
vendor/filament/forms/resources/js/components/checkbox-list.js
vendored
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
export default function checkboxListFormComponent({ livewireId }) {
|
||||
return {
|
||||
areAllCheckboxesChecked: false,
|
||||
|
||||
checkboxListOptions: [],
|
||||
|
||||
search: '',
|
||||
|
||||
unsubscribeLivewireHook: null,
|
||||
|
||||
visibleCheckboxListOptions: [],
|
||||
|
||||
init() {
|
||||
this.checkboxListOptions = Array.from(
|
||||
this.$root.querySelectorAll('.fi-fo-checkbox-list-option'),
|
||||
)
|
||||
|
||||
this.updateVisibleCheckboxListOptions()
|
||||
|
||||
this.$nextTick(() => {
|
||||
this.checkIfAllCheckboxesAreChecked()
|
||||
})
|
||||
|
||||
this.unsubscribeLivewireHook = Livewire.interceptMessage(
|
||||
({ message, onSuccess }) => {
|
||||
onSuccess(() => {
|
||||
this.$nextTick(() => {
|
||||
if (message.component.id !== livewireId) {
|
||||
return
|
||||
}
|
||||
|
||||
this.checkboxListOptions = Array.from(
|
||||
this.$root.querySelectorAll(
|
||||
'.fi-fo-checkbox-list-option',
|
||||
),
|
||||
)
|
||||
|
||||
this.updateVisibleCheckboxListOptions()
|
||||
|
||||
this.checkIfAllCheckboxesAreChecked()
|
||||
})
|
||||
})
|
||||
},
|
||||
)
|
||||
|
||||
this.$watch('search', () => {
|
||||
this.updateVisibleCheckboxListOptions()
|
||||
this.checkIfAllCheckboxesAreChecked()
|
||||
})
|
||||
},
|
||||
|
||||
checkIfAllCheckboxesAreChecked() {
|
||||
this.areAllCheckboxesChecked =
|
||||
this.visibleCheckboxListOptions.length ===
|
||||
this.visibleCheckboxListOptions.filter((checkboxLabel) =>
|
||||
checkboxLabel.querySelector(
|
||||
'input[type=checkbox]:checked, input[type=checkbox]:disabled',
|
||||
),
|
||||
).length
|
||||
},
|
||||
|
||||
toggleAllCheckboxes() {
|
||||
this.checkIfAllCheckboxesAreChecked()
|
||||
|
||||
const inverseAreAllCheckboxesChecked = !this.areAllCheckboxesChecked
|
||||
|
||||
this.visibleCheckboxListOptions.forEach((checkboxLabel) => {
|
||||
const checkbox = checkboxLabel.querySelector(
|
||||
'input[type=checkbox]',
|
||||
)
|
||||
|
||||
if (checkbox.disabled) {
|
||||
return
|
||||
}
|
||||
|
||||
if (checkbox.checked === inverseAreAllCheckboxesChecked) {
|
||||
return
|
||||
}
|
||||
|
||||
checkbox.checked = inverseAreAllCheckboxesChecked
|
||||
checkbox.dispatchEvent(new Event('change'))
|
||||
})
|
||||
|
||||
this.areAllCheckboxesChecked = inverseAreAllCheckboxesChecked
|
||||
},
|
||||
|
||||
updateVisibleCheckboxListOptions() {
|
||||
this.visibleCheckboxListOptions = this.checkboxListOptions.filter(
|
||||
(checkboxListItem) => {
|
||||
if (['', null, undefined].includes(this.search)) {
|
||||
return true
|
||||
}
|
||||
|
||||
if (
|
||||
checkboxListItem
|
||||
.querySelector('.fi-fo-checkbox-list-option-label')
|
||||
?.innerText.toLowerCase()
|
||||
.includes(this.search.toLowerCase())
|
||||
) {
|
||||
return true
|
||||
}
|
||||
|
||||
return checkboxListItem
|
||||
.querySelector(
|
||||
'.fi-fo-checkbox-list-option-description',
|
||||
)
|
||||
?.innerText.toLowerCase()
|
||||
.includes(this.search.toLowerCase())
|
||||
},
|
||||
)
|
||||
},
|
||||
|
||||
destroy() {
|
||||
this.unsubscribeLivewireHook?.()
|
||||
},
|
||||
}
|
||||
}
|
||||
162
vendor/filament/forms/resources/js/components/code-editor.js
vendored
Normal file
162
vendor/filament/forms/resources/js/components/code-editor.js
vendored
Normal file
|
|
@ -0,0 +1,162 @@
|
|||
import { EditorState, Compartment } from '@codemirror/state'
|
||||
import { EditorView, basicSetup } from 'codemirror-v6'
|
||||
import { indentWithTab } from '@codemirror/commands'
|
||||
import { oneDark } from '@codemirror/theme-one-dark'
|
||||
import { keymap } from '@codemirror/view'
|
||||
|
||||
import { cpp } from '@codemirror/lang-cpp'
|
||||
import { css } from '@codemirror/lang-css'
|
||||
import { go } from '@codemirror/lang-go'
|
||||
import { html } from '@codemirror/lang-html'
|
||||
import { java } from '@codemirror/lang-java'
|
||||
import { javascript } from '@codemirror/lang-javascript'
|
||||
import { json } from '@codemirror/lang-json'
|
||||
import { markdown } from '@codemirror/lang-markdown'
|
||||
import { php } from '@codemirror/lang-php'
|
||||
import { python } from '@codemirror/lang-python'
|
||||
import { sql } from '@codemirror/lang-sql'
|
||||
import { xml } from '@codemirror/lang-xml'
|
||||
import { yaml } from '@codemirror/lang-yaml'
|
||||
|
||||
export default function codeEditorFormComponent({
|
||||
canWrap,
|
||||
isDisabled,
|
||||
isLive,
|
||||
isLiveDebounced,
|
||||
isLiveOnBlur,
|
||||
label,
|
||||
liveDebounce,
|
||||
language,
|
||||
state,
|
||||
}) {
|
||||
return {
|
||||
editor: null,
|
||||
themeCompartment: new Compartment(),
|
||||
isDocChanged: false,
|
||||
state,
|
||||
|
||||
init() {
|
||||
const languageExtension = this.getLanguageExtension()
|
||||
|
||||
const debouncedCommit = Alpine.debounce(
|
||||
() => this.$wire.commit(),
|
||||
liveDebounce ?? 300,
|
||||
)
|
||||
|
||||
this.editor = new EditorView({
|
||||
parent: this.$refs.editor,
|
||||
state: EditorState.create({
|
||||
doc: this.state,
|
||||
extensions: [
|
||||
basicSetup,
|
||||
keymap.of([indentWithTab]),
|
||||
...(label
|
||||
? [
|
||||
EditorView.contentAttributes.of({
|
||||
'aria-label': label,
|
||||
}),
|
||||
]
|
||||
: []),
|
||||
...(canWrap ? [EditorView.lineWrapping] : []),
|
||||
EditorState.readOnly.of(isDisabled),
|
||||
EditorView.editable.of(!isDisabled),
|
||||
EditorView.updateListener.of((viewUpdate) => {
|
||||
if (!viewUpdate.docChanged) {
|
||||
return
|
||||
}
|
||||
this.isDocChanged = true
|
||||
this.state = viewUpdate.state.doc.toString()
|
||||
if (!isLiveOnBlur && (isLive || isLiveDebounced)) {
|
||||
debouncedCommit()
|
||||
}
|
||||
}),
|
||||
EditorView.domEventHandlers({
|
||||
blur: (event, view) => {
|
||||
if (isLiveOnBlur && this.isDocChanged) {
|
||||
this.$wire.$commit()
|
||||
}
|
||||
},
|
||||
}),
|
||||
...(languageExtension ? [languageExtension] : []),
|
||||
this.themeCompartment.of(this.getThemeExtensions()),
|
||||
],
|
||||
}),
|
||||
})
|
||||
|
||||
this.$watch('state', () => {
|
||||
if (this.state === undefined) {
|
||||
return
|
||||
}
|
||||
|
||||
if (this.editor.state.doc.toString() === this.state) {
|
||||
return
|
||||
}
|
||||
|
||||
this.editor.dispatch({
|
||||
changes: {
|
||||
from: 0,
|
||||
to: this.editor.state.doc.length,
|
||||
insert: this.state,
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
this.themeObserver = new MutationObserver(() => {
|
||||
this.editor.dispatch({
|
||||
effects: this.themeCompartment.reconfigure(
|
||||
this.getThemeExtensions(),
|
||||
),
|
||||
})
|
||||
})
|
||||
|
||||
this.themeObserver.observe(document.documentElement, {
|
||||
attributes: true,
|
||||
attributeFilter: ['class'],
|
||||
})
|
||||
},
|
||||
|
||||
isDarkMode() {
|
||||
return document.documentElement.classList.contains('dark')
|
||||
},
|
||||
|
||||
getThemeExtensions() {
|
||||
return this.isDarkMode() ? [oneDark] : []
|
||||
},
|
||||
|
||||
getLanguageExtension() {
|
||||
if (!language) {
|
||||
return null
|
||||
}
|
||||
|
||||
const extensions = {
|
||||
cpp,
|
||||
css,
|
||||
go,
|
||||
html,
|
||||
java,
|
||||
javascript,
|
||||
json,
|
||||
markdown,
|
||||
php,
|
||||
python,
|
||||
sql,
|
||||
xml,
|
||||
yaml,
|
||||
}
|
||||
|
||||
return extensions[language]?.() || null
|
||||
},
|
||||
|
||||
destroy() {
|
||||
if (this.themeObserver) {
|
||||
this.themeObserver.disconnect()
|
||||
this.themeObserver = null
|
||||
}
|
||||
|
||||
if (this.editor) {
|
||||
this.editor.destroy()
|
||||
this.editor = null
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
124
vendor/filament/forms/resources/js/components/color-picker.js
vendored
Normal file
124
vendor/filament/forms/resources/js/components/color-picker.js
vendored
Normal file
|
|
@ -0,0 +1,124 @@
|
|||
import 'vanilla-colorful/hex-color-picker.js'
|
||||
import 'vanilla-colorful/hsl-string-color-picker.js'
|
||||
import 'vanilla-colorful/rgb-string-color-picker.js'
|
||||
import 'vanilla-colorful/rgba-string-color-picker.js'
|
||||
|
||||
export default function colorPickerFormComponent({
|
||||
isAutofocused,
|
||||
isDisabled,
|
||||
isLive,
|
||||
isLiveDebounced,
|
||||
isLiveOnBlur,
|
||||
liveDebounce,
|
||||
state,
|
||||
}) {
|
||||
let isDestroyed = false
|
||||
|
||||
return {
|
||||
state,
|
||||
|
||||
panelObserver: null,
|
||||
|
||||
init() {
|
||||
if (!(this.state === null || this.state === '')) {
|
||||
this.setState(this.state)
|
||||
}
|
||||
|
||||
if (isAutofocused) {
|
||||
this.togglePanelVisibility(this.$refs.input)
|
||||
}
|
||||
|
||||
this.$watch(
|
||||
'state',
|
||||
Alpine.debounce((value) => {
|
||||
if (isDestroyed) {
|
||||
return
|
||||
}
|
||||
|
||||
if (!CSS.supports('color', value)) {
|
||||
return
|
||||
}
|
||||
|
||||
this.$refs.picker.color = value
|
||||
}, 200),
|
||||
)
|
||||
|
||||
this.$refs.input.addEventListener('change', (event) => {
|
||||
this.setState(event.target.value)
|
||||
})
|
||||
|
||||
this.$refs.panel.addEventListener('color-changed', (event) => {
|
||||
this.setState(event.detail.value)
|
||||
|
||||
if (isLiveOnBlur || !(isLive || isLiveDebounced)) {
|
||||
return
|
||||
}
|
||||
|
||||
setTimeout(
|
||||
() => {
|
||||
if (isDestroyed) {
|
||||
return
|
||||
}
|
||||
|
||||
if (this.state !== event.detail.value) {
|
||||
return
|
||||
}
|
||||
|
||||
this.commitState()
|
||||
},
|
||||
isLiveDebounced ? liveDebounce : 250,
|
||||
)
|
||||
})
|
||||
|
||||
if (isLive || isLiveDebounced || isLiveOnBlur) {
|
||||
this.panelObserver = new MutationObserver(() =>
|
||||
this.isOpen() ? null : this.commitState(),
|
||||
)
|
||||
|
||||
this.panelObserver.observe(this.$refs.panel, {
|
||||
attributes: true,
|
||||
childList: true,
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
togglePanelVisibility() {
|
||||
if (isDisabled) {
|
||||
return
|
||||
}
|
||||
|
||||
this.$refs.panel.toggle(this.$refs.input)
|
||||
},
|
||||
|
||||
setState(value) {
|
||||
this.state = value
|
||||
|
||||
this.$refs.input.value = value
|
||||
this.$refs.picker.color = value
|
||||
},
|
||||
|
||||
isOpen() {
|
||||
return this.$refs.panel.style.display === 'block'
|
||||
},
|
||||
|
||||
commitState() {
|
||||
if (isDestroyed) {
|
||||
return
|
||||
}
|
||||
|
||||
if (
|
||||
JSON.stringify(this.$wire.__instance.canonical) ===
|
||||
JSON.stringify(this.$wire.__instance.ephemeral)
|
||||
) {
|
||||
return
|
||||
}
|
||||
|
||||
this.$wire.$commit()
|
||||
},
|
||||
|
||||
destroy() {
|
||||
isDestroyed = true
|
||||
this.panelObserver?.disconnect()
|
||||
},
|
||||
}
|
||||
}
|
||||
580
vendor/filament/forms/resources/js/components/date-time-picker.js
vendored
Normal file
580
vendor/filament/forms/resources/js/components/date-time-picker.js
vendored
Normal file
|
|
@ -0,0 +1,580 @@
|
|||
import dayjs from 'dayjs/esm'
|
||||
import advancedFormat from 'dayjs/plugin/advancedFormat'
|
||||
import customParseFormat from 'dayjs/plugin/customParseFormat'
|
||||
import localeData from 'dayjs/plugin/localeData'
|
||||
import timezone from 'dayjs/plugin/timezone'
|
||||
import utc from 'dayjs/plugin/utc'
|
||||
|
||||
dayjs.extend(advancedFormat)
|
||||
dayjs.extend(customParseFormat)
|
||||
dayjs.extend(localeData)
|
||||
dayjs.extend(timezone)
|
||||
dayjs.extend(utc)
|
||||
|
||||
window.dayjs = dayjs
|
||||
|
||||
export default function dateTimePickerFormComponent({
|
||||
defaultFocusedDate,
|
||||
displayFormat,
|
||||
firstDayOfWeek,
|
||||
isAutofocused,
|
||||
locale,
|
||||
shouldCloseOnDateSelection,
|
||||
state,
|
||||
}) {
|
||||
const timezone = dayjs.tz.guess()
|
||||
|
||||
return {
|
||||
daysInFocusedMonth: [],
|
||||
|
||||
displayText: '',
|
||||
|
||||
emptyDaysInFocusedMonth: [],
|
||||
|
||||
focusedDate: null,
|
||||
|
||||
focusedMonth: null,
|
||||
|
||||
focusedYear: null,
|
||||
|
||||
hasValidationMessage: false,
|
||||
|
||||
hour: null,
|
||||
|
||||
isClearingState: false,
|
||||
|
||||
minute: null,
|
||||
|
||||
second: null,
|
||||
|
||||
state,
|
||||
|
||||
defaultFocusedDate,
|
||||
|
||||
dayLabels: [],
|
||||
|
||||
months: [],
|
||||
|
||||
init() {
|
||||
dayjs.locale(locales[locale] ?? locales['en'])
|
||||
|
||||
this.$nextTick(() => {
|
||||
this.focusedDate ??= (
|
||||
this.getDefaultFocusedDate() ?? dayjs()
|
||||
).tz(timezone)
|
||||
this.focusedMonth ??= this.focusedDate.month()
|
||||
this.focusedYear ??= this.focusedDate.year()
|
||||
})
|
||||
|
||||
let date =
|
||||
this.getSelectedDate() ??
|
||||
this.getDefaultFocusedDate() ??
|
||||
dayjs().tz(timezone).hour(0).minute(0).second(0)
|
||||
|
||||
if (this.getMaxDate() !== null && date.isAfter(this.getMaxDate())) {
|
||||
date = null
|
||||
} else if (
|
||||
this.getMinDate() !== null &&
|
||||
date.isBefore(this.getMinDate())
|
||||
) {
|
||||
date = null
|
||||
}
|
||||
|
||||
this.hour = date?.hour() ?? 0
|
||||
this.minute = date?.minute() ?? 0
|
||||
this.second = date?.second() ?? 0
|
||||
|
||||
this.setDisplayText()
|
||||
this.setMonths()
|
||||
this.setDayLabels()
|
||||
|
||||
if (isAutofocused) {
|
||||
this.$nextTick(() =>
|
||||
this.togglePanelVisibility(this.$refs.button),
|
||||
)
|
||||
}
|
||||
|
||||
this.$watch('focusedMonth', () => {
|
||||
this.focusedMonth = +this.focusedMonth
|
||||
|
||||
if (this.focusedDate.month() === this.focusedMonth) {
|
||||
return
|
||||
}
|
||||
|
||||
this.focusedDate = this.focusedDate.month(this.focusedMonth)
|
||||
})
|
||||
|
||||
this.$watch('focusedYear', () => {
|
||||
if (this.focusedYear?.length > 4) {
|
||||
this.focusedYear = this.focusedYear.substring(0, 4)
|
||||
}
|
||||
|
||||
if (!this.focusedYear || this.focusedYear?.length !== 4) {
|
||||
return
|
||||
}
|
||||
|
||||
let year = +this.focusedYear
|
||||
|
||||
if (!Number.isInteger(year)) {
|
||||
year = dayjs().tz(timezone).year()
|
||||
|
||||
this.focusedYear = year
|
||||
}
|
||||
|
||||
if (this.focusedDate.year() === year) {
|
||||
return
|
||||
}
|
||||
|
||||
this.focusedDate = this.focusedDate.year(year)
|
||||
})
|
||||
|
||||
this.$watch('focusedDate', () => {
|
||||
let month = this.focusedDate.month()
|
||||
let year = this.focusedDate.year()
|
||||
|
||||
if (this.focusedMonth !== month) {
|
||||
this.focusedMonth = month
|
||||
}
|
||||
|
||||
if (this.focusedYear !== year) {
|
||||
this.focusedYear = year
|
||||
}
|
||||
|
||||
this.setupDaysGrid()
|
||||
})
|
||||
|
||||
this.$watch('hour', () => {
|
||||
let hour = +this.hour
|
||||
|
||||
if (!Number.isInteger(hour)) {
|
||||
this.hour = 0
|
||||
} else if (hour > 23) {
|
||||
this.hour = 0
|
||||
} else if (hour < 0) {
|
||||
this.hour = 23
|
||||
} else {
|
||||
this.hour = hour
|
||||
}
|
||||
|
||||
if (this.isClearingState) {
|
||||
return
|
||||
}
|
||||
|
||||
let date = this.getSelectedDate() ?? this.focusedDate
|
||||
|
||||
this.setState(date.hour(this.hour ?? 0))
|
||||
})
|
||||
|
||||
this.$watch('minute', () => {
|
||||
let minute = +this.minute
|
||||
|
||||
if (!Number.isInteger(minute)) {
|
||||
this.minute = 0
|
||||
} else if (minute > 59) {
|
||||
this.minute = 0
|
||||
} else if (minute < 0) {
|
||||
this.minute = 59
|
||||
} else {
|
||||
this.minute = minute
|
||||
}
|
||||
|
||||
if (this.isClearingState) {
|
||||
return
|
||||
}
|
||||
|
||||
let date = this.getSelectedDate() ?? this.focusedDate
|
||||
|
||||
this.setState(date.minute(this.minute ?? 0))
|
||||
})
|
||||
|
||||
this.$watch('second', () => {
|
||||
let second = +this.second
|
||||
|
||||
if (!Number.isInteger(second)) {
|
||||
this.second = 0
|
||||
} else if (second > 59) {
|
||||
this.second = 0
|
||||
} else if (second < 0) {
|
||||
this.second = 59
|
||||
} else {
|
||||
this.second = second
|
||||
}
|
||||
|
||||
if (this.isClearingState) {
|
||||
return
|
||||
}
|
||||
|
||||
let date = this.getSelectedDate() ?? this.focusedDate
|
||||
|
||||
this.setState(date.second(this.second ?? 0))
|
||||
})
|
||||
|
||||
this.$watch('state', () => {
|
||||
if (this.state === undefined) {
|
||||
return
|
||||
}
|
||||
|
||||
let date = this.getSelectedDate()
|
||||
|
||||
if (date === null) {
|
||||
this.clearState()
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if (
|
||||
this.getMaxDate() !== null &&
|
||||
date?.isAfter(this.getMaxDate())
|
||||
) {
|
||||
date = null
|
||||
}
|
||||
if (
|
||||
this.getMinDate() !== null &&
|
||||
date?.isBefore(this.getMinDate())
|
||||
) {
|
||||
date = null
|
||||
}
|
||||
|
||||
const newHour = date?.hour() ?? 0
|
||||
if (this.hour !== newHour) {
|
||||
this.hour = newHour
|
||||
}
|
||||
|
||||
const newMinute = date?.minute() ?? 0
|
||||
if (this.minute !== newMinute) {
|
||||
this.minute = newMinute
|
||||
}
|
||||
|
||||
const newSecond = date?.second() ?? 0
|
||||
if (this.second !== newSecond) {
|
||||
this.second = newSecond
|
||||
}
|
||||
|
||||
this.setDisplayText()
|
||||
})
|
||||
},
|
||||
|
||||
checkTimeInputValidity(event) {
|
||||
const el = event.target
|
||||
if (this.isOpen() && !el.validity.valid) {
|
||||
el.reportValidity()
|
||||
}
|
||||
},
|
||||
|
||||
clearState() {
|
||||
this.isClearingState = true
|
||||
|
||||
this.setState(null)
|
||||
|
||||
this.hour = 0
|
||||
this.minute = 0
|
||||
this.second = 0
|
||||
|
||||
this.$nextTick(() => (this.isClearingState = false))
|
||||
},
|
||||
|
||||
dateIsDisabled(date) {
|
||||
if (
|
||||
this.$refs?.disabledDates &&
|
||||
JSON.parse(this.$refs.disabledDates.value ?? []).some(
|
||||
(disabledDate) => {
|
||||
disabledDate = dayjs(disabledDate)
|
||||
|
||||
if (!disabledDate.isValid()) {
|
||||
return false
|
||||
}
|
||||
|
||||
return disabledDate.isSame(date, 'day')
|
||||
},
|
||||
)
|
||||
) {
|
||||
return true
|
||||
}
|
||||
|
||||
if (this.getMaxDate() && date.isAfter(this.getMaxDate(), 'day')) {
|
||||
return true
|
||||
}
|
||||
if (this.getMinDate() && date.isBefore(this.getMinDate(), 'day')) {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
},
|
||||
|
||||
dayIsDisabled(day) {
|
||||
this.focusedDate ??= dayjs().tz(timezone)
|
||||
|
||||
return this.dateIsDisabled(this.focusedDate.date(day))
|
||||
},
|
||||
|
||||
dayIsSelected(day) {
|
||||
let selectedDate = this.getSelectedDate()
|
||||
|
||||
if (selectedDate === null) {
|
||||
return false
|
||||
}
|
||||
|
||||
this.focusedDate ??= dayjs().tz(timezone)
|
||||
|
||||
return (
|
||||
selectedDate.date() === day &&
|
||||
selectedDate.month() === this.focusedDate.month() &&
|
||||
selectedDate.year() === this.focusedDate.year()
|
||||
)
|
||||
},
|
||||
|
||||
dayIsToday(day) {
|
||||
let date = dayjs().tz(timezone)
|
||||
this.focusedDate ??= date
|
||||
|
||||
return (
|
||||
date.date() === day &&
|
||||
date.month() === this.focusedDate.month() &&
|
||||
date.year() === this.focusedDate.year()
|
||||
)
|
||||
},
|
||||
|
||||
focusPreviousDay() {
|
||||
this.focusedDate ??= dayjs().tz(timezone)
|
||||
|
||||
this.focusedDate = this.focusedDate.subtract(1, 'day')
|
||||
},
|
||||
|
||||
focusPreviousWeek() {
|
||||
this.focusedDate ??= dayjs().tz(timezone)
|
||||
|
||||
this.focusedDate = this.focusedDate.subtract(1, 'week')
|
||||
},
|
||||
|
||||
focusNextDay() {
|
||||
this.focusedDate ??= dayjs().tz(timezone)
|
||||
|
||||
this.focusedDate = this.focusedDate.add(1, 'day')
|
||||
},
|
||||
|
||||
focusNextWeek() {
|
||||
this.focusedDate ??= dayjs().tz(timezone)
|
||||
|
||||
this.focusedDate = this.focusedDate.add(1, 'week')
|
||||
},
|
||||
|
||||
getDayLabels() {
|
||||
const labels = dayjs.weekdaysShort()
|
||||
|
||||
if (firstDayOfWeek === 0) {
|
||||
return labels
|
||||
}
|
||||
|
||||
return [
|
||||
...labels.slice(firstDayOfWeek),
|
||||
...labels.slice(0, firstDayOfWeek),
|
||||
]
|
||||
},
|
||||
|
||||
getMaxDate() {
|
||||
let date = dayjs(this.$refs.maxDate?.value)
|
||||
|
||||
return date.isValid() ? date : null
|
||||
},
|
||||
|
||||
getMinDate() {
|
||||
let date = dayjs(this.$refs.minDate?.value)
|
||||
|
||||
return date.isValid() ? date : null
|
||||
},
|
||||
|
||||
getSelectedDate() {
|
||||
if (this.state === undefined) {
|
||||
return null
|
||||
}
|
||||
|
||||
if (this.state === null) {
|
||||
return null
|
||||
}
|
||||
|
||||
let date = dayjs(this.state)
|
||||
|
||||
if (!date.isValid()) {
|
||||
return null
|
||||
}
|
||||
|
||||
return date
|
||||
},
|
||||
|
||||
getDefaultFocusedDate() {
|
||||
if (this.defaultFocusedDate === null) {
|
||||
return null
|
||||
}
|
||||
|
||||
let defaultFocusedDate = dayjs(this.defaultFocusedDate)
|
||||
|
||||
if (!defaultFocusedDate.isValid()) {
|
||||
return null
|
||||
}
|
||||
|
||||
return defaultFocusedDate
|
||||
},
|
||||
|
||||
togglePanelVisibility() {
|
||||
if (!this.isOpen()) {
|
||||
this.focusedDate =
|
||||
this.getSelectedDate() ??
|
||||
this.focusedDate ??
|
||||
this.getMinDate() ??
|
||||
dayjs().tz(timezone)
|
||||
|
||||
this.setupDaysGrid()
|
||||
}
|
||||
|
||||
this.$refs.panel.toggle(this.$refs.button)
|
||||
},
|
||||
|
||||
selectDate(day = null) {
|
||||
if (day) {
|
||||
this.setFocusedDay(day)
|
||||
}
|
||||
|
||||
this.focusedDate ??= dayjs().tz(timezone)
|
||||
|
||||
this.setState(this.focusedDate)
|
||||
|
||||
if (shouldCloseOnDateSelection) {
|
||||
this.togglePanelVisibility()
|
||||
}
|
||||
},
|
||||
|
||||
setDisplayText() {
|
||||
this.displayText = this.getSelectedDate()
|
||||
? this.getSelectedDate().format(displayFormat)
|
||||
: ''
|
||||
},
|
||||
|
||||
setMonths() {
|
||||
this.months = dayjs.months()
|
||||
},
|
||||
|
||||
setDayLabels() {
|
||||
this.dayLabels = this.getDayLabels()
|
||||
},
|
||||
|
||||
setupDaysGrid() {
|
||||
this.focusedDate ??= dayjs().tz(timezone)
|
||||
|
||||
this.emptyDaysInFocusedMonth = Array.from(
|
||||
{
|
||||
length: this.focusedDate.date(8 - firstDayOfWeek).day(),
|
||||
},
|
||||
(_, i) => i + 1,
|
||||
)
|
||||
|
||||
this.daysInFocusedMonth = Array.from(
|
||||
{
|
||||
length: this.focusedDate.daysInMonth(),
|
||||
},
|
||||
(_, i) => i + 1,
|
||||
)
|
||||
},
|
||||
|
||||
setFocusedDay(day) {
|
||||
this.focusedDate = (this.focusedDate ?? dayjs().tz(timezone)).date(
|
||||
day,
|
||||
)
|
||||
},
|
||||
|
||||
setState(date) {
|
||||
if (date === null) {
|
||||
this.state = null
|
||||
this.setDisplayText()
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if (this.dateIsDisabled(date)) {
|
||||
return
|
||||
}
|
||||
|
||||
this.state = date
|
||||
.hour(this.hour ?? 0)
|
||||
.minute(this.minute ?? 0)
|
||||
.second(this.second ?? 0)
|
||||
.format('YYYY-MM-DD HH:mm:ss')
|
||||
|
||||
this.setDisplayText()
|
||||
},
|
||||
|
||||
timeInputInvalid(event) {
|
||||
const el = event.target
|
||||
|
||||
if (!this.isOpen()) {
|
||||
event.preventDefault()
|
||||
this.togglePanelVisibility()
|
||||
}
|
||||
|
||||
if (!this.hasValidationMessage) {
|
||||
this.hasValidationMessage = true
|
||||
|
||||
this.$nextTick(() => {
|
||||
el.reportValidity()
|
||||
this.hasValidationMessage = false
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
isOpen() {
|
||||
return this.$refs.panel?.style.display === 'block'
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
const locales = {
|
||||
am: require('dayjs/locale/am'),
|
||||
ar: require('dayjs/locale/ar'),
|
||||
bs: require('dayjs/locale/bs'),
|
||||
ca: require('dayjs/locale/ca'),
|
||||
ckb: require('dayjs/locale/ku'),
|
||||
cs: require('dayjs/locale/cs'),
|
||||
cy: require('dayjs/locale/cy'),
|
||||
da: require('dayjs/locale/da'),
|
||||
de: require('dayjs/locale/de'),
|
||||
el: require('dayjs/locale/el'),
|
||||
en: require('dayjs/locale/en'),
|
||||
es: require('dayjs/locale/es'),
|
||||
et: require('dayjs/locale/et'),
|
||||
fa: require('dayjs/locale/fa'),
|
||||
fi: require('dayjs/locale/fi'),
|
||||
fr: require('dayjs/locale/fr'),
|
||||
he: require('dayjs/locale/he'),
|
||||
hi: require('dayjs/locale/hi'),
|
||||
hu: require('dayjs/locale/hu'),
|
||||
hy: require('dayjs/locale/hy-am'),
|
||||
id: require('dayjs/locale/id'),
|
||||
it: require('dayjs/locale/it'),
|
||||
ja: require('dayjs/locale/ja'),
|
||||
ka: require('dayjs/locale/ka'),
|
||||
km: require('dayjs/locale/km'),
|
||||
ko: require('dayjs/locale/ko'),
|
||||
ku: require('dayjs/locale/ku'),
|
||||
lt: require('dayjs/locale/lt'),
|
||||
lv: require('dayjs/locale/lv'),
|
||||
ms: require('dayjs/locale/ms'),
|
||||
my: require('dayjs/locale/my'),
|
||||
nb: require('dayjs/locale/nb'),
|
||||
nl: require('dayjs/locale/nl'),
|
||||
pl: require('dayjs/locale/pl'),
|
||||
pt: require('dayjs/locale/pt'),
|
||||
pt_BR: require('dayjs/locale/pt-br'),
|
||||
ro: require('dayjs/locale/ro'),
|
||||
ru: require('dayjs/locale/ru'),
|
||||
sl: require('dayjs/locale/sl'),
|
||||
sr_Cyrl: require('dayjs/locale/sr-cyrl'),
|
||||
sr_Latn: require('dayjs/locale/sr'),
|
||||
sv: require('dayjs/locale/sv'),
|
||||
th: require('dayjs/locale/th'),
|
||||
tr: require('dayjs/locale/tr'),
|
||||
uk: require('dayjs/locale/uk'),
|
||||
ur: require('dayjs/locale/ur'),
|
||||
vi: require('dayjs/locale/vi'),
|
||||
zh_CN: require('dayjs/locale/zh-cn'),
|
||||
zh_HK: require('dayjs/locale/zh-hk'),
|
||||
zh_TW: require('dayjs/locale/zh-tw'),
|
||||
}
|
||||
1166
vendor/filament/forms/resources/js/components/file-upload.js
vendored
Normal file
1166
vendor/filament/forms/resources/js/components/file-upload.js
vendored
Normal file
File diff suppressed because it is too large
Load diff
365
vendor/filament/forms/resources/js/components/file-upload/filepond-plugin-media-preview.js
vendored
Normal file
365
vendor/filament/forms/resources/js/components/file-upload/filepond-plugin-media-preview.js
vendored
Normal file
|
|
@ -0,0 +1,365 @@
|
|||
/**
|
||||
* Source: https://github.com/nielsboogaard/filepond-plugin-media-preview (MIT)
|
||||
* Changes:
|
||||
* - Merged all source modules into a single file.
|
||||
* - Fixed upstream PR #33 `mediaPreviewHeight` implementation.
|
||||
* - Prevented audio controls from initiating file reordering.
|
||||
* - Corrected audio timeline positioning when the preview is transformed or resized.
|
||||
* - Added stable references for global audio drag listeners and an `AudioPlayer.destroy()` method to remove them.
|
||||
* - Retained the `AudioPlayer` on the FilePond view and destroyed it through the view's `destroy` callback.
|
||||
* - Tracked generated media object URLs and revoked them before replacement and when the view is destroyed.
|
||||
*/
|
||||
|
||||
const isPreviewableVideo = (file) => /^video/.test(file.type)
|
||||
|
||||
const isPreviewableAudio = (file) => /^audio/.test(file.type)
|
||||
|
||||
class AudioPlayer {
|
||||
constructor(mediaEl, audioElements) {
|
||||
this.mediaEl = mediaEl
|
||||
this.audioElements = audioElements
|
||||
this.onPlayhead = false
|
||||
this.duration = 0
|
||||
this.movePlayheadHandler = this.movePlayhead.bind(this)
|
||||
this.mouseUpHandler = this.mouseUp.bind(this)
|
||||
|
||||
this.registerListeners()
|
||||
}
|
||||
|
||||
registerListeners() {
|
||||
this.mediaEl.addEventListener(
|
||||
'timeupdate',
|
||||
this.timeUpdate.bind(this),
|
||||
false,
|
||||
)
|
||||
this.mediaEl.addEventListener(
|
||||
'canplaythrough',
|
||||
() => (this.duration = this.mediaEl.duration),
|
||||
false,
|
||||
)
|
||||
this.audioElements.timeline.addEventListener(
|
||||
'click',
|
||||
this.timelineClicked.bind(this),
|
||||
false,
|
||||
)
|
||||
this.audioElements.button.addEventListener(
|
||||
'click',
|
||||
this.play.bind(this),
|
||||
)
|
||||
this.audioElements.container.addEventListener(
|
||||
'pointerdown',
|
||||
(event) => event.stopPropagation(),
|
||||
false,
|
||||
)
|
||||
this.audioElements.playhead.addEventListener(
|
||||
'mousedown',
|
||||
this.mouseDown.bind(this),
|
||||
false,
|
||||
)
|
||||
window.addEventListener('mouseup', this.mouseUpHandler, false)
|
||||
}
|
||||
|
||||
play() {
|
||||
if (this.mediaEl.paused) {
|
||||
this.mediaEl.play()
|
||||
} else {
|
||||
this.mediaEl.pause()
|
||||
}
|
||||
|
||||
this.audioElements.button.classList.toggle('play')
|
||||
this.audioElements.button.classList.toggle('pause')
|
||||
}
|
||||
|
||||
timeUpdate() {
|
||||
const playPercent = (this.mediaEl.currentTime / this.duration) * 100
|
||||
|
||||
this.audioElements.playhead.style.marginLeft = `${playPercent}%`
|
||||
|
||||
if (this.mediaEl.currentTime === this.duration) {
|
||||
this.audioElements.button.classList.toggle('play')
|
||||
this.audioElements.button.classList.toggle('pause')
|
||||
}
|
||||
}
|
||||
|
||||
movePlayhead(event) {
|
||||
this.audioElements.playhead.style.marginLeft = `${this.clickPercent(event) * 100}%`
|
||||
}
|
||||
|
||||
timelineClicked(event) {
|
||||
this.movePlayhead(event)
|
||||
this.mediaEl.currentTime = this.duration * this.clickPercent(event)
|
||||
}
|
||||
|
||||
mouseDown() {
|
||||
this.onPlayhead = true
|
||||
window.addEventListener('mousemove', this.movePlayheadHandler, true)
|
||||
this.mediaEl.removeEventListener(
|
||||
'timeupdate',
|
||||
this.timeUpdate.bind(this),
|
||||
false,
|
||||
)
|
||||
}
|
||||
|
||||
mouseUp(event) {
|
||||
window.removeEventListener('mousemove', this.movePlayheadHandler, true)
|
||||
|
||||
if (this.onPlayhead) {
|
||||
this.movePlayhead(event)
|
||||
this.mediaEl.currentTime = this.duration * this.clickPercent(event)
|
||||
this.mediaEl.addEventListener(
|
||||
'timeupdate',
|
||||
this.timeUpdate.bind(this),
|
||||
false,
|
||||
)
|
||||
}
|
||||
|
||||
this.onPlayhead = false
|
||||
}
|
||||
|
||||
clickPercent(event) {
|
||||
const timelineBounds =
|
||||
this.audioElements.timeline.getBoundingClientRect()
|
||||
|
||||
return Math.max(
|
||||
0,
|
||||
Math.min(
|
||||
1,
|
||||
(event.clientX - timelineBounds.left) / timelineBounds.width,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
destroy() {
|
||||
window.removeEventListener('mousemove', this.movePlayheadHandler, true)
|
||||
window.removeEventListener('mouseup', this.mouseUpHandler, false)
|
||||
}
|
||||
}
|
||||
|
||||
const createMediaView = (_) =>
|
||||
_.utils.createView({
|
||||
name: 'media-preview',
|
||||
tag: 'div',
|
||||
ignoreRect: true,
|
||||
create: ({ root, props }) => {
|
||||
const item = root.query('GET_ITEM', { id: props.id })
|
||||
const tagName = isPreviewableAudio(item.file) ? 'audio' : 'video'
|
||||
|
||||
root.ref.media = document.createElement(tagName)
|
||||
root.ref.media.setAttribute('controls', true)
|
||||
root.element.appendChild(root.ref.media)
|
||||
|
||||
if (isPreviewableAudio(item.file)) {
|
||||
const fragment = document.createDocumentFragment()
|
||||
|
||||
root.ref.audio = []
|
||||
root.ref.audio.container = document.createElement('div')
|
||||
root.ref.audio.button = document.createElement('span')
|
||||
root.ref.audio.timeline = document.createElement('div')
|
||||
root.ref.audio.playhead = document.createElement('div')
|
||||
|
||||
root.ref.audio.container.className = 'audioplayer'
|
||||
root.ref.audio.button.className = 'playpausebtn play'
|
||||
root.ref.audio.timeline.className = 'timeline'
|
||||
root.ref.audio.playhead.className = 'playhead'
|
||||
|
||||
root.ref.audio.timeline.appendChild(root.ref.audio.playhead)
|
||||
root.ref.audio.container.appendChild(root.ref.audio.button)
|
||||
root.ref.audio.container.appendChild(root.ref.audio.timeline)
|
||||
fragment.appendChild(root.ref.audio.container)
|
||||
|
||||
root.element.appendChild(fragment)
|
||||
}
|
||||
},
|
||||
write: _.utils.createRoute({
|
||||
DID_MEDIA_PREVIEW_LOAD: ({ root, props }) => {
|
||||
const { id, mediaPreviewHeight } = props
|
||||
const item = root.query('GET_ITEM', { id })
|
||||
|
||||
if (!item) {
|
||||
return
|
||||
}
|
||||
|
||||
const url = window.URL || window.webkitURL
|
||||
|
||||
if (root.ref.objectUrl) {
|
||||
url.revokeObjectURL(root.ref.objectUrl)
|
||||
root.ref.objectUrl = null
|
||||
}
|
||||
|
||||
root.ref.media.type = item.file.type
|
||||
|
||||
if (item.file.mock && item.file.url) {
|
||||
root.ref.media.src = item.file.url
|
||||
} else {
|
||||
const blob = new Blob([item.file], { type: item.file.type })
|
||||
|
||||
root.ref.objectUrl = url.createObjectURL(blob)
|
||||
root.ref.media.src = root.ref.objectUrl
|
||||
}
|
||||
|
||||
if (isPreviewableAudio(item.file)) {
|
||||
root.ref.audioPlayer = new AudioPlayer(
|
||||
root.ref.media,
|
||||
root.ref.audio,
|
||||
)
|
||||
}
|
||||
|
||||
root.ref.media.addEventListener(
|
||||
'loadeddata',
|
||||
() => {
|
||||
let height = 75
|
||||
|
||||
if (isPreviewableVideo(item.file)) {
|
||||
if (mediaPreviewHeight) {
|
||||
height = mediaPreviewHeight
|
||||
root.element.querySelector(
|
||||
'video',
|
||||
).style.height = `${height}px`
|
||||
} else {
|
||||
let containerWidth = root.ref.media.offsetWidth
|
||||
let factor =
|
||||
root.ref.media.videoWidth / containerWidth
|
||||
|
||||
height = root.ref.media.videoHeight / factor
|
||||
}
|
||||
}
|
||||
|
||||
root.dispatch('DID_UPDATE_PANEL_HEIGHT', {
|
||||
id,
|
||||
height,
|
||||
})
|
||||
},
|
||||
false,
|
||||
)
|
||||
},
|
||||
}),
|
||||
destroy: ({ root }) => {
|
||||
root.ref.audioPlayer?.destroy()
|
||||
|
||||
if (root.ref.objectUrl) {
|
||||
const url = window.URL || window.webkitURL
|
||||
|
||||
url.revokeObjectURL(root.ref.objectUrl)
|
||||
root.ref.objectUrl = null
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
const createMediaWrapperView = (_) => {
|
||||
const didCreatePreviewContainer = ({ root, props }) => {
|
||||
const item = root.query('GET_ITEM', props.id)
|
||||
|
||||
if (!item) {
|
||||
return
|
||||
}
|
||||
|
||||
root.dispatch('DID_MEDIA_PREVIEW_LOAD', {
|
||||
id: props.id,
|
||||
mediaPreviewHeight: props.mediaPreviewHeight,
|
||||
})
|
||||
}
|
||||
|
||||
const create = ({ root, props }) => {
|
||||
const media = createMediaView(_)
|
||||
|
||||
root.ref.media = root.appendChildView(
|
||||
root.createChildView(media, {
|
||||
id: props.id,
|
||||
mediaPreviewHeight: props.mediaPreviewHeight,
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
return _.utils.createView({
|
||||
name: 'media-preview-wrapper',
|
||||
create,
|
||||
write: _.utils.createRoute({
|
||||
DID_MEDIA_PREVIEW_CONTAINER_CREATE: didCreatePreviewContainer,
|
||||
}),
|
||||
})
|
||||
}
|
||||
|
||||
const plugin = (fpAPI) => {
|
||||
const { addFilter, utils } = fpAPI
|
||||
const { Type, createRoute } = utils
|
||||
const mediaWrapperView = createMediaWrapperView(fpAPI)
|
||||
|
||||
addFilter('CREATE_VIEW', (viewAPI) => {
|
||||
const { is, view, query } = viewAPI
|
||||
|
||||
if (!is('file')) {
|
||||
return
|
||||
}
|
||||
|
||||
const didLoadItem = ({ root, props }) => {
|
||||
const item = query('GET_ITEM', props.id)
|
||||
const allowVideoPreview = query('GET_ALLOW_VIDEO_PREVIEW')
|
||||
const allowAudioPreview = query('GET_ALLOW_AUDIO_PREVIEW')
|
||||
const mediaPreviewHeight = query('GET_MEDIA_PREVIEW_HEIGHT')
|
||||
|
||||
if (
|
||||
!item ||
|
||||
item.archived ||
|
||||
((!isPreviewableVideo(item.file) || !allowVideoPreview) &&
|
||||
(!isPreviewableAudio(item.file) || !allowAudioPreview))
|
||||
) {
|
||||
return
|
||||
}
|
||||
|
||||
root.ref.mediaPreview = view.appendChildView(
|
||||
view.createChildView(mediaWrapperView, {
|
||||
id: props.id,
|
||||
mediaPreviewHeight,
|
||||
}),
|
||||
)
|
||||
|
||||
root.dispatch('DID_MEDIA_PREVIEW_CONTAINER_CREATE', {
|
||||
id: props.id,
|
||||
})
|
||||
}
|
||||
|
||||
view.registerWriter(
|
||||
createRoute(
|
||||
{
|
||||
DID_LOAD_ITEM: didLoadItem,
|
||||
},
|
||||
({ root, props }) => {
|
||||
const item = query('GET_ITEM', props.id)
|
||||
const allowVideoPreview = root.query(
|
||||
'GET_ALLOW_VIDEO_PREVIEW',
|
||||
)
|
||||
const allowAudioPreview = root.query(
|
||||
'GET_ALLOW_AUDIO_PREVIEW',
|
||||
)
|
||||
|
||||
if (
|
||||
!item ||
|
||||
((!isPreviewableVideo(item.file) ||
|
||||
!allowVideoPreview) &&
|
||||
(!isPreviewableAudio(item.file) ||
|
||||
!allowAudioPreview)) ||
|
||||
root.rect.element.hidden
|
||||
) {
|
||||
return
|
||||
}
|
||||
},
|
||||
),
|
||||
)
|
||||
})
|
||||
|
||||
return {
|
||||
options: {
|
||||
allowVideoPreview: [true, Type.BOOLEAN],
|
||||
allowAudioPreview: [true, Type.BOOLEAN],
|
||||
mediaPreviewHeight: [null, Type.INT],
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof window !== 'undefined' && typeof window.document !== 'undefined') {
|
||||
document.dispatchEvent(
|
||||
new CustomEvent('FilePond:pluginloaded', { detail: plugin }),
|
||||
)
|
||||
}
|
||||
|
||||
export default plugin
|
||||
113
vendor/filament/forms/resources/js/components/key-value.js
vendored
Normal file
113
vendor/filament/forms/resources/js/components/key-value.js
vendored
Normal file
|
|
@ -0,0 +1,113 @@
|
|||
export default function keyValueFormComponent({ state }) {
|
||||
return {
|
||||
state,
|
||||
|
||||
rows: [],
|
||||
|
||||
init() {
|
||||
this.updateRows()
|
||||
|
||||
if (this.rows.length <= 0) {
|
||||
this.rows.push({ key: '', value: '' })
|
||||
} else {
|
||||
this.updateState()
|
||||
}
|
||||
|
||||
this.$watch('state', (state, oldState) => {
|
||||
if (!Array.isArray(state)) {
|
||||
return
|
||||
}
|
||||
|
||||
const getLength = (value) => {
|
||||
if (value === null) {
|
||||
return 0
|
||||
}
|
||||
|
||||
if (Array.isArray(value)) {
|
||||
return value.length
|
||||
}
|
||||
|
||||
if (typeof value !== 'object') {
|
||||
return 0
|
||||
}
|
||||
|
||||
return Object.keys(value).length
|
||||
}
|
||||
|
||||
if (getLength(state) === 0 && getLength(oldState) === 0) {
|
||||
return
|
||||
}
|
||||
|
||||
this.updateRows()
|
||||
})
|
||||
},
|
||||
|
||||
addRow() {
|
||||
this.rows.push({ key: '', value: '' })
|
||||
|
||||
this.updateState()
|
||||
},
|
||||
|
||||
deleteRow(index) {
|
||||
this.rows.splice(index, 1)
|
||||
|
||||
if (this.rows.length <= 0) {
|
||||
this.addRow()
|
||||
}
|
||||
|
||||
this.updateState()
|
||||
},
|
||||
|
||||
reorderRows(event) {
|
||||
const rows = Alpine.raw(this.rows)
|
||||
|
||||
this.rows = []
|
||||
|
||||
const reorderedRow = rows.splice(event.oldIndex, 1)[0]
|
||||
rows.splice(event.newIndex, 0, reorderedRow)
|
||||
|
||||
this.$nextTick(() => {
|
||||
this.rows = rows
|
||||
|
||||
this.updateState()
|
||||
})
|
||||
},
|
||||
|
||||
// https://github.com/filamentphp/filament/issues/1107
|
||||
// https://github.com/filamentphp/filament/issues/12824
|
||||
updateRows() {
|
||||
const state = Alpine.raw(this.state)
|
||||
const mergedRows = state.map(({ key, value }) => ({ key, value }))
|
||||
|
||||
this.rows.forEach((row) => {
|
||||
if (row.key === '' || row.key === null) {
|
||||
mergedRows.push({
|
||||
key: '',
|
||||
value: row.value,
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
this.rows = mergedRows
|
||||
},
|
||||
|
||||
updateState() {
|
||||
let state = []
|
||||
|
||||
this.rows.forEach((row) => {
|
||||
if (row.key === '' || row.key === null) {
|
||||
return
|
||||
}
|
||||
|
||||
state.push({
|
||||
key: row.key,
|
||||
value: row.value,
|
||||
})
|
||||
})
|
||||
|
||||
if (JSON.stringify(this.state) !== JSON.stringify(state)) {
|
||||
this.state = state
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
511
vendor/filament/forms/resources/js/components/markdown-editor.js
vendored
Normal file
511
vendor/filament/forms/resources/js/components/markdown-editor.js
vendored
Normal file
|
|
@ -0,0 +1,511 @@
|
|||
window.CodeMirror = require('codemirror/lib/codemirror')
|
||||
|
||||
require('codemirror')
|
||||
require('codemirror/addon/mode/overlay')
|
||||
require('codemirror/addon/edit/continuelist')
|
||||
require('codemirror/addon/display/placeholder')
|
||||
require('codemirror/addon/selection/mark-selection')
|
||||
require('codemirror/addon/search/searchcursor')
|
||||
require('codemirror/mode/clike/clike')
|
||||
require('codemirror/mode/cmake/cmake')
|
||||
require('codemirror/mode/css/css')
|
||||
require('codemirror/mode/diff/diff')
|
||||
require('codemirror/mode/django/django')
|
||||
require('codemirror/mode/dockerfile/dockerfile')
|
||||
require('codemirror/mode/gfm/gfm')
|
||||
require('codemirror/mode/go/go')
|
||||
require('codemirror/mode/htmlmixed/htmlmixed')
|
||||
require('codemirror/mode/http/http')
|
||||
require('codemirror/mode/javascript/javascript')
|
||||
require('codemirror/mode/jinja2/jinja2')
|
||||
require('codemirror/mode/jsx/jsx')
|
||||
require('codemirror/mode/markdown/markdown')
|
||||
require('codemirror/mode/nginx/nginx')
|
||||
require('codemirror/mode/pascal/pascal')
|
||||
require('codemirror/mode/perl/perl')
|
||||
require('codemirror/mode/php/php')
|
||||
require('codemirror/mode/protobuf/protobuf')
|
||||
require('codemirror/mode/python/python')
|
||||
require('codemirror/mode/ruby/ruby')
|
||||
require('codemirror/mode/rust/rust')
|
||||
require('codemirror/mode/sass/sass')
|
||||
require('codemirror/mode/shell/shell')
|
||||
require('codemirror/mode/sql/sql')
|
||||
require('codemirror/mode/stylus/stylus')
|
||||
require('codemirror/mode/swift/swift')
|
||||
require('codemirror/mode/vue/vue')
|
||||
require('codemirror/mode/xml/xml')
|
||||
require('codemirror/mode/yaml/yaml')
|
||||
|
||||
require('./markdown-editor/EasyMDE')
|
||||
|
||||
CodeMirror.commands.tabAndIndentMarkdownList = function (codemirror) {
|
||||
var ranges = codemirror.listSelections()
|
||||
var pos = ranges[0].head
|
||||
var eolState = codemirror.getStateAfter(pos.line)
|
||||
var inList = eolState.list !== false
|
||||
|
||||
if (inList) {
|
||||
codemirror.execCommand('indentMore')
|
||||
return
|
||||
}
|
||||
|
||||
if (codemirror.options.indentWithTabs) {
|
||||
codemirror.execCommand('insertTab')
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
var spaces = Array(codemirror.options.tabSize + 1).join(' ')
|
||||
codemirror.replaceSelection(spaces)
|
||||
}
|
||||
|
||||
CodeMirror.commands.shiftTabAndUnindentMarkdownList = function (codemirror) {
|
||||
var ranges = codemirror.listSelections()
|
||||
var pos = ranges[0].head
|
||||
var eolState = codemirror.getStateAfter(pos.line)
|
||||
var inList = eolState.list !== false
|
||||
|
||||
if (inList) {
|
||||
codemirror.execCommand('indentLess')
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if (codemirror.options.indentWithTabs) {
|
||||
codemirror.execCommand('insertTab')
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
var spaces = Array(codemirror.options.tabSize + 1).join(' ')
|
||||
codemirror.replaceSelection(spaces)
|
||||
}
|
||||
|
||||
export default function markdownEditorFormComponent({
|
||||
canAttachFiles,
|
||||
isLiveDebounced,
|
||||
isLiveOnBlur,
|
||||
label,
|
||||
liveDebounce,
|
||||
maxHeight,
|
||||
minHeight,
|
||||
placeholder,
|
||||
setUpUsing,
|
||||
state,
|
||||
translations,
|
||||
toolbarButtons,
|
||||
uploadFileAttachmentUsing,
|
||||
}) {
|
||||
let isDestroyed = false
|
||||
|
||||
return {
|
||||
editor: null,
|
||||
|
||||
form: null,
|
||||
|
||||
state,
|
||||
|
||||
wasEditorVisible: false,
|
||||
|
||||
resizeObserver: null,
|
||||
|
||||
intersectionObserver: null,
|
||||
|
||||
async init() {
|
||||
// If the editor is inside a modal, wait for the modal transition to finish before initializing the editor.
|
||||
// This is necessary to prevent the editor from being initialized before the modal is fully visible,
|
||||
// which can cause it to render without any content.
|
||||
if (this.$root.closest('.fi-modal')) {
|
||||
await new Promise((resolve) => setTimeout(resolve, 300))
|
||||
}
|
||||
|
||||
if (isDestroyed) {
|
||||
return
|
||||
}
|
||||
|
||||
if (this.$root._editor) {
|
||||
this.$root._editor.toTextArea()
|
||||
this.$root._editor = null
|
||||
}
|
||||
|
||||
this.form = this.$refs.editor.form
|
||||
|
||||
this.$root._editor = this.editor = new EasyMDE({
|
||||
autoDownloadFontAwesome: false,
|
||||
autoRefresh: true,
|
||||
autoSave: false,
|
||||
element: this.$refs.editor,
|
||||
imageAccept:
|
||||
'image/png, image/jpeg, image/gif, image/avif, image/webp',
|
||||
imageUploadFunction: uploadFileAttachmentUsing,
|
||||
initialValue: this.state ?? '',
|
||||
maxHeight,
|
||||
minHeight: minHeight ?? '3rem',
|
||||
placeholder,
|
||||
previewImagesInEditor: true,
|
||||
spellChecker: false,
|
||||
status: [
|
||||
{
|
||||
className: 'upload-image',
|
||||
defaultValue: '',
|
||||
},
|
||||
],
|
||||
toolbar: this.getToolbar(),
|
||||
uploadImage: canAttachFiles,
|
||||
})
|
||||
|
||||
if (label) {
|
||||
const inputField = this.editor.codemirror.getInputField()
|
||||
|
||||
if (inputField) {
|
||||
inputField.setAttribute('aria-label', label)
|
||||
}
|
||||
}
|
||||
|
||||
this.editor.codemirror.setOption(
|
||||
'direction',
|
||||
document.documentElement?.dir ?? 'ltr',
|
||||
)
|
||||
|
||||
// When creating a link, highlight the URL instead of the label:
|
||||
this.editor.codemirror.on('changes', (instance, changes) => {
|
||||
try {
|
||||
const lastChange = changes[changes.length - 1]
|
||||
|
||||
if (lastChange.origin === '+input') {
|
||||
const urlPlaceholder = '(https://)'
|
||||
const urlLineText =
|
||||
lastChange.text[lastChange.text.length - 1]
|
||||
|
||||
if (
|
||||
urlLineText.endsWith(urlPlaceholder) &&
|
||||
urlLineText !== '[]' + urlPlaceholder
|
||||
) {
|
||||
const from = lastChange.from
|
||||
const to = lastChange.to
|
||||
const isSelectionMultiline =
|
||||
lastChange.text.length > 1
|
||||
const baseIndex = isSelectionMultiline ? 0 : from.ch
|
||||
|
||||
setTimeout(() => {
|
||||
instance.setSelection(
|
||||
{
|
||||
line: to.line,
|
||||
ch:
|
||||
baseIndex +
|
||||
urlLineText.lastIndexOf('(') +
|
||||
1,
|
||||
},
|
||||
{
|
||||
line: to.line,
|
||||
ch:
|
||||
baseIndex +
|
||||
urlLineText.lastIndexOf(')'),
|
||||
},
|
||||
)
|
||||
}, 25)
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
// Revert to original behavior.
|
||||
}
|
||||
})
|
||||
|
||||
const debouncedCommit = Alpine.debounce(() => {
|
||||
if (!this.editor) {
|
||||
return
|
||||
}
|
||||
|
||||
this.$wire.commit()
|
||||
}, liveDebounce ?? 300)
|
||||
|
||||
this.editor.codemirror.on('change', (instance, changeObject) => {
|
||||
if (!this.editor) {
|
||||
return
|
||||
}
|
||||
|
||||
// `setValue` changes originate from the `state` watcher applying
|
||||
// an external state change to the editor, not from user input, so
|
||||
// they should not be echoed back into the state.
|
||||
if (changeObject.origin === 'setValue') {
|
||||
return
|
||||
}
|
||||
|
||||
this.state = this.editor.value()
|
||||
|
||||
if (isLiveDebounced) {
|
||||
debouncedCommit()
|
||||
}
|
||||
})
|
||||
|
||||
if (isLiveOnBlur) {
|
||||
this.editor.codemirror.on('blur', () => this.$wire.commit())
|
||||
}
|
||||
|
||||
this.$watch('state', () => {
|
||||
if (!this.editor) {
|
||||
return
|
||||
}
|
||||
|
||||
// Skip the echo of the editor's own input to avoid resetting the
|
||||
// cursor position, but still apply genuine external state changes,
|
||||
// even while the editor is focused.
|
||||
if ((this.state ?? '') === this.editor.value()) {
|
||||
return
|
||||
}
|
||||
|
||||
Alpine.raw(this.editor).value(this.state ?? '')
|
||||
})
|
||||
|
||||
if (setUpUsing) {
|
||||
setUpUsing(this)
|
||||
}
|
||||
|
||||
// If the editor initializes while hidden, such as in a collapsed
|
||||
// section or an inactive tab, CodeMirror renders no lines, and no
|
||||
// update pass runs when the editor is revealed, so inline image
|
||||
// previews stay unapplied until the first keystroke. A `refresh()`
|
||||
// once the editor becomes visible renders it correctly. The
|
||||
// observers stay connected for the whole lifecycle of the editor
|
||||
// since it may be hidden and revealed again, potentially receiving
|
||||
// state changes while hidden, but `refresh()` only runs on the
|
||||
// hidden-to-visible transition, not on every resize or scroll.
|
||||
this.wasEditorVisible = this.isEditorVisible()
|
||||
|
||||
this.resizeObserver = new ResizeObserver(() =>
|
||||
this.handleEditorVisibilityChange(),
|
||||
)
|
||||
this.resizeObserver.observe(this.$el)
|
||||
|
||||
this.intersectionObserver = new IntersectionObserver(() =>
|
||||
this.handleEditorVisibilityChange(),
|
||||
)
|
||||
this.intersectionObserver.observe(this.$el)
|
||||
},
|
||||
|
||||
isEditorVisible() {
|
||||
// `offsetParent` is `null` when the editor or an ancestor uses
|
||||
// `display: none`, such as in an inactive tab. A collapsed section
|
||||
// hides its content with `visibility: hidden` instead, which only
|
||||
// a computed style check detects.
|
||||
return (
|
||||
this.$el.offsetParent !== null &&
|
||||
getComputedStyle(this.$el).visibility !== 'hidden'
|
||||
)
|
||||
},
|
||||
|
||||
handleEditorVisibilityChange() {
|
||||
const isEditorVisible = this.isEditorVisible()
|
||||
|
||||
if (isEditorVisible && !this.wasEditorVisible) {
|
||||
Alpine.raw(this.editor)?.codemirror?.refresh()
|
||||
}
|
||||
|
||||
this.wasEditorVisible = isEditorVisible
|
||||
},
|
||||
|
||||
destroy() {
|
||||
isDestroyed = true
|
||||
|
||||
this.resizeObserver?.disconnect()
|
||||
this.resizeObserver = null
|
||||
|
||||
this.intersectionObserver?.disconnect()
|
||||
this.intersectionObserver = null
|
||||
|
||||
if (this.editor) {
|
||||
this.editor.codemirror.setOption('autoRefresh', false)
|
||||
this.form?.removeEventListener(
|
||||
'submit',
|
||||
this.editor.codemirror.save,
|
||||
)
|
||||
this.editor.cleanup()
|
||||
this.editor.toTextArea()
|
||||
}
|
||||
|
||||
this.$root._editor = null
|
||||
this.editor = null
|
||||
},
|
||||
|
||||
getToolbar() {
|
||||
let toolbar = []
|
||||
|
||||
toolbarButtons.forEach((buttonGroup) => {
|
||||
buttonGroup.forEach((button) =>
|
||||
toolbar.push(this.getToolbarButton(button)),
|
||||
)
|
||||
|
||||
if (buttonGroup.length > 0) {
|
||||
toolbar.push('|')
|
||||
}
|
||||
})
|
||||
|
||||
if (toolbar[toolbar.length - 1] === '|') {
|
||||
toolbar.pop()
|
||||
}
|
||||
|
||||
return toolbar
|
||||
},
|
||||
|
||||
getToolbarButton(name) {
|
||||
if (name === 'bold') {
|
||||
return this.getBoldToolbarButton()
|
||||
}
|
||||
|
||||
if (name === 'italic') {
|
||||
return this.getItalicToolbarButton()
|
||||
}
|
||||
|
||||
if (name === 'strike') {
|
||||
return this.getStrikeToolbarButton()
|
||||
}
|
||||
|
||||
if (name === 'link') {
|
||||
return this.getLinkToolbarButton()
|
||||
}
|
||||
|
||||
if (name === 'heading') {
|
||||
return this.getHeadingToolbarButton()
|
||||
}
|
||||
|
||||
if (name === 'blockquote') {
|
||||
return this.getBlockquoteToolbarButton()
|
||||
}
|
||||
|
||||
if (name === 'codeBlock') {
|
||||
return this.getCodeBlockToolbarButton()
|
||||
}
|
||||
|
||||
if (name === 'bulletList') {
|
||||
return this.getBulletListToolbarButton()
|
||||
}
|
||||
|
||||
if (name === 'orderedList') {
|
||||
return this.getOrderedListToolbarButton()
|
||||
}
|
||||
|
||||
if (name === 'table') {
|
||||
return this.getTableToolbarButton()
|
||||
}
|
||||
|
||||
if (name === 'attachFiles') {
|
||||
return this.getAttachFilesToolbarButton()
|
||||
}
|
||||
|
||||
if (name === 'undo') {
|
||||
return this.getUndoToolbarButton()
|
||||
}
|
||||
|
||||
if (name === 'redo') {
|
||||
return this.getRedoToolbarButton()
|
||||
}
|
||||
|
||||
console.error(`Markdown editor toolbar button "${name}" not found.`)
|
||||
},
|
||||
|
||||
getBoldToolbarButton() {
|
||||
return {
|
||||
name: 'bold',
|
||||
action: EasyMDE.toggleBold,
|
||||
title: translations.tools?.bold,
|
||||
}
|
||||
},
|
||||
|
||||
getItalicToolbarButton() {
|
||||
return {
|
||||
name: 'italic',
|
||||
action: EasyMDE.toggleItalic,
|
||||
title: translations.tools?.italic,
|
||||
}
|
||||
},
|
||||
|
||||
getStrikeToolbarButton() {
|
||||
return {
|
||||
name: 'strikethrough',
|
||||
action: EasyMDE.toggleStrikethrough,
|
||||
title: translations.tools?.strike,
|
||||
}
|
||||
},
|
||||
|
||||
getLinkToolbarButton() {
|
||||
return {
|
||||
name: 'link',
|
||||
action: EasyMDE.drawLink,
|
||||
title: translations.tools?.link,
|
||||
}
|
||||
},
|
||||
|
||||
getHeadingToolbarButton() {
|
||||
return {
|
||||
name: 'heading',
|
||||
action: EasyMDE.toggleHeadingSmaller,
|
||||
title: translations.tools?.heading,
|
||||
}
|
||||
},
|
||||
|
||||
getBlockquoteToolbarButton() {
|
||||
return {
|
||||
name: 'quote',
|
||||
action: EasyMDE.toggleBlockquote,
|
||||
title: translations.tools?.blockquote,
|
||||
}
|
||||
},
|
||||
|
||||
getCodeBlockToolbarButton() {
|
||||
return {
|
||||
name: 'code',
|
||||
action: EasyMDE.toggleCodeBlock,
|
||||
title: translations.tools?.code_block,
|
||||
}
|
||||
},
|
||||
|
||||
getBulletListToolbarButton() {
|
||||
return {
|
||||
name: 'unordered-list',
|
||||
action: EasyMDE.toggleUnorderedList,
|
||||
title: translations.tools?.bullet_list,
|
||||
}
|
||||
},
|
||||
|
||||
getOrderedListToolbarButton() {
|
||||
return {
|
||||
name: 'ordered-list',
|
||||
action: EasyMDE.toggleOrderedList,
|
||||
title: translations.tools?.ordered_list,
|
||||
}
|
||||
},
|
||||
|
||||
getTableToolbarButton() {
|
||||
return {
|
||||
name: 'table',
|
||||
action: EasyMDE.drawTable,
|
||||
title: translations.tools?.table,
|
||||
}
|
||||
},
|
||||
|
||||
getAttachFilesToolbarButton() {
|
||||
return {
|
||||
name: 'upload-image',
|
||||
action: EasyMDE.drawUploadedImage,
|
||||
title: translations.tools?.attach_files,
|
||||
}
|
||||
},
|
||||
|
||||
getUndoToolbarButton() {
|
||||
return {
|
||||
name: 'undo',
|
||||
action: EasyMDE.undo,
|
||||
title: translations.tools?.undo,
|
||||
}
|
||||
},
|
||||
|
||||
getRedoToolbarButton() {
|
||||
return {
|
||||
name: 'redo',
|
||||
action: EasyMDE.redo,
|
||||
title: translations.tools?.redo,
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
3554
vendor/filament/forms/resources/js/components/markdown-editor/EasyMDE.js
vendored
Normal file
3554
vendor/filament/forms/resources/js/components/markdown-editor/EasyMDE.js
vendored
Normal file
File diff suppressed because it is too large
Load diff
424
vendor/filament/forms/resources/js/components/rich-editor.js
vendored
Normal file
424
vendor/filament/forms/resources/js/components/rich-editor.js
vendored
Normal file
|
|
@ -0,0 +1,424 @@
|
|||
import * as TipTapCore from '@tiptap/core'
|
||||
import * as TipTapPmState from '@tiptap/pm/state'
|
||||
import * as TipTapPmView from '@tiptap/pm/view'
|
||||
import * as TipTapPmModel from '@tiptap/pm/model'
|
||||
import getExtensions from './rich-editor/extensions'
|
||||
import { BubbleMenuPlugin } from '@tiptap/extension-bubble-menu'
|
||||
|
||||
const { Editor } = TipTapCore
|
||||
const { Selection } = TipTapPmState
|
||||
|
||||
// Expose the bundled TipTap/ProseMirror modules so custom extensions loaded
|
||||
// via `RichContentPlugin::getTipTapJsExtensions()` can share the same
|
||||
// ProseMirror instance (required for `instanceof` checks across bundles).
|
||||
window.FilamentRichEditor = window.FilamentRichEditor || {}
|
||||
window.FilamentRichEditor.tiptap = {
|
||||
core: TipTapCore,
|
||||
pmState: TipTapPmState,
|
||||
pmView: TipTapPmView,
|
||||
pmModel: TipTapPmModel,
|
||||
}
|
||||
|
||||
export default function richEditorFormComponent({
|
||||
acceptedFileTypes,
|
||||
acceptedFileTypesValidationMessage,
|
||||
activePanel,
|
||||
canAttachFiles,
|
||||
deleteCustomBlockButtonIconHtml,
|
||||
editCustomBlockButtonIconHtml,
|
||||
extensions,
|
||||
floatingToolbars,
|
||||
hasResizableImages,
|
||||
isDisabled,
|
||||
isLiveDebounced,
|
||||
isLiveOnBlur,
|
||||
key,
|
||||
label,
|
||||
linkProtocols,
|
||||
liveDebounce,
|
||||
livewireId,
|
||||
maxFileSize,
|
||||
maxFileSizeValidationMessage,
|
||||
mergeTags,
|
||||
mentions,
|
||||
getMentionSearchResultsUsing,
|
||||
getMentionLabelsUsing,
|
||||
noMergeTagSearchResultsMessage,
|
||||
placeholder,
|
||||
state,
|
||||
statePath,
|
||||
textColors,
|
||||
uploadingFileMessage,
|
||||
}) {
|
||||
let editor
|
||||
let eventListeners = []
|
||||
let isDestroyed = false
|
||||
|
||||
return {
|
||||
state,
|
||||
|
||||
activePanel,
|
||||
|
||||
editorSelection: { type: 'text', anchor: 1, head: 1 },
|
||||
|
||||
isUploadingFile: false,
|
||||
|
||||
fileValidationMessage: null,
|
||||
|
||||
shouldUpdateState: true,
|
||||
|
||||
editorUpdatedAt: Date.now(),
|
||||
|
||||
async init() {
|
||||
const resolvedExtensions = await getExtensions({
|
||||
acceptedFileTypes,
|
||||
acceptedFileTypesValidationMessage,
|
||||
canAttachFiles,
|
||||
customExtensionUrls: extensions,
|
||||
deleteCustomBlockButtonIconHtml,
|
||||
editCustomBlockButtonIconHtml,
|
||||
editCustomBlockUsing: (id, config) =>
|
||||
this.$wire.mountAction(
|
||||
'customBlock',
|
||||
{
|
||||
editorSelection: this.editorSelection,
|
||||
id,
|
||||
config,
|
||||
mode: 'edit',
|
||||
},
|
||||
{ schemaComponent: key },
|
||||
),
|
||||
floatingToolbars,
|
||||
hasResizableImages,
|
||||
insertCustomBlockUsing: (id, dragPosition = null) =>
|
||||
this.$wire.mountAction(
|
||||
'customBlock',
|
||||
{ id, dragPosition, mode: 'insert' },
|
||||
{ schemaComponent: key },
|
||||
),
|
||||
key,
|
||||
linkProtocols,
|
||||
maxFileSize,
|
||||
maxFileSizeValidationMessage,
|
||||
mergeTags,
|
||||
mentions,
|
||||
getMentionSearchResultsUsing,
|
||||
getMentionLabelsUsing,
|
||||
noMergeTagSearchResultsMessage,
|
||||
placeholder,
|
||||
statePath,
|
||||
textColors,
|
||||
uploadingFileMessage,
|
||||
$wire: this.$wire,
|
||||
})
|
||||
|
||||
if (isDestroyed) {
|
||||
return
|
||||
}
|
||||
|
||||
editor = new Editor({
|
||||
editable: !isDisabled,
|
||||
element: this.$refs.editor,
|
||||
editorProps: {
|
||||
attributes: {
|
||||
...(label ? { 'aria-label': label } : {}),
|
||||
},
|
||||
},
|
||||
extensions: resolvedExtensions,
|
||||
content: this.state,
|
||||
})
|
||||
|
||||
const hasParagraphToolbar = 'paragraph' in floatingToolbars
|
||||
|
||||
Object.keys(floatingToolbars).forEach((key) => {
|
||||
const element = this.$refs[`floatingToolbar::${key}`]
|
||||
|
||||
if (!element) {
|
||||
console.warn(`Floating toolbar [${key}] not found.`)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
editor.registerPlugin(
|
||||
BubbleMenuPlugin({
|
||||
editor,
|
||||
element,
|
||||
pluginKey: `floatingToolbar::${key}`,
|
||||
shouldShow: ({ editor }) => {
|
||||
if (key === 'paragraph') {
|
||||
return (
|
||||
editor.isFocused &&
|
||||
editor.isActive(key) &&
|
||||
!editor.state.selection.empty
|
||||
)
|
||||
}
|
||||
|
||||
if (
|
||||
hasParagraphToolbar &&
|
||||
!editor.state.selection.empty &&
|
||||
editor.isActive('paragraph')
|
||||
) {
|
||||
return false
|
||||
}
|
||||
|
||||
return editor.isFocused && editor.isActive(key)
|
||||
},
|
||||
options: {
|
||||
placement: 'bottom',
|
||||
offset: 15,
|
||||
},
|
||||
}),
|
||||
)
|
||||
})
|
||||
|
||||
editor.on('create', () => {
|
||||
this.editorUpdatedAt = Date.now()
|
||||
})
|
||||
|
||||
const debouncedCommit = Alpine.debounce(() => {
|
||||
if (!isDestroyed) {
|
||||
this.$wire.commit()
|
||||
}
|
||||
}, liveDebounce ?? 300)
|
||||
|
||||
editor.on('update', ({ editor }) =>
|
||||
this.$nextTick(() => {
|
||||
if (isDestroyed) return
|
||||
|
||||
this.editorUpdatedAt = Date.now()
|
||||
|
||||
this.state = editor.getJSON()
|
||||
|
||||
this.shouldUpdateState = false
|
||||
|
||||
this.fileValidationMessage = null
|
||||
|
||||
if (isLiveDebounced) {
|
||||
debouncedCommit()
|
||||
}
|
||||
}),
|
||||
)
|
||||
|
||||
editor.on('selectionUpdate', ({ transaction }) => {
|
||||
if (isDestroyed) return
|
||||
|
||||
this.editorUpdatedAt = Date.now()
|
||||
this.editorSelection = transaction.selection.toJSON()
|
||||
})
|
||||
|
||||
editor.on('transaction', () => {
|
||||
if (isDestroyed) return
|
||||
|
||||
this.editorUpdatedAt = Date.now()
|
||||
})
|
||||
|
||||
if (isLiveOnBlur) {
|
||||
editor.on('blur', () => {
|
||||
if (!isDestroyed) {
|
||||
this.$wire.commit()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
this.$watch('state', () => {
|
||||
if (isDestroyed) return
|
||||
|
||||
if (!this.shouldUpdateState) {
|
||||
this.shouldUpdateState = true
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
editor.commands.setContent(this.state)
|
||||
})
|
||||
|
||||
const runCommandsHandler = (event) => {
|
||||
if (event.detail.livewireId !== livewireId) {
|
||||
return
|
||||
}
|
||||
|
||||
if (event.detail.key !== key) {
|
||||
return
|
||||
}
|
||||
|
||||
this.runEditorCommands(event.detail)
|
||||
}
|
||||
window.addEventListener(
|
||||
'run-rich-editor-commands',
|
||||
runCommandsHandler,
|
||||
)
|
||||
eventListeners.push([
|
||||
'run-rich-editor-commands',
|
||||
runCommandsHandler,
|
||||
])
|
||||
|
||||
const uploadingFileHandler = (event) => {
|
||||
if (event.detail.livewireId !== livewireId) {
|
||||
return
|
||||
}
|
||||
|
||||
if (event.detail.key !== key) {
|
||||
return
|
||||
}
|
||||
|
||||
this.isUploadingFile = true
|
||||
this.fileValidationMessage = null
|
||||
|
||||
event.stopPropagation()
|
||||
}
|
||||
window.addEventListener(
|
||||
'rich-editor-uploading-file',
|
||||
uploadingFileHandler,
|
||||
)
|
||||
eventListeners.push([
|
||||
'rich-editor-uploading-file',
|
||||
uploadingFileHandler,
|
||||
])
|
||||
|
||||
const uploadedFileHandler = (event) => {
|
||||
if (event.detail.livewireId !== livewireId) {
|
||||
return
|
||||
}
|
||||
|
||||
if (event.detail.key !== key) {
|
||||
return
|
||||
}
|
||||
|
||||
this.isUploadingFile = false
|
||||
|
||||
event.stopPropagation()
|
||||
}
|
||||
window.addEventListener(
|
||||
'rich-editor-uploaded-file',
|
||||
uploadedFileHandler,
|
||||
)
|
||||
eventListeners.push([
|
||||
'rich-editor-uploaded-file',
|
||||
uploadedFileHandler,
|
||||
])
|
||||
|
||||
const validationMessageHandler = (event) => {
|
||||
if (event.detail.livewireId !== livewireId) {
|
||||
return
|
||||
}
|
||||
|
||||
if (event.detail.key !== key) {
|
||||
return
|
||||
}
|
||||
|
||||
this.isUploadingFile = false
|
||||
this.fileValidationMessage = event.detail.validationMessage
|
||||
|
||||
event.stopPropagation()
|
||||
}
|
||||
window.addEventListener(
|
||||
'rich-editor-file-validation-message',
|
||||
validationMessageHandler,
|
||||
)
|
||||
eventListeners.push([
|
||||
'rich-editor-file-validation-message',
|
||||
validationMessageHandler,
|
||||
])
|
||||
|
||||
window.dispatchEvent(
|
||||
new CustomEvent(`schema-component-${livewireId}-${key}-loaded`),
|
||||
)
|
||||
},
|
||||
|
||||
getEditor() {
|
||||
return editor
|
||||
},
|
||||
|
||||
$getEditor() {
|
||||
return this.getEditor()
|
||||
},
|
||||
|
||||
setEditorSelection(selection) {
|
||||
if (!selection) {
|
||||
return
|
||||
}
|
||||
|
||||
this.editorSelection = selection
|
||||
|
||||
editor
|
||||
.chain()
|
||||
.command(({ tr }) => {
|
||||
tr.setSelection(
|
||||
Selection.fromJSON(
|
||||
editor.state.doc,
|
||||
this.editorSelection,
|
||||
),
|
||||
)
|
||||
|
||||
return true
|
||||
})
|
||||
.run()
|
||||
},
|
||||
|
||||
runEditorCommands({ commands, editorSelection }) {
|
||||
this.setEditorSelection(editorSelection)
|
||||
|
||||
let commandChain = editor.chain()
|
||||
|
||||
commands.forEach(
|
||||
(command) =>
|
||||
(commandChain = commandChain[command.name](
|
||||
...(command.arguments ?? []),
|
||||
)),
|
||||
)
|
||||
|
||||
commandChain.run()
|
||||
},
|
||||
|
||||
togglePanel(id = null) {
|
||||
if (this.isPanelActive(id)) {
|
||||
this.activePanel = null
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
this.activePanel = id
|
||||
},
|
||||
|
||||
isPanelActive(id = null) {
|
||||
if (id === null) {
|
||||
return this.activePanel !== null
|
||||
}
|
||||
|
||||
return this.activePanel === id
|
||||
},
|
||||
|
||||
insertMergeTag(id) {
|
||||
editor
|
||||
.chain()
|
||||
.focus()
|
||||
.insertContent([
|
||||
{
|
||||
type: 'mergeTag',
|
||||
attrs: { id },
|
||||
},
|
||||
{
|
||||
type: 'text',
|
||||
text: ' ',
|
||||
},
|
||||
])
|
||||
.run()
|
||||
},
|
||||
|
||||
destroy() {
|
||||
isDestroyed = true
|
||||
|
||||
eventListeners.forEach(([eventName, handler]) => {
|
||||
window.removeEventListener(eventName, handler)
|
||||
})
|
||||
eventListeners = []
|
||||
|
||||
if (editor) {
|
||||
editor.destroy()
|
||||
editor = null
|
||||
}
|
||||
|
||||
this.shouldUpdateState = true
|
||||
},
|
||||
}
|
||||
}
|
||||
257
vendor/filament/forms/resources/js/components/rich-editor/extension-custom-block.js
vendored
Normal file
257
vendor/filament/forms/resources/js/components/rich-editor/extension-custom-block.js
vendored
Normal file
|
|
@ -0,0 +1,257 @@
|
|||
import { mergeAttributes, Node } from '@tiptap/core'
|
||||
import { Node as ProseMirrorNode } from '@tiptap/pm/model'
|
||||
import { Plugin } from '@tiptap/pm/state'
|
||||
|
||||
export default Node.create({
|
||||
name: 'customBlock',
|
||||
|
||||
group: 'block',
|
||||
|
||||
atom: true,
|
||||
|
||||
defining: true,
|
||||
|
||||
draggable: true,
|
||||
|
||||
selectable: true,
|
||||
|
||||
isolating: true,
|
||||
|
||||
allowGapCursor: true,
|
||||
|
||||
inline: false,
|
||||
|
||||
addNodeView() {
|
||||
return ({
|
||||
editor,
|
||||
node,
|
||||
getPos,
|
||||
HTMLAttributes,
|
||||
decorations,
|
||||
extension,
|
||||
}) => {
|
||||
const dom = document.createElement('div')
|
||||
dom.setAttribute('data-config', JSON.stringify(node.attrs.config))
|
||||
dom.setAttribute('data-id', node.attrs.id)
|
||||
dom.setAttribute('data-type', 'customBlock')
|
||||
|
||||
const header = document.createElement('div')
|
||||
header.className =
|
||||
'fi-fo-rich-editor-custom-block-header fi-not-prose'
|
||||
dom.appendChild(header)
|
||||
|
||||
if (
|
||||
editor.isEditable &&
|
||||
typeof node.attrs.config === 'object' &&
|
||||
node.attrs.config !== null &&
|
||||
Object.keys(node.attrs.config).length > 0
|
||||
) {
|
||||
const editButtonContainer = document.createElement('div')
|
||||
editButtonContainer.className =
|
||||
'fi-fo-rich-editor-custom-block-edit-btn-ctn'
|
||||
header.appendChild(editButtonContainer)
|
||||
|
||||
const editButton = document.createElement('button')
|
||||
editButton.className = 'fi-icon-btn'
|
||||
editButton.type = 'button'
|
||||
editButton.innerHTML =
|
||||
extension.options.editCustomBlockButtonIconHtml
|
||||
editButton.addEventListener('click', () =>
|
||||
extension.options.editCustomBlockUsing(
|
||||
node.attrs.id,
|
||||
node.attrs.config,
|
||||
),
|
||||
)
|
||||
editButtonContainer.appendChild(editButton)
|
||||
}
|
||||
|
||||
const heading = document.createElement('p')
|
||||
heading.className = 'fi-fo-rich-editor-custom-block-heading'
|
||||
heading.textContent = node.attrs.label
|
||||
header.appendChild(heading)
|
||||
|
||||
if (editor.isEditable) {
|
||||
const deleteButtonContainer = document.createElement('div')
|
||||
deleteButtonContainer.className =
|
||||
'fi-fo-rich-editor-custom-block-delete-btn-ctn'
|
||||
header.appendChild(deleteButtonContainer)
|
||||
|
||||
const deleteButton = document.createElement('button')
|
||||
deleteButton.className = 'fi-icon-btn'
|
||||
deleteButton.type = 'button'
|
||||
deleteButton.innerHTML =
|
||||
extension.options.deleteCustomBlockButtonIconHtml
|
||||
deleteButton.addEventListener('click', () =>
|
||||
editor
|
||||
.chain()
|
||||
.setNodeSelection(getPos())
|
||||
.deleteSelection()
|
||||
.run(),
|
||||
)
|
||||
deleteButtonContainer.appendChild(deleteButton)
|
||||
}
|
||||
|
||||
if (node.attrs.preview) {
|
||||
const preview = document.createElement('div')
|
||||
const previewClasses = [
|
||||
'fi-fo-rich-editor-custom-block-preview',
|
||||
]
|
||||
|
||||
if (!node.attrs.shouldApplyProseStylingToPreview) {
|
||||
previewClasses.push('fi-not-prose')
|
||||
}
|
||||
|
||||
preview.className = previewClasses.join(' ')
|
||||
preview.innerHTML = new TextDecoder().decode(
|
||||
Uint8Array.from(atob(node.attrs.preview), (char) =>
|
||||
char.charCodeAt(0),
|
||||
),
|
||||
)
|
||||
dom.appendChild(preview)
|
||||
}
|
||||
|
||||
return {
|
||||
dom,
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
addOptions() {
|
||||
return {
|
||||
deleteCustomBlockButtonIconHtml: null,
|
||||
editCustomBlockButtonIconHtml: null,
|
||||
editCustomBlockUsing: () => {},
|
||||
insertCustomBlockUsing: () => {},
|
||||
}
|
||||
},
|
||||
|
||||
addAttributes() {
|
||||
return {
|
||||
config: {
|
||||
default: null,
|
||||
parseHTML: (element) =>
|
||||
JSON.parse(element.getAttribute('data-config')),
|
||||
renderHTML: (attributes) => {
|
||||
if (!attributes.config) {
|
||||
return {}
|
||||
}
|
||||
|
||||
return {
|
||||
'data-config': JSON.stringify(attributes.config),
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
id: {
|
||||
default: null,
|
||||
parseHTML: (element) => element.getAttribute('data-id'),
|
||||
renderHTML: (attributes) => {
|
||||
if (!attributes.id) {
|
||||
return {}
|
||||
}
|
||||
|
||||
return {
|
||||
'data-id': attributes.id,
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
label: {
|
||||
default: null,
|
||||
parseHTML: (element) => element.getAttribute('data-label'),
|
||||
rendered: false,
|
||||
},
|
||||
|
||||
preview: {
|
||||
default: null,
|
||||
parseHTML: (element) => element.getAttribute('data-preview'),
|
||||
rendered: false,
|
||||
},
|
||||
|
||||
shouldApplyProseStylingToPreview: {
|
||||
default: false,
|
||||
rendered: false,
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
parseHTML() {
|
||||
return [
|
||||
{
|
||||
tag: `div[data-type="${this.name}"]`,
|
||||
},
|
||||
]
|
||||
},
|
||||
|
||||
renderHTML({ HTMLAttributes }) {
|
||||
return [
|
||||
'div',
|
||||
mergeAttributes({ 'data-type': 'customBlock' }, HTMLAttributes),
|
||||
]
|
||||
},
|
||||
|
||||
addKeyboardShortcuts() {
|
||||
return {
|
||||
Backspace: () =>
|
||||
this.editor.commands.command(({ tr, state }) => {
|
||||
let isCustomBlock = false
|
||||
const { selection } = state
|
||||
const { empty, anchor } = selection
|
||||
|
||||
if (!empty) {
|
||||
return false
|
||||
}
|
||||
|
||||
// Store node and position for later use
|
||||
let customBlockNode = new ProseMirrorNode()
|
||||
let customBlockPos = 0
|
||||
|
||||
state.doc.nodesBetween(anchor - 1, anchor, (node, pos) => {
|
||||
if (node.type.name === this.name) {
|
||||
isCustomBlock = true
|
||||
customBlockNode = node
|
||||
customBlockPos = pos
|
||||
return false
|
||||
}
|
||||
})
|
||||
|
||||
return isCustomBlock
|
||||
}),
|
||||
}
|
||||
},
|
||||
|
||||
addProseMirrorPlugins() {
|
||||
const { insertCustomBlockUsing } = this.options
|
||||
|
||||
return [
|
||||
new Plugin({
|
||||
props: {
|
||||
handleDrop(view, event) {
|
||||
if (!event) {
|
||||
return false
|
||||
}
|
||||
|
||||
event.preventDefault()
|
||||
|
||||
if (!event.dataTransfer.getData('customBlock')) {
|
||||
return false
|
||||
}
|
||||
|
||||
const customBlockId =
|
||||
event.dataTransfer.getData('customBlock')
|
||||
|
||||
insertCustomBlockUsing(
|
||||
customBlockId,
|
||||
view.posAtCoords({
|
||||
left: event.clientX,
|
||||
top: event.clientY,
|
||||
}).pos,
|
||||
)
|
||||
|
||||
return false
|
||||
},
|
||||
},
|
||||
}),
|
||||
]
|
||||
},
|
||||
})
|
||||
58
vendor/filament/forms/resources/js/components/rich-editor/extension-grid-column.js
vendored
Normal file
58
vendor/filament/forms/resources/js/components/rich-editor/extension-grid-column.js
vendored
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
import { Node, mergeAttributes } from '@tiptap/core'
|
||||
|
||||
export default Node.create({
|
||||
name: 'gridColumn',
|
||||
|
||||
content: 'block+',
|
||||
|
||||
isolating: true,
|
||||
|
||||
addOptions() {
|
||||
return {
|
||||
HTMLAttributes: {
|
||||
class: 'grid-layout-col',
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
addAttributes() {
|
||||
return {
|
||||
'data-col-span': {
|
||||
default: 1,
|
||||
parseHTML: (element) => element.getAttribute('data-col-span'),
|
||||
renderHTML: (attributes) => {
|
||||
return {
|
||||
'data-col-span': attributes['data-col-span'] ?? 1,
|
||||
}
|
||||
},
|
||||
},
|
||||
style: {
|
||||
default: null,
|
||||
parseHTML: (element) => element.getAttribute('style'),
|
||||
renderHTML: (attributes) => {
|
||||
return {
|
||||
style: `grid-column: span ${attributes['data-col-span'] ?? 1};`,
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
parseHTML() {
|
||||
return [
|
||||
{
|
||||
tag: 'div',
|
||||
getAttrs: (node) =>
|
||||
node.classList.contains('grid-layout-col') && null,
|
||||
},
|
||||
]
|
||||
},
|
||||
|
||||
renderHTML({ HTMLAttributes }) {
|
||||
return [
|
||||
'div',
|
||||
mergeAttributes(this.options.HTMLAttributes, HTMLAttributes),
|
||||
0,
|
||||
]
|
||||
},
|
||||
})
|
||||
132
vendor/filament/forms/resources/js/components/rich-editor/extension-grid.js
vendored
Normal file
132
vendor/filament/forms/resources/js/components/rich-editor/extension-grid.js
vendored
Normal file
|
|
@ -0,0 +1,132 @@
|
|||
import { mergeAttributes, Node } from '@tiptap/core'
|
||||
import { TextSelection } from '@tiptap/pm/state'
|
||||
|
||||
export default Node.create({
|
||||
name: 'grid',
|
||||
|
||||
group: 'block',
|
||||
|
||||
defining: true,
|
||||
|
||||
isolating: true,
|
||||
|
||||
allowGapCursor: false,
|
||||
|
||||
content: 'gridColumn+',
|
||||
|
||||
addOptions() {
|
||||
return {
|
||||
HTMLAttributes: {
|
||||
class: 'grid-layout',
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
addAttributes() {
|
||||
return {
|
||||
'data-cols': {
|
||||
default: 2,
|
||||
parseHTML: (element) => element.getAttribute('data-cols'),
|
||||
},
|
||||
'data-from-breakpoint': {
|
||||
default: 'md',
|
||||
parseHTML: (element) =>
|
||||
element.getAttribute('data-from-breakpoint'),
|
||||
},
|
||||
style: {
|
||||
default: null,
|
||||
parseHTML: (element) => element.getAttribute('style'),
|
||||
renderHTML: (attributes) => {
|
||||
return {
|
||||
style: `grid-template-columns: repeat(${attributes['data-cols']}, 1fr)`,
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
parseHTML() {
|
||||
return [
|
||||
{
|
||||
tag: 'div',
|
||||
getAttrs: (node) =>
|
||||
node.classList.contains('grid-layout') && null,
|
||||
},
|
||||
]
|
||||
},
|
||||
|
||||
renderHTML({ HTMLAttributes }) {
|
||||
return [
|
||||
'div',
|
||||
mergeAttributes(this.options.HTMLAttributes, HTMLAttributes),
|
||||
0,
|
||||
]
|
||||
},
|
||||
|
||||
addCommands() {
|
||||
return {
|
||||
insertGrid:
|
||||
({
|
||||
columns = [1, 1],
|
||||
fromBreakpoint,
|
||||
coordinates = null,
|
||||
} = {}) =>
|
||||
({ tr, dispatch, editor }) => {
|
||||
const columnNodeType = editor.schema.nodes.gridColumn
|
||||
|
||||
const spans =
|
||||
Array.isArray(columns) && columns.length
|
||||
? columns
|
||||
: [1, 1]
|
||||
|
||||
const columnNodes = []
|
||||
|
||||
for (let index = 0; index < spans.length; index += 1) {
|
||||
columnNodes.push(
|
||||
columnNodeType.createAndFill({
|
||||
'data-col-span': Number(spans[index] ?? 1) || 1,
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
const totalColumnsCount = spans
|
||||
.map((v) => Number(v) || 1)
|
||||
.reduce((a, b) => a + b, 0)
|
||||
|
||||
const node = editor.schema.nodes.grid.createChecked(
|
||||
{
|
||||
'data-cols': totalColumnsCount,
|
||||
'data-from-breakpoint': fromBreakpoint,
|
||||
},
|
||||
columnNodes,
|
||||
)
|
||||
|
||||
if (dispatch) {
|
||||
const offset = tr.selection.anchor + 1
|
||||
|
||||
if (![null, undefined].includes(coordinates?.from)) {
|
||||
tr.replaceRangeWith(
|
||||
coordinates.from,
|
||||
coordinates.to,
|
||||
node,
|
||||
)
|
||||
.scrollIntoView()
|
||||
.setSelection(
|
||||
TextSelection.near(
|
||||
tr.doc.resolve(coordinates.from),
|
||||
),
|
||||
)
|
||||
} else {
|
||||
tr.replaceSelectionWith(node)
|
||||
.scrollIntoView()
|
||||
.setSelection(
|
||||
TextSelection.near(tr.doc.resolve(offset)),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
},
|
||||
}
|
||||
},
|
||||
})
|
||||
62
vendor/filament/forms/resources/js/components/rich-editor/extension-image.js
vendored
Normal file
62
vendor/filament/forms/resources/js/components/rich-editor/extension-image.js
vendored
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
import Image from '@tiptap/extension-image'
|
||||
|
||||
const normalizeStyleLength = (value) =>
|
||||
/^\d+(?:\.\d+)?$/.test(value) ? `${value}px` : value
|
||||
|
||||
export default Image.extend({
|
||||
addAttributes() {
|
||||
return {
|
||||
...this.parent?.(),
|
||||
|
||||
id: {
|
||||
default: null,
|
||||
parseHTML: (element) => element.getAttribute('data-id'),
|
||||
renderHTML: (attributes) => {
|
||||
if (!attributes.id) {
|
||||
return {}
|
||||
}
|
||||
|
||||
return {
|
||||
'data-id': attributes.id,
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
width: {
|
||||
default: null,
|
||||
parseHTML: (element) =>
|
||||
element.getAttribute('width') ||
|
||||
element.style.width ||
|
||||
null,
|
||||
renderHTML: (attributes) => {
|
||||
if (!attributes.width) {
|
||||
return {}
|
||||
}
|
||||
|
||||
return {
|
||||
width: attributes.width,
|
||||
style: `width: ${normalizeStyleLength(attributes.width)}`,
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
height: {
|
||||
default: null,
|
||||
parseHTML: (element) =>
|
||||
element.getAttribute('height') ||
|
||||
element.style.height ||
|
||||
null,
|
||||
renderHTML: (attributes) => {
|
||||
if (!attributes.height) {
|
||||
return {}
|
||||
}
|
||||
|
||||
return {
|
||||
height: attributes.height,
|
||||
style: `height: ${normalizeStyleLength(attributes.height)}`,
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
},
|
||||
})
|
||||
44
vendor/filament/forms/resources/js/components/rich-editor/extension-lead.js
vendored
Normal file
44
vendor/filament/forms/resources/js/components/rich-editor/extension-lead.js
vendored
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
import { Node, mergeAttributes } from '@tiptap/core'
|
||||
|
||||
export default Node.create({
|
||||
name: 'lead',
|
||||
|
||||
group: 'block',
|
||||
|
||||
content: 'block+',
|
||||
|
||||
addOptions() {
|
||||
return {
|
||||
HTMLAttributes: {
|
||||
class: 'lead',
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
parseHTML() {
|
||||
return [
|
||||
{
|
||||
tag: 'div',
|
||||
getAttrs: (element) => element.classList.contains('lead'),
|
||||
},
|
||||
]
|
||||
},
|
||||
|
||||
renderHTML({ HTMLAttributes }) {
|
||||
return [
|
||||
'div',
|
||||
mergeAttributes(this.options.HTMLAttributes, HTMLAttributes),
|
||||
0,
|
||||
]
|
||||
},
|
||||
|
||||
addCommands() {
|
||||
return {
|
||||
toggleLead:
|
||||
() =>
|
||||
({ commands }) => {
|
||||
return commands.toggleWrap(this.name)
|
||||
},
|
||||
}
|
||||
},
|
||||
})
|
||||
464
vendor/filament/forms/resources/js/components/rich-editor/extension-local-files.js
vendored
Normal file
464
vendor/filament/forms/resources/js/components/rich-editor/extension-local-files.js
vendored
Normal file
|
|
@ -0,0 +1,464 @@
|
|||
import { Extension } from '@tiptap/core'
|
||||
import { DOMParser as ProseMirrorDOMParser } from '@tiptap/pm/model'
|
||||
import { Plugin, PluginKey } from '@tiptap/pm/state'
|
||||
|
||||
const dispatchFormEvent = (editorView, name, detail = {}) => {
|
||||
editorView.dom.closest('form')?.dispatchEvent(
|
||||
new CustomEvent(name, {
|
||||
composed: true,
|
||||
cancelable: true,
|
||||
detail,
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
const validateFiles = ({
|
||||
files,
|
||||
acceptedTypes,
|
||||
acceptedTypesValidationMessage,
|
||||
maxSize,
|
||||
maxSizeValidationMessage,
|
||||
}) => {
|
||||
for (const file of files) {
|
||||
if (acceptedTypes && !acceptedTypes.includes(file.type)) {
|
||||
return acceptedTypesValidationMessage
|
||||
}
|
||||
|
||||
if (maxSize && file.size > +maxSize * 1024) {
|
||||
return maxSizeValidationMessage
|
||||
}
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
const generateFileKey = () =>
|
||||
([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, (c) =>
|
||||
(
|
||||
c ^
|
||||
(crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (c / 4)))
|
||||
).toString(16),
|
||||
)
|
||||
|
||||
const LocalFilesPlugin = ({
|
||||
editor,
|
||||
acceptedTypes,
|
||||
acceptedTypesValidationMessage,
|
||||
get$WireUsing,
|
||||
key,
|
||||
maxSize,
|
||||
maxSizeValidationMessage,
|
||||
statePath,
|
||||
uploadingMessage,
|
||||
}) => {
|
||||
const getFileAttachmentUrl = (fileKey) => {
|
||||
return Livewire.fireAction(
|
||||
get$WireUsing().__instance,
|
||||
'callSchemaComponentMethod',
|
||||
[
|
||||
key,
|
||||
'getUploadedFileAttachmentTemporaryUrl',
|
||||
{
|
||||
attachment: fileKey,
|
||||
},
|
||||
],
|
||||
{ async: true },
|
||||
)
|
||||
}
|
||||
|
||||
return new Plugin({
|
||||
key: new PluginKey('localFiles'),
|
||||
props: {
|
||||
handleDrop(editorView, event) {
|
||||
if (!event.dataTransfer?.files.length) {
|
||||
return false
|
||||
}
|
||||
|
||||
const files = Array.from(event.dataTransfer.files)
|
||||
|
||||
const validationMessage = validateFiles({
|
||||
files,
|
||||
acceptedTypes,
|
||||
acceptedTypesValidationMessage,
|
||||
maxSize,
|
||||
maxSizeValidationMessage,
|
||||
})
|
||||
|
||||
if (validationMessage) {
|
||||
editorView.dom.dispatchEvent(
|
||||
new CustomEvent('rich-editor-file-validation-message', {
|
||||
bubbles: true,
|
||||
detail: {
|
||||
key,
|
||||
livewireId: get$WireUsing().id,
|
||||
validationMessage,
|
||||
},
|
||||
}),
|
||||
)
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
if (!files.length) {
|
||||
return false
|
||||
}
|
||||
|
||||
dispatchFormEvent(editorView, 'form-processing-started', {
|
||||
message: uploadingMessage,
|
||||
})
|
||||
|
||||
event.preventDefault()
|
||||
event.stopPropagation()
|
||||
|
||||
const position = editorView.posAtCoords({
|
||||
left: event.clientX,
|
||||
top: event.clientY,
|
||||
})
|
||||
|
||||
files.forEach((file, fileIndex) => {
|
||||
editor.setEditable(false)
|
||||
editorView.dom.dispatchEvent(
|
||||
new CustomEvent('rich-editor-uploading-file', {
|
||||
bubbles: true,
|
||||
detail: {
|
||||
key,
|
||||
livewireId: get$WireUsing().id,
|
||||
},
|
||||
}),
|
||||
)
|
||||
|
||||
const fileKey = generateFileKey()
|
||||
|
||||
get$WireUsing().upload(
|
||||
`componentFileAttachments.${statePath}.${fileKey}`,
|
||||
file,
|
||||
() => {
|
||||
getFileAttachmentUrl(fileKey).then((url) => {
|
||||
if (!url) {
|
||||
return
|
||||
}
|
||||
|
||||
editor
|
||||
.chain()
|
||||
.insertContentAt(position?.pos ?? 0, {
|
||||
type: 'image',
|
||||
attrs: {
|
||||
id: fileKey,
|
||||
src: url,
|
||||
},
|
||||
})
|
||||
.run()
|
||||
|
||||
editor.setEditable(true)
|
||||
editorView.dom.dispatchEvent(
|
||||
new CustomEvent(
|
||||
'rich-editor-uploaded-file',
|
||||
{
|
||||
bubbles: true,
|
||||
detail: {
|
||||
key,
|
||||
livewireId: get$WireUsing().id,
|
||||
},
|
||||
},
|
||||
),
|
||||
)
|
||||
|
||||
if (fileIndex === files.length - 1) {
|
||||
dispatchFormEvent(
|
||||
editorView,
|
||||
'form-processing-finished',
|
||||
)
|
||||
}
|
||||
})
|
||||
},
|
||||
)
|
||||
})
|
||||
|
||||
return true
|
||||
},
|
||||
handlePaste(editorView, event) {
|
||||
const files = event.clipboardData?.files?.length
|
||||
? Array.from(event.clipboardData.files)
|
||||
: []
|
||||
const hasText = event.clipboardData?.getData('text')?.length > 0
|
||||
const html = event.clipboardData?.getData('text/html') || ''
|
||||
|
||||
if (files.length && !hasText) {
|
||||
const validationMessage = validateFiles({
|
||||
files,
|
||||
acceptedTypes,
|
||||
acceptedTypesValidationMessage,
|
||||
maxSize,
|
||||
maxSizeValidationMessage,
|
||||
})
|
||||
|
||||
if (validationMessage) {
|
||||
editorView.dom.dispatchEvent(
|
||||
new CustomEvent(
|
||||
'rich-editor-file-validation-message',
|
||||
{
|
||||
bubbles: true,
|
||||
detail: {
|
||||
key,
|
||||
livewireId: get$WireUsing().id,
|
||||
validationMessage,
|
||||
},
|
||||
},
|
||||
),
|
||||
)
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
event.preventDefault()
|
||||
event.stopPropagation()
|
||||
|
||||
dispatchFormEvent(editorView, 'form-processing-started', {
|
||||
message: uploadingMessage,
|
||||
})
|
||||
|
||||
files.forEach((file, fileIndex) => {
|
||||
editor.setEditable(false)
|
||||
editorView.dom.dispatchEvent(
|
||||
new CustomEvent('rich-editor-uploading-file', {
|
||||
bubbles: true,
|
||||
detail: {
|
||||
key,
|
||||
livewireId: get$WireUsing().id,
|
||||
},
|
||||
}),
|
||||
)
|
||||
|
||||
const fileKey = generateFileKey()
|
||||
|
||||
get$WireUsing().upload(
|
||||
`componentFileAttachments.${statePath}.${fileKey}`,
|
||||
file,
|
||||
() => {
|
||||
getFileAttachmentUrl(fileKey).then((url) => {
|
||||
if (!url) {
|
||||
return
|
||||
}
|
||||
|
||||
editor
|
||||
.chain()
|
||||
.insertContentAt(
|
||||
editor.state.selection.anchor,
|
||||
{
|
||||
type: 'image',
|
||||
attrs: {
|
||||
id: fileKey,
|
||||
src: url,
|
||||
},
|
||||
},
|
||||
)
|
||||
.run()
|
||||
|
||||
editor.setEditable(true)
|
||||
editorView.dom.dispatchEvent(
|
||||
new CustomEvent(
|
||||
'rich-editor-uploaded-file',
|
||||
{
|
||||
bubbles: true,
|
||||
detail: {
|
||||
key,
|
||||
livewireId:
|
||||
get$WireUsing().id,
|
||||
},
|
||||
},
|
||||
),
|
||||
)
|
||||
|
||||
if (fileIndex === files.length - 1) {
|
||||
dispatchFormEvent(
|
||||
editorView,
|
||||
'form-processing-finished',
|
||||
)
|
||||
}
|
||||
})
|
||||
},
|
||||
)
|
||||
})
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
if (html) {
|
||||
const domParser = new DOMParser()
|
||||
const parsed = domParser.parseFromString(html, 'text/html')
|
||||
const images = parsed.querySelectorAll('img[src]')
|
||||
|
||||
if (images.length) {
|
||||
event.stopPropagation()
|
||||
|
||||
const { from, to } = editor.state.selection
|
||||
|
||||
dispatchFormEvent(
|
||||
editorView,
|
||||
'form-processing-started',
|
||||
{ message: uploadingMessage },
|
||||
)
|
||||
|
||||
editor.setEditable(false)
|
||||
|
||||
editorView.dom.dispatchEvent(
|
||||
new CustomEvent('rich-editor-uploading-file', {
|
||||
bubbles: true,
|
||||
detail: {
|
||||
key,
|
||||
livewireId: get$WireUsing().id,
|
||||
},
|
||||
}),
|
||||
)
|
||||
;(async () => {
|
||||
for (const image of images) {
|
||||
const src = image.getAttribute('src')
|
||||
|
||||
if (!src.startsWith('data:image/')) {
|
||||
continue
|
||||
}
|
||||
|
||||
let blob
|
||||
|
||||
try {
|
||||
const [header, base64] = src.split(',')
|
||||
const mimeType = header.match(/:(.*?);/)[1]
|
||||
const bytes = atob(base64)
|
||||
const array = new Uint8Array(bytes.length)
|
||||
|
||||
for (let i = 0; i < bytes.length; i++) {
|
||||
array[i] = bytes.charCodeAt(i)
|
||||
}
|
||||
|
||||
blob = new Blob([array], {
|
||||
type: mimeType,
|
||||
})
|
||||
} catch {
|
||||
continue
|
||||
}
|
||||
|
||||
const extension =
|
||||
blob.type.split('/')[1]?.split('+')[0] ||
|
||||
'png'
|
||||
const file = new File(
|
||||
[blob],
|
||||
`image.${extension}`,
|
||||
{ type: blob.type },
|
||||
)
|
||||
|
||||
const validationMessage = validateFiles({
|
||||
files: [file],
|
||||
acceptedTypes,
|
||||
acceptedTypesValidationMessage,
|
||||
maxSize,
|
||||
maxSizeValidationMessage,
|
||||
})
|
||||
|
||||
if (validationMessage) {
|
||||
continue
|
||||
}
|
||||
|
||||
const fileKey = generateFileKey()
|
||||
|
||||
const url = await new Promise((resolve) => {
|
||||
get$WireUsing().upload(
|
||||
`componentFileAttachments.${statePath}.${fileKey}`,
|
||||
file,
|
||||
() => {
|
||||
getFileAttachmentUrl(fileKey).then(
|
||||
(uploadedUrl) =>
|
||||
resolve(
|
||||
uploadedUrl ?? null,
|
||||
),
|
||||
)
|
||||
},
|
||||
() => resolve(null),
|
||||
)
|
||||
})
|
||||
|
||||
if (url) {
|
||||
image.setAttribute('src', url)
|
||||
image.setAttribute('data-id', fileKey)
|
||||
}
|
||||
}
|
||||
|
||||
for (const image of Array.from(
|
||||
parsed.querySelectorAll('img[src]'),
|
||||
)) {
|
||||
const p = parsed.createElement('p')
|
||||
image.replaceWith(p)
|
||||
p.appendChild(image)
|
||||
}
|
||||
|
||||
let cleanedHtml = parsed.body.innerHTML
|
||||
|
||||
editor.view.someProp('transformPastedHTML', (f) => {
|
||||
cleanedHtml = f(cleanedHtml)
|
||||
})
|
||||
|
||||
const wrapper = document.createElement('div')
|
||||
wrapper.innerHTML = cleanedHtml
|
||||
|
||||
const slice = ProseMirrorDOMParser.fromSchema(
|
||||
editor.state.schema,
|
||||
).parseSlice(wrapper, {
|
||||
preserveWhitespace: false,
|
||||
})
|
||||
|
||||
editor.view.dispatch(
|
||||
editor.state.tr.replaceRange(from, to, slice),
|
||||
)
|
||||
|
||||
editor.setEditable(true)
|
||||
|
||||
editorView.dom.dispatchEvent(
|
||||
new CustomEvent('rich-editor-uploaded-file', {
|
||||
bubbles: true,
|
||||
detail: {
|
||||
key,
|
||||
livewireId: get$WireUsing().id,
|
||||
},
|
||||
}),
|
||||
)
|
||||
|
||||
dispatchFormEvent(
|
||||
editorView,
|
||||
'form-processing-finished',
|
||||
)
|
||||
})()
|
||||
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export default Extension.create({
|
||||
name: 'localFiles',
|
||||
|
||||
addOptions() {
|
||||
return {
|
||||
acceptedTypes: [],
|
||||
acceptedTypesValidationMessage: null,
|
||||
key: null,
|
||||
maxSize: null,
|
||||
maxSizeValidationMessage: null,
|
||||
statePath: null,
|
||||
uploadingMessage: null,
|
||||
get$WireUsing: null,
|
||||
}
|
||||
},
|
||||
|
||||
addProseMirrorPlugins() {
|
||||
return [
|
||||
LocalFilesPlugin({
|
||||
editor: this.editor,
|
||||
...this.options,
|
||||
}),
|
||||
]
|
||||
},
|
||||
})
|
||||
446
vendor/filament/forms/resources/js/components/rich-editor/extension-mention.js
vendored
Normal file
446
vendor/filament/forms/resources/js/components/rich-editor/extension-mention.js
vendored
Normal file
|
|
@ -0,0 +1,446 @@
|
|||
import { mergeAttributes, Node } from '@tiptap/core'
|
||||
import { Node as ProseMirrorNode } from '@tiptap/pm/model'
|
||||
import { Plugin, PluginKey } from '@tiptap/pm/state'
|
||||
import Suggestion from '@tiptap/suggestion'
|
||||
import getMentionSuggestion from './mention-suggestion.js'
|
||||
|
||||
const getSuggestionOptions = function ({
|
||||
editor: tiptapEditor,
|
||||
overrideSuggestionOptions,
|
||||
extensionName,
|
||||
}) {
|
||||
const pluginKey = new PluginKey()
|
||||
|
||||
const triggerChar = overrideSuggestionOptions?.char ?? '@'
|
||||
const extraAttributes = overrideSuggestionOptions?.extraAttributes ?? {}
|
||||
|
||||
return {
|
||||
editor: tiptapEditor,
|
||||
char: triggerChar,
|
||||
pluginKey,
|
||||
command: ({ editor, range, props }) => {
|
||||
const nodeAfter = editor.view.state.selection.$to.nodeAfter
|
||||
const overrideSpace = nodeAfter?.text?.startsWith(' ')
|
||||
|
||||
if (overrideSpace) {
|
||||
range.to += 1
|
||||
}
|
||||
|
||||
const mentionAttrs = {
|
||||
...props,
|
||||
char: triggerChar,
|
||||
extra: extraAttributes,
|
||||
}
|
||||
|
||||
editor
|
||||
.chain()
|
||||
.focus()
|
||||
.insertContentAt(range, [
|
||||
{
|
||||
type: extensionName,
|
||||
attrs: mentionAttrs,
|
||||
},
|
||||
{
|
||||
type: 'text',
|
||||
text: ' ',
|
||||
},
|
||||
])
|
||||
.run()
|
||||
|
||||
editor.view.dom.ownerDocument.defaultView
|
||||
?.getSelection()
|
||||
?.collapseToEnd()
|
||||
},
|
||||
allow: ({ state, range }) => {
|
||||
const $from = state.doc.resolve(range.from)
|
||||
const type = state.schema.nodes[extensionName]
|
||||
const allow = !!$from.parent.type.contentMatch.matchType(type)
|
||||
|
||||
return allow
|
||||
},
|
||||
...overrideSuggestionOptions,
|
||||
}
|
||||
}
|
||||
|
||||
export default Node.create({
|
||||
name: 'mention',
|
||||
|
||||
priority: 101,
|
||||
|
||||
addStorage() {
|
||||
return {
|
||||
suggestions: [],
|
||||
getSuggestionFromChar: () => null,
|
||||
}
|
||||
},
|
||||
|
||||
addOptions() {
|
||||
return {
|
||||
HTMLAttributes: {},
|
||||
renderText({ node }) {
|
||||
const char = node.attrs.char ?? '@'
|
||||
return `${char}`
|
||||
},
|
||||
deleteTriggerWithBackspace: true,
|
||||
renderHTML({ options, node }) {
|
||||
return [
|
||||
'span',
|
||||
mergeAttributes(
|
||||
this.HTMLAttributes,
|
||||
options.HTMLAttributes,
|
||||
),
|
||||
`${node.attrs.char ?? '@'}${node.attrs.label ?? ''}`,
|
||||
]
|
||||
},
|
||||
suggestions: [],
|
||||
suggestion: {},
|
||||
getMentionLabelsUsing: null,
|
||||
}
|
||||
},
|
||||
|
||||
group: 'inline',
|
||||
|
||||
inline: true,
|
||||
|
||||
selectable: false,
|
||||
|
||||
atom: true,
|
||||
|
||||
addAttributes() {
|
||||
return {
|
||||
id: {
|
||||
default: null,
|
||||
parseHTML: (element) => element.getAttribute('data-id'),
|
||||
renderHTML: (attributes) => {
|
||||
if (!attributes.id) {
|
||||
return {}
|
||||
}
|
||||
|
||||
return {
|
||||
'data-id': attributes.id,
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
label: {
|
||||
default: null,
|
||||
keepOnSplit: false,
|
||||
parseHTML: (element) => element.getAttribute('data-label'),
|
||||
renderHTML: (attributes) => {
|
||||
if (!attributes.label) {
|
||||
return {}
|
||||
}
|
||||
|
||||
return {
|
||||
'data-label': attributes.label,
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
char: {
|
||||
default: '@',
|
||||
parseHTML: (element) =>
|
||||
element.getAttribute('data-char') ?? '@',
|
||||
renderHTML: (attributes) => {
|
||||
if (!attributes.char) {
|
||||
return {}
|
||||
}
|
||||
|
||||
return {
|
||||
'data-char': attributes.char,
|
||||
}
|
||||
},
|
||||
},
|
||||
extra: {
|
||||
default: null,
|
||||
renderHTML: (attributes) => {
|
||||
const value = attributes?.extra
|
||||
if (!value || typeof value !== 'object') return {}
|
||||
return value
|
||||
},
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
parseHTML() {
|
||||
return [
|
||||
{
|
||||
tag: `span[data-type="${this.name}"]`,
|
||||
},
|
||||
]
|
||||
},
|
||||
|
||||
renderHTML({ node, HTMLAttributes }) {
|
||||
const suggestion = this.editor?.extensionStorage?.[
|
||||
this.name
|
||||
]?.getSuggestionFromChar(node?.attrs?.char ?? '@')
|
||||
|
||||
const mergedOptions = { ...this.options }
|
||||
|
||||
mergedOptions.HTMLAttributes = mergeAttributes(
|
||||
{ 'data-type': this.name },
|
||||
this.options.HTMLAttributes,
|
||||
HTMLAttributes,
|
||||
)
|
||||
|
||||
const html = this.options.renderHTML({
|
||||
options: mergedOptions,
|
||||
node,
|
||||
suggestion,
|
||||
})
|
||||
|
||||
if (typeof html === 'string') {
|
||||
return [
|
||||
'span',
|
||||
mergeAttributes(
|
||||
{ 'data-type': this.name },
|
||||
this.options.HTMLAttributes,
|
||||
HTMLAttributes,
|
||||
),
|
||||
html,
|
||||
]
|
||||
}
|
||||
return html
|
||||
},
|
||||
|
||||
renderText({ node }) {
|
||||
const args = {
|
||||
options: this.options,
|
||||
node,
|
||||
suggestion: this.editor?.extensionStorage?.[
|
||||
this.name
|
||||
]?.getSuggestionFromChar(node?.attrs?.char ?? '@'),
|
||||
}
|
||||
return this.options.renderText(args)
|
||||
},
|
||||
|
||||
addKeyboardShortcuts() {
|
||||
return {
|
||||
Backspace: () =>
|
||||
this.editor.commands.command(({ tr: transaction, state }) => {
|
||||
let isMention = false
|
||||
const { selection } = state
|
||||
const { empty, anchor } = selection
|
||||
|
||||
if (!empty) {
|
||||
return false
|
||||
}
|
||||
|
||||
let mentionNode = new ProseMirrorNode()
|
||||
let mentionPos = 0
|
||||
|
||||
state.doc.nodesBetween(anchor - 1, anchor, (node, pos) => {
|
||||
if (node.type.name === this.name) {
|
||||
isMention = true
|
||||
mentionNode = node
|
||||
mentionPos = pos
|
||||
return false
|
||||
}
|
||||
})
|
||||
|
||||
if (isMention) {
|
||||
const trigger = mentionNode?.attrs?.char ?? '@'
|
||||
transaction.insertText(
|
||||
this.options.deleteTriggerWithBackspace
|
||||
? ''
|
||||
: trigger,
|
||||
mentionPos,
|
||||
mentionPos + mentionNode.nodeSize,
|
||||
)
|
||||
}
|
||||
|
||||
return isMention
|
||||
}),
|
||||
}
|
||||
},
|
||||
|
||||
addProseMirrorPlugins() {
|
||||
const hydrateMentions = async (view) => {
|
||||
const { state, dispatch } = view
|
||||
const pending = []
|
||||
|
||||
state.doc.descendants((node, pos) => {
|
||||
if (node.type.name !== this.name) return
|
||||
if (node.attrs?.label) return
|
||||
const id = node.attrs?.id
|
||||
const char = node.attrs?.char ?? '@'
|
||||
if (!id) return
|
||||
pending.push({ id, char, pos })
|
||||
})
|
||||
|
||||
if (pending.length === 0) return
|
||||
|
||||
const getMentionLabelsUsing = this.options.getMentionLabelsUsing
|
||||
if (typeof getMentionLabelsUsing !== 'function') return
|
||||
|
||||
try {
|
||||
const mentions = pending.map(({ id, char }) => ({ id, char }))
|
||||
const labels = await getMentionLabelsUsing(mentions)
|
||||
|
||||
pending.forEach(({ id, pos }) => {
|
||||
const label = labels[id]
|
||||
if (!label) return
|
||||
const current = view.state.doc.nodeAt(pos)
|
||||
if (!current || current.type.name !== this.name) return
|
||||
const attrs = { ...current.attrs, label }
|
||||
const transaction = view.state.tr.setNodeMarkup(
|
||||
pos,
|
||||
undefined,
|
||||
attrs,
|
||||
)
|
||||
dispatch(transaction)
|
||||
})
|
||||
} catch {}
|
||||
}
|
||||
|
||||
return [
|
||||
...this.storage.suggestions.map(Suggestion),
|
||||
new Plugin({
|
||||
view: (view) => {
|
||||
setTimeout(() => hydrateMentions(view), 0)
|
||||
return {
|
||||
update: (view) => hydrateMentions(view),
|
||||
}
|
||||
},
|
||||
}),
|
||||
]
|
||||
},
|
||||
|
||||
onBeforeCreate() {
|
||||
const toItemsArray = (value) => {
|
||||
if (Array.isArray(value)) {
|
||||
return value
|
||||
}
|
||||
|
||||
if (value && typeof value === 'object') {
|
||||
return Object.entries(value).map(([id, label]) => ({
|
||||
id,
|
||||
label,
|
||||
}))
|
||||
}
|
||||
|
||||
return []
|
||||
}
|
||||
|
||||
const configured = this.options.suggestions.length
|
||||
? this.options.suggestions
|
||||
: [this.options.suggestion]
|
||||
|
||||
this.storage.suggestions = configured.map((suggestionConfig) => {
|
||||
const char = suggestionConfig?.char ?? '@'
|
||||
const baseItems = suggestionConfig?.items ?? []
|
||||
const noOptionsMessage = suggestionConfig?.noOptionsMessage ?? null
|
||||
const noSearchResultsMessage =
|
||||
suggestionConfig?.noSearchResultsMessage ?? null
|
||||
const isSearchable = suggestionConfig?.isSearchable ?? false
|
||||
const getMentionSearchResultsUsing =
|
||||
this.options.getMentionSearchResultsUsing
|
||||
|
||||
let suggestion
|
||||
|
||||
if (typeof suggestionConfig?.items === 'function') {
|
||||
const originalItems = suggestionConfig.items
|
||||
|
||||
suggestion = {
|
||||
...suggestionConfig,
|
||||
items: async (context) => {
|
||||
if (
|
||||
context?.query &&
|
||||
typeof getMentionSearchResultsUsing === 'function'
|
||||
) {
|
||||
try {
|
||||
const results =
|
||||
await getMentionSearchResultsUsing(
|
||||
context?.query,
|
||||
char,
|
||||
)
|
||||
|
||||
return toItemsArray(results)
|
||||
} catch {}
|
||||
}
|
||||
|
||||
return await originalItems(context)
|
||||
},
|
||||
}
|
||||
} else {
|
||||
const extraAttributes = suggestionConfig?.extraAttributes
|
||||
const searchPrompt = suggestionConfig?.searchPrompt ?? null
|
||||
const searchingMessage =
|
||||
suggestionConfig?.searchingMessage ?? null
|
||||
|
||||
suggestion = {
|
||||
...getMentionSuggestion({
|
||||
items: async ({ query }) => {
|
||||
const hasBaseItems = Array.isArray(baseItems)
|
||||
? baseItems.length > 0
|
||||
: baseItems &&
|
||||
typeof baseItems === 'object' &&
|
||||
Object.keys(baseItems).length > 0
|
||||
|
||||
if (!hasBaseItems && !query) {
|
||||
return []
|
||||
}
|
||||
|
||||
const items = toItemsArray(baseItems)
|
||||
|
||||
if (
|
||||
query &&
|
||||
isSearchable &&
|
||||
typeof getMentionSearchResultsUsing ===
|
||||
'function'
|
||||
) {
|
||||
try {
|
||||
const results =
|
||||
await getMentionSearchResultsUsing(
|
||||
query,
|
||||
char,
|
||||
)
|
||||
|
||||
return toItemsArray(results)
|
||||
} catch {}
|
||||
}
|
||||
|
||||
if (!query) {
|
||||
return items
|
||||
}
|
||||
|
||||
const searchQuery = String(query).toLowerCase()
|
||||
|
||||
return items.filter((item) => {
|
||||
const label =
|
||||
typeof item === 'string'
|
||||
? item
|
||||
: (item?.label ?? item?.name ?? '')
|
||||
|
||||
return String(label)
|
||||
.toLowerCase()
|
||||
.includes(searchQuery)
|
||||
})
|
||||
},
|
||||
isSearchable,
|
||||
noOptionsMessage,
|
||||
noSearchResultsMessage,
|
||||
searchPrompt,
|
||||
searchingMessage,
|
||||
}),
|
||||
char,
|
||||
...(extraAttributes ? { extraAttributes } : {}),
|
||||
}
|
||||
}
|
||||
|
||||
return getSuggestionOptions({
|
||||
editor: this.editor,
|
||||
overrideSuggestionOptions: suggestion,
|
||||
extensionName: this.name,
|
||||
})
|
||||
})
|
||||
|
||||
this.storage.getSuggestionFromChar = (char) => {
|
||||
return (
|
||||
this.storage.suggestions.find((item) => item.char === char) ??
|
||||
this.storage.suggestions[0] ??
|
||||
null
|
||||
)
|
||||
}
|
||||
},
|
||||
})
|
||||
279
vendor/filament/forms/resources/js/components/rich-editor/extension-merge-tag.js
vendored
Normal file
279
vendor/filament/forms/resources/js/components/rich-editor/extension-merge-tag.js
vendored
Normal file
|
|
@ -0,0 +1,279 @@
|
|||
import { mergeAttributes, Node } from '@tiptap/core'
|
||||
import { Node as ProseMirrorNode } from '@tiptap/pm/model'
|
||||
import { Plugin, PluginKey } from '@tiptap/pm/state'
|
||||
import Suggestion from '@tiptap/suggestion'
|
||||
|
||||
const getSuggestionOptions = function ({
|
||||
editor: tiptapEditor,
|
||||
overrideSuggestionOptions,
|
||||
extensionName,
|
||||
}) {
|
||||
const pluginKey = new PluginKey()
|
||||
|
||||
return {
|
||||
editor: tiptapEditor,
|
||||
char: '{{',
|
||||
pluginKey,
|
||||
command: ({ editor, range, props }) => {
|
||||
// increase range.to by one when the next node is of type "text"
|
||||
// and starts with a space character
|
||||
const nodeAfter = editor.view.state.selection.$to.nodeAfter
|
||||
const overrideSpace = nodeAfter?.text?.startsWith(' ')
|
||||
|
||||
if (overrideSpace) {
|
||||
range.to += 1
|
||||
}
|
||||
|
||||
editor
|
||||
.chain()
|
||||
.focus()
|
||||
.insertContentAt(range, [
|
||||
{
|
||||
type: extensionName,
|
||||
attrs: { ...props },
|
||||
},
|
||||
{
|
||||
type: 'text',
|
||||
text: ' ',
|
||||
},
|
||||
])
|
||||
.run()
|
||||
|
||||
// get reference to `window` object from editor element, to support cross-frame JS usage
|
||||
editor.view.dom.ownerDocument.defaultView
|
||||
?.getSelection()
|
||||
?.collapseToEnd()
|
||||
},
|
||||
allow: ({ state, range }) => {
|
||||
const $from = state.doc.resolve(range.from)
|
||||
const type = state.schema.nodes[extensionName]
|
||||
const allow = !!$from.parent.type.contentMatch.matchType(type)
|
||||
|
||||
return allow
|
||||
},
|
||||
...overrideSuggestionOptions,
|
||||
}
|
||||
}
|
||||
|
||||
export default Node.create({
|
||||
name: 'mergeTag',
|
||||
|
||||
priority: 101,
|
||||
|
||||
addStorage() {
|
||||
return {
|
||||
mergeTags: [],
|
||||
suggestions: [],
|
||||
getSuggestionFromChar: () => null,
|
||||
}
|
||||
},
|
||||
|
||||
addOptions() {
|
||||
return {
|
||||
HTMLAttributes: {},
|
||||
renderText({ node }) {
|
||||
return `{{ ${this.mergeTags[node.attrs.id]} }}`
|
||||
},
|
||||
deleteTriggerWithBackspace: false,
|
||||
renderHTML({ options, node }) {
|
||||
return [
|
||||
'span',
|
||||
mergeAttributes(
|
||||
this.HTMLAttributes,
|
||||
options.HTMLAttributes,
|
||||
),
|
||||
`${this.mergeTags[node.attrs.id]}`,
|
||||
]
|
||||
},
|
||||
suggestions: [],
|
||||
suggestion: {},
|
||||
}
|
||||
},
|
||||
|
||||
group: 'inline',
|
||||
|
||||
inline: true,
|
||||
|
||||
selectable: false,
|
||||
|
||||
atom: true,
|
||||
|
||||
addAttributes() {
|
||||
return {
|
||||
id: {
|
||||
default: null,
|
||||
parseHTML: (element) => element.getAttribute('data-id'),
|
||||
renderHTML: (attributes) => {
|
||||
if (!attributes.id) {
|
||||
return {}
|
||||
}
|
||||
|
||||
return {
|
||||
'data-id': attributes.id,
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
parseHTML() {
|
||||
return [
|
||||
{
|
||||
tag: `span[data-type="${this.name}"]`,
|
||||
},
|
||||
]
|
||||
},
|
||||
|
||||
renderHTML({ node, HTMLAttributes }) {
|
||||
// We cannot use the `this.storage` property here because, when accessed this method,
|
||||
// it returns the initial value of the extension storage
|
||||
const suggestion =
|
||||
this.editor?.extensionStorage?.[this.name]?.getSuggestionFromChar(
|
||||
'{{',
|
||||
)
|
||||
|
||||
const mergedOptions = { ...this.options }
|
||||
|
||||
mergedOptions.HTMLAttributes = mergeAttributes(
|
||||
{ 'data-type': this.name },
|
||||
this.options.HTMLAttributes,
|
||||
HTMLAttributes,
|
||||
)
|
||||
|
||||
const html = this.options.renderHTML({
|
||||
options: mergedOptions,
|
||||
node,
|
||||
suggestion,
|
||||
})
|
||||
|
||||
if (typeof html === 'string') {
|
||||
return [
|
||||
'span',
|
||||
mergeAttributes(
|
||||
{ 'data-type': this.name },
|
||||
this.options.HTMLAttributes,
|
||||
HTMLAttributes,
|
||||
),
|
||||
html,
|
||||
]
|
||||
}
|
||||
return html
|
||||
},
|
||||
|
||||
renderText({ node }) {
|
||||
const args = {
|
||||
options: this.options,
|
||||
node,
|
||||
suggestion:
|
||||
this.editor?.extensionStorage?.[
|
||||
this.name
|
||||
]?.getSuggestionFromChar('{{'),
|
||||
}
|
||||
|
||||
return this.options.renderText(args)
|
||||
},
|
||||
|
||||
addKeyboardShortcuts() {
|
||||
return {
|
||||
Backspace: () =>
|
||||
this.editor.commands.command(({ tr, state }) => {
|
||||
let isMergeTag = false
|
||||
const { selection } = state
|
||||
const { empty, anchor } = selection
|
||||
|
||||
if (!empty) {
|
||||
return false
|
||||
}
|
||||
|
||||
// Store node and position for later use
|
||||
let mergeTagNode = new ProseMirrorNode()
|
||||
let mergeTagPos = 0
|
||||
|
||||
state.doc.nodesBetween(anchor - 1, anchor, (node, pos) => {
|
||||
if (node.type.name === this.name) {
|
||||
isMergeTag = true
|
||||
mergeTagNode = node
|
||||
mergeTagPos = pos
|
||||
return false
|
||||
}
|
||||
})
|
||||
|
||||
if (isMergeTag) {
|
||||
tr.insertText(
|
||||
this.options.deleteTriggerWithBackspace ? '' : '{{',
|
||||
mergeTagPos,
|
||||
mergeTagPos + mergeTagNode.nodeSize,
|
||||
)
|
||||
}
|
||||
|
||||
return isMergeTag
|
||||
}),
|
||||
}
|
||||
},
|
||||
|
||||
addProseMirrorPlugins() {
|
||||
return [
|
||||
...this.storage.suggestions.map(Suggestion), // Create a plugin for each suggestion configuration
|
||||
new Plugin({
|
||||
props: {
|
||||
handleDrop(view, event) {
|
||||
if (!event) {
|
||||
return false
|
||||
}
|
||||
|
||||
event.preventDefault()
|
||||
|
||||
if (!event.dataTransfer.getData('mergeTag')) {
|
||||
return false
|
||||
}
|
||||
|
||||
const mergeTagId =
|
||||
event.dataTransfer.getData('mergeTag')
|
||||
|
||||
view.dispatch(
|
||||
view.state.tr.insert(
|
||||
view.posAtCoords({
|
||||
left: event.clientX,
|
||||
top: event.clientY,
|
||||
}).pos,
|
||||
view.state.schema.nodes.mergeTag.create({
|
||||
id: mergeTagId,
|
||||
}),
|
||||
),
|
||||
)
|
||||
|
||||
return false
|
||||
},
|
||||
},
|
||||
}),
|
||||
]
|
||||
},
|
||||
|
||||
onBeforeCreate() {
|
||||
this.storage.suggestions = (
|
||||
this.options.suggestions.length
|
||||
? this.options.suggestions
|
||||
: [this.options.suggestion]
|
||||
).map((suggestion) =>
|
||||
getSuggestionOptions({
|
||||
editor: this.editor,
|
||||
overrideSuggestionOptions: suggestion,
|
||||
extensionName: this.name,
|
||||
}),
|
||||
)
|
||||
|
||||
this.storage.getSuggestionFromChar = (char) => {
|
||||
const suggestion = this.storage.suggestions.find(
|
||||
(s) => s.char === char,
|
||||
)
|
||||
if (suggestion) {
|
||||
return suggestion
|
||||
}
|
||||
if (this.storage.suggestions.length) {
|
||||
return this.storage.suggestions[0]
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
},
|
||||
})
|
||||
37
vendor/filament/forms/resources/js/components/rich-editor/extension-small.js
vendored
Normal file
37
vendor/filament/forms/resources/js/components/rich-editor/extension-small.js
vendored
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
import { Mark } from '@tiptap/core'
|
||||
|
||||
export default Mark.create({
|
||||
name: 'small',
|
||||
|
||||
parseHTML() {
|
||||
return [
|
||||
{
|
||||
tag: 'small',
|
||||
},
|
||||
]
|
||||
},
|
||||
|
||||
renderHTML({ HTMLAttributes }) {
|
||||
return ['small', HTMLAttributes, 0]
|
||||
},
|
||||
|
||||
addCommands() {
|
||||
return {
|
||||
setSmall:
|
||||
() =>
|
||||
({ commands }) => {
|
||||
return commands.setMark(this.name)
|
||||
},
|
||||
toggleSmall:
|
||||
() =>
|
||||
({ commands }) => {
|
||||
return commands.toggleMark(this.name)
|
||||
},
|
||||
unsetSmall:
|
||||
() =>
|
||||
({ commands }) => {
|
||||
return commands.unsetMark(this.name)
|
||||
},
|
||||
}
|
||||
},
|
||||
})
|
||||
78
vendor/filament/forms/resources/js/components/rich-editor/extension-text-color.js
vendored
Normal file
78
vendor/filament/forms/resources/js/components/rich-editor/extension-text-color.js
vendored
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
import { Mark } from '@tiptap/core'
|
||||
|
||||
export default Mark.create({
|
||||
name: 'textColor',
|
||||
|
||||
addOptions() {
|
||||
return {
|
||||
textColors: {},
|
||||
}
|
||||
},
|
||||
|
||||
parseHTML() {
|
||||
return [
|
||||
{
|
||||
tag: 'span',
|
||||
getAttrs: (element) => element.classList?.contains('color'),
|
||||
},
|
||||
]
|
||||
},
|
||||
|
||||
renderHTML({ HTMLAttributes }) {
|
||||
const attrs = { ...HTMLAttributes }
|
||||
const existingClass = HTMLAttributes.class
|
||||
attrs.class = ['color', existingClass].filter(Boolean).join(' ')
|
||||
|
||||
const colorName = HTMLAttributes['data-color']
|
||||
const colors = this.options.textColors || {}
|
||||
const config = colors[colorName]
|
||||
|
||||
const hasColorName =
|
||||
typeof colorName === 'string' && colorName.length > 0
|
||||
const cssVars = config
|
||||
? `--color: ${config.color}; --dark-color: ${config.darkColor}`
|
||||
: hasColorName
|
||||
? `--color: ${colorName}; --dark-color: ${colorName}`
|
||||
: null
|
||||
|
||||
if (cssVars) {
|
||||
const existingStyle =
|
||||
typeof HTMLAttributes.style === 'string'
|
||||
? HTMLAttributes.style
|
||||
: ''
|
||||
attrs.style = existingStyle
|
||||
? `${cssVars}; ${existingStyle}`
|
||||
: cssVars
|
||||
}
|
||||
|
||||
return ['span', attrs, 0]
|
||||
},
|
||||
|
||||
addAttributes() {
|
||||
return {
|
||||
'data-color': {
|
||||
default: null,
|
||||
parseHTML: (element) => element.getAttribute('data-color'),
|
||||
renderHTML: (attributes) => {
|
||||
if (!attributes['data-color']) return {}
|
||||
return { 'data-color': attributes['data-color'] }
|
||||
},
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
addCommands() {
|
||||
return {
|
||||
setTextColor:
|
||||
({ color }) =>
|
||||
({ commands }) => {
|
||||
return commands.setMark(this.name, { 'data-color': color })
|
||||
},
|
||||
unsetTextColor:
|
||||
() =>
|
||||
({ commands }) => {
|
||||
return commands.unsetMark(this.name)
|
||||
},
|
||||
}
|
||||
},
|
||||
})
|
||||
225
vendor/filament/forms/resources/js/components/rich-editor/extensions.js
vendored
Normal file
225
vendor/filament/forms/resources/js/components/rich-editor/extensions.js
vendored
Normal file
|
|
@ -0,0 +1,225 @@
|
|||
import { Dropcursor, Gapcursor, UndoRedo } from '@tiptap/extensions'
|
||||
import Blockquote from '@tiptap/extension-blockquote'
|
||||
import Bold from '@tiptap/extension-bold'
|
||||
import Code from '@tiptap/extension-code'
|
||||
import CodeBlock from '@tiptap/extension-code-block'
|
||||
import CustomBlock from './extension-custom-block.js'
|
||||
import {
|
||||
Details,
|
||||
DetailsSummary,
|
||||
DetailsContent,
|
||||
} from '@tiptap/extension-details'
|
||||
import Document from '@tiptap/extension-document'
|
||||
import Grid from './extension-grid.js'
|
||||
import GridColumn from './extension-grid-column.js'
|
||||
import HardBreak from '@tiptap/extension-hard-break'
|
||||
import Heading from '@tiptap/extension-heading'
|
||||
import Highlight from '@tiptap/extension-highlight'
|
||||
import HorizontalRule from '@tiptap/extension-horizontal-rule'
|
||||
import Italic from '@tiptap/extension-italic'
|
||||
import Image from './extension-image.js'
|
||||
import Lead from './extension-lead.js'
|
||||
import Link from '@tiptap/extension-link'
|
||||
import { BulletList, ListItem, OrderedList } from '@tiptap/extension-list'
|
||||
import LocalFiles from './extension-local-files.js'
|
||||
import MergeTag from './extension-merge-tag.js'
|
||||
import Mention from './extension-mention.js'
|
||||
import Paragraph from '@tiptap/extension-paragraph'
|
||||
import Placeholder from '@tiptap/extension-placeholder'
|
||||
import Small from './extension-small.js'
|
||||
import TextColor from './extension-text-color.js'
|
||||
import Strike from '@tiptap/extension-strike'
|
||||
import Subscript from '@tiptap/extension-subscript'
|
||||
import Superscript from '@tiptap/extension-superscript'
|
||||
import { TableKit } from '@tiptap/extension-table'
|
||||
import Text from '@tiptap/extension-text'
|
||||
import TextAlign from '@tiptap/extension-text-align'
|
||||
import Underline from '@tiptap/extension-underline'
|
||||
|
||||
import getMergeTagSuggestion from './merge-tag-suggestion.js'
|
||||
|
||||
export default async ({
|
||||
$wire,
|
||||
acceptedFileTypes,
|
||||
acceptedFileTypesValidationMessage,
|
||||
canAttachFiles,
|
||||
customExtensionUrls,
|
||||
deleteCustomBlockButtonIconHtml,
|
||||
editCustomBlockButtonIconHtml,
|
||||
editCustomBlockUsing,
|
||||
getMentionLabelsUsing,
|
||||
getMentionSearchResultsUsing,
|
||||
hasResizableImages,
|
||||
insertCustomBlockUsing,
|
||||
key,
|
||||
linkProtocols,
|
||||
maxFileSize,
|
||||
maxFileSizeValidationMessage,
|
||||
mentions,
|
||||
mergeTags,
|
||||
noMergeTagSearchResultsMessage,
|
||||
placeholder,
|
||||
statePath,
|
||||
textColors,
|
||||
uploadingFileMessage,
|
||||
}) => {
|
||||
const extensions = [
|
||||
Blockquote,
|
||||
Bold,
|
||||
BulletList,
|
||||
Code,
|
||||
CodeBlock,
|
||||
CustomBlock.configure({
|
||||
deleteCustomBlockButtonIconHtml,
|
||||
editCustomBlockButtonIconHtml,
|
||||
editCustomBlockUsing,
|
||||
insertCustomBlockUsing,
|
||||
}),
|
||||
Details,
|
||||
DetailsSummary,
|
||||
DetailsContent,
|
||||
Document,
|
||||
Dropcursor.configure({
|
||||
class: 'fi-not-prose',
|
||||
}),
|
||||
Gapcursor,
|
||||
Grid,
|
||||
GridColumn,
|
||||
HardBreak,
|
||||
Heading,
|
||||
Highlight,
|
||||
HorizontalRule,
|
||||
Italic,
|
||||
Image.configure({
|
||||
inline: true,
|
||||
resize: {
|
||||
enabled: hasResizableImages,
|
||||
alwaysPreserveAspectRatio: true,
|
||||
allowBase64: true,
|
||||
},
|
||||
}),
|
||||
Lead,
|
||||
Link.configure({
|
||||
autolink: true,
|
||||
HTMLAttributes: {
|
||||
target: null,
|
||||
rel: null,
|
||||
},
|
||||
openOnClick: false,
|
||||
protocols: linkProtocols,
|
||||
}),
|
||||
ListItem,
|
||||
...(canAttachFiles
|
||||
? [
|
||||
LocalFiles.configure({
|
||||
acceptedTypes: acceptedFileTypes,
|
||||
acceptedTypesValidationMessage:
|
||||
acceptedFileTypesValidationMessage,
|
||||
get$WireUsing: () => $wire,
|
||||
key,
|
||||
maxSize: maxFileSize,
|
||||
maxSizeValidationMessage: maxFileSizeValidationMessage,
|
||||
statePath,
|
||||
uploadingMessage: uploadingFileMessage,
|
||||
}),
|
||||
]
|
||||
: []),
|
||||
...(Object.keys(mergeTags).length
|
||||
? [
|
||||
MergeTag.configure({
|
||||
deleteTriggerWithBackspace: true,
|
||||
suggestion: getMergeTagSuggestion({
|
||||
mergeTags,
|
||||
noMergeTagSearchResultsMessage,
|
||||
}),
|
||||
mergeTags,
|
||||
}),
|
||||
]
|
||||
: []),
|
||||
...(mentions.length
|
||||
? [
|
||||
Mention.configure({
|
||||
HTMLAttributes: { class: 'fi-fo-rich-editor-mention' },
|
||||
suggestions: mentions,
|
||||
getMentionSearchResultsUsing,
|
||||
getMentionLabelsUsing,
|
||||
}),
|
||||
]
|
||||
: []),
|
||||
OrderedList,
|
||||
Paragraph,
|
||||
Placeholder.configure({
|
||||
placeholder,
|
||||
}),
|
||||
TextColor.configure({
|
||||
textColors,
|
||||
}),
|
||||
Small,
|
||||
Strike,
|
||||
Subscript,
|
||||
Superscript,
|
||||
TableKit.configure({
|
||||
table: {
|
||||
resizable: true,
|
||||
},
|
||||
}),
|
||||
Text,
|
||||
TextAlign.configure({
|
||||
types: ['heading', 'paragraph'],
|
||||
alignments: ['start', 'center', 'end', 'justify'],
|
||||
defaultAlignment: 'start',
|
||||
}),
|
||||
Underline,
|
||||
UndoRedo,
|
||||
]
|
||||
|
||||
const loadedCustomExtensions = await Promise.all(
|
||||
customExtensionUrls.map(async (url) => {
|
||||
const absoluteUrlRegExp = new RegExp('^(?:[a-z+]+:)?//', 'i')
|
||||
|
||||
if (!absoluteUrlRegExp.test(url)) {
|
||||
url = new URL(url, document.baseURI).href
|
||||
}
|
||||
|
||||
try {
|
||||
const factoryOrInstance = (await import(url)).default
|
||||
|
||||
return typeof factoryOrInstance === 'function'
|
||||
? factoryOrInstance()
|
||||
: factoryOrInstance
|
||||
} catch (error) {
|
||||
console.error(
|
||||
`Failed to load rich editor custom extension from [${url}]:`,
|
||||
error,
|
||||
)
|
||||
|
||||
return null
|
||||
}
|
||||
}),
|
||||
)
|
||||
|
||||
for (let customExtension of loadedCustomExtensions) {
|
||||
if (!customExtension || !customExtension.name) {
|
||||
continue
|
||||
}
|
||||
|
||||
const existingIndex = extensions.findIndex(
|
||||
(extension) => extension.name === customExtension.name,
|
||||
)
|
||||
|
||||
if (
|
||||
customExtension.name === 'placeholder' &&
|
||||
customExtension.parent === null
|
||||
) {
|
||||
customExtension = Placeholder.configure(customExtension.options)
|
||||
}
|
||||
|
||||
if (existingIndex !== -1) {
|
||||
extensions[existingIndex] = customExtension
|
||||
} else {
|
||||
extensions.push(customExtension)
|
||||
}
|
||||
}
|
||||
|
||||
return extensions
|
||||
}
|
||||
320
vendor/filament/forms/resources/js/components/rich-editor/mention-suggestion.js
vendored
Normal file
320
vendor/filament/forms/resources/js/components/rich-editor/mention-suggestion.js
vendored
Normal file
|
|
@ -0,0 +1,320 @@
|
|||
import { computePosition, flip, shift } from '@floating-ui/dom'
|
||||
|
||||
const updatePosition = (editor, element) => {
|
||||
const referenceElement = {
|
||||
getBoundingClientRect: () => {
|
||||
const { from, to } = editor.state.selection
|
||||
const start = editor.view.coordsAtPos(from)
|
||||
const end = editor.view.coordsAtPos(to)
|
||||
|
||||
return {
|
||||
top: Math.min(start.top, end.top),
|
||||
bottom: Math.max(start.bottom, end.bottom),
|
||||
left: Math.min(start.left, end.left),
|
||||
right: Math.max(start.right, end.right),
|
||||
width: Math.abs(end.right - start.left),
|
||||
height: Math.abs(end.bottom - start.top),
|
||||
x: Math.min(start.left, end.left),
|
||||
y: Math.min(start.top, end.top),
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
computePosition(referenceElement, element, {
|
||||
placement: 'bottom-start',
|
||||
strategy: 'absolute',
|
||||
middleware: [shift(), flip()],
|
||||
}).then(({ x, y, strategy }) => {
|
||||
element.style.width = 'max-content'
|
||||
element.style.position = strategy
|
||||
element.style.left = `${x}px`
|
||||
element.style.top = `${y}px`
|
||||
})
|
||||
}
|
||||
|
||||
export default ({
|
||||
items = [],
|
||||
noOptionsMessage = null,
|
||||
noSearchResultsMessage = null,
|
||||
searchPrompt = null,
|
||||
searchingMessage = null,
|
||||
isSearchable = false,
|
||||
}) => {
|
||||
let renderContext = null
|
||||
|
||||
return {
|
||||
items: async ({ query }) => {
|
||||
if (typeof items === 'function') {
|
||||
if (renderContext && isSearchable) {
|
||||
renderContext.setLoading(true)
|
||||
}
|
||||
|
||||
try {
|
||||
const result = items({ query })
|
||||
const resolved = Array.isArray(result)
|
||||
? result
|
||||
: await result
|
||||
|
||||
if (renderContext) {
|
||||
renderContext.setLoading(false)
|
||||
}
|
||||
|
||||
return resolved
|
||||
} catch {
|
||||
if (renderContext) {
|
||||
renderContext.setLoading(false)
|
||||
}
|
||||
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
if (!query) return items
|
||||
|
||||
const searchQuery = String(query).toLowerCase()
|
||||
return items.filter((item) => {
|
||||
const label =
|
||||
typeof item === 'string'
|
||||
? item
|
||||
: (item?.label ?? item?.name ?? '')
|
||||
return String(label).toLowerCase().includes(searchQuery)
|
||||
})
|
||||
},
|
||||
|
||||
render: () => {
|
||||
let element
|
||||
let selectedIndex = 0
|
||||
let currentProps = null
|
||||
let isLoading = false
|
||||
|
||||
renderContext = {
|
||||
setLoading: (loading) => {
|
||||
isLoading = loading
|
||||
renderItems()
|
||||
},
|
||||
}
|
||||
|
||||
const createDropdown = () => {
|
||||
const dropdown = document.createElement('div')
|
||||
dropdown.className =
|
||||
'fi-dropdown-panel fi-dropdown-list fi-scrollable'
|
||||
dropdown.style.maxHeight = '15rem'
|
||||
dropdown.style.minWidth = '12rem'
|
||||
|
||||
return dropdown
|
||||
}
|
||||
|
||||
const renderItems = () => {
|
||||
if (!element || !currentProps) return
|
||||
|
||||
const items = Array.isArray(currentProps.items)
|
||||
? currentProps.items
|
||||
: []
|
||||
const query = currentProps.query ?? ''
|
||||
|
||||
element.innerHTML = ''
|
||||
|
||||
if (isLoading) {
|
||||
const message = searchingMessage ?? 'Searching...'
|
||||
const messageElement = document.createElement('div')
|
||||
messageElement.className = 'fi-dropdown-header'
|
||||
|
||||
const messageSpan = document.createElement('span')
|
||||
messageSpan.style.whiteSpace = 'normal'
|
||||
messageSpan.textContent = message
|
||||
messageElement.appendChild(messageSpan)
|
||||
|
||||
element.appendChild(messageElement)
|
||||
return
|
||||
}
|
||||
|
||||
if (items.length) {
|
||||
items.forEach((raw, index) => {
|
||||
const label =
|
||||
typeof raw === 'string'
|
||||
? raw
|
||||
: (raw?.label ??
|
||||
raw?.name ??
|
||||
String(raw?.id ?? ''))
|
||||
const id =
|
||||
typeof raw === 'object' ? (raw?.id ?? label) : label
|
||||
|
||||
const button = document.createElement('button')
|
||||
button.className = `fi-dropdown-list-item ${index === selectedIndex ? 'fi-selected' : ''}`
|
||||
button.type = 'button'
|
||||
button.addEventListener('click', () =>
|
||||
selectItem(id, label),
|
||||
)
|
||||
|
||||
const labelSpan = document.createElement('span')
|
||||
labelSpan.className = 'fi-dropdown-list-item-label'
|
||||
labelSpan.textContent = label
|
||||
button.appendChild(labelSpan)
|
||||
|
||||
element.appendChild(button)
|
||||
})
|
||||
} else {
|
||||
const message = getEmptyMessage(query)
|
||||
|
||||
if (message) {
|
||||
const messageElement = document.createElement('div')
|
||||
messageElement.className = 'fi-dropdown-header'
|
||||
|
||||
const messageSpan = document.createElement('span')
|
||||
messageSpan.style.whiteSpace = 'normal'
|
||||
messageSpan.textContent = message
|
||||
messageElement.appendChild(messageSpan)
|
||||
|
||||
element.appendChild(messageElement)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const getEmptyMessage = (query) => {
|
||||
if (query) {
|
||||
return noSearchResultsMessage
|
||||
}
|
||||
|
||||
if (isSearchable) {
|
||||
return searchPrompt
|
||||
}
|
||||
|
||||
return noOptionsMessage
|
||||
}
|
||||
|
||||
const selectItem = (id, label) => {
|
||||
if (!currentProps) return
|
||||
|
||||
currentProps.command({ id, label })
|
||||
}
|
||||
|
||||
const scrollToSelected = () => {
|
||||
if (!element || !currentProps) return
|
||||
|
||||
const items = currentProps.items || []
|
||||
if (items.length === 0) return
|
||||
|
||||
const selectedButton = element.children[selectedIndex]
|
||||
|
||||
if (selectedButton) {
|
||||
const rect = selectedButton.getBoundingClientRect()
|
||||
const containerRect = element.getBoundingClientRect()
|
||||
if (
|
||||
rect.top < containerRect.top ||
|
||||
rect.bottom > containerRect.bottom
|
||||
) {
|
||||
selectedButton.scrollIntoView({ block: 'nearest' })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const upHandler = () => {
|
||||
if (!currentProps) return
|
||||
|
||||
const items = Array.isArray(currentProps.items)
|
||||
? currentProps.items
|
||||
: []
|
||||
if (items.length === 0) return
|
||||
|
||||
selectedIndex =
|
||||
(selectedIndex + items.length - 1) % items.length
|
||||
renderItems()
|
||||
scrollToSelected()
|
||||
}
|
||||
|
||||
const downHandler = () => {
|
||||
if (!currentProps) return
|
||||
|
||||
const items = currentProps.items || []
|
||||
if (items.length === 0) return
|
||||
|
||||
selectedIndex = (selectedIndex + 1) % items.length
|
||||
renderItems()
|
||||
scrollToSelected()
|
||||
}
|
||||
|
||||
const enterHandler = () => {
|
||||
const items = currentProps?.items || []
|
||||
if (items.length === 0) return
|
||||
|
||||
const raw = items[selectedIndex]
|
||||
const label =
|
||||
typeof raw === 'string'
|
||||
? raw
|
||||
: (raw?.label ?? raw?.name ?? String(raw?.id ?? ''))
|
||||
const id = typeof raw === 'object' ? (raw?.id ?? label) : label
|
||||
selectItem(id, label)
|
||||
}
|
||||
|
||||
return {
|
||||
onStart: (props) => {
|
||||
currentProps = props
|
||||
selectedIndex = 0
|
||||
|
||||
element = createDropdown()
|
||||
element.style.position = 'absolute'
|
||||
element.style.zIndex = '50'
|
||||
|
||||
renderItems()
|
||||
|
||||
document.body.appendChild(element)
|
||||
|
||||
if (!props.clientRect) {
|
||||
return
|
||||
}
|
||||
|
||||
updatePosition(props.editor, element)
|
||||
},
|
||||
|
||||
onUpdate: (props) => {
|
||||
currentProps = props
|
||||
selectedIndex = 0
|
||||
|
||||
renderItems()
|
||||
scrollToSelected()
|
||||
|
||||
if (!props.clientRect) {
|
||||
return
|
||||
}
|
||||
|
||||
updatePosition(props.editor, element)
|
||||
},
|
||||
|
||||
onKeyDown: (props) => {
|
||||
if (props.event.key === 'Escape') {
|
||||
if (element && element.parentNode) {
|
||||
element.parentNode.removeChild(element)
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
if (props.event.key === 'ArrowUp') {
|
||||
upHandler()
|
||||
return true
|
||||
}
|
||||
|
||||
if (props.event.key === 'ArrowDown') {
|
||||
downHandler()
|
||||
return true
|
||||
}
|
||||
|
||||
if (props.event.key === 'Enter') {
|
||||
enterHandler()
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
},
|
||||
|
||||
onExit: () => {
|
||||
if (element && element.parentNode) {
|
||||
element.parentNode.removeChild(element)
|
||||
}
|
||||
|
||||
renderContext = null
|
||||
},
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
217
vendor/filament/forms/resources/js/components/rich-editor/merge-tag-suggestion.js
vendored
Normal file
217
vendor/filament/forms/resources/js/components/rich-editor/merge-tag-suggestion.js
vendored
Normal file
|
|
@ -0,0 +1,217 @@
|
|||
import { computePosition, flip, shift } from '@floating-ui/dom'
|
||||
|
||||
const updatePosition = (editor, element) => {
|
||||
const referenceElement = {
|
||||
getBoundingClientRect: () => {
|
||||
const { from, to } = editor.state.selection
|
||||
const start = editor.view.coordsAtPos(from)
|
||||
const end = editor.view.coordsAtPos(to)
|
||||
|
||||
return {
|
||||
top: Math.min(start.top, end.top),
|
||||
bottom: Math.max(start.bottom, end.bottom),
|
||||
left: Math.min(start.left, end.left),
|
||||
right: Math.max(start.right, end.right),
|
||||
width: Math.abs(end.right - start.left),
|
||||
height: Math.abs(end.bottom - start.top),
|
||||
x: Math.min(start.left, end.left),
|
||||
y: Math.min(start.top, end.top),
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
computePosition(referenceElement, element, {
|
||||
placement: 'bottom-start',
|
||||
strategy: 'absolute',
|
||||
middleware: [shift(), flip()],
|
||||
}).then(({ x, y, strategy }) => {
|
||||
element.style.width = 'max-content'
|
||||
element.style.position = strategy
|
||||
element.style.left = `${x}px`
|
||||
element.style.top = `${y}px`
|
||||
})
|
||||
}
|
||||
|
||||
export default ({ mergeTags, noMergeTagSearchResultsMessage }) => ({
|
||||
items: ({ query }) => {
|
||||
return Object.entries(mergeTags)
|
||||
.filter(
|
||||
([id, label]) =>
|
||||
id
|
||||
.toLowerCase()
|
||||
.replace(/\s/g, '')
|
||||
.includes(query.toLowerCase()) ||
|
||||
label
|
||||
.toLowerCase()
|
||||
.replace(/\s/g, '')
|
||||
.includes(query.toLowerCase()),
|
||||
)
|
||||
.map(([id, label]) => ({ id, label }))
|
||||
},
|
||||
|
||||
render: () => {
|
||||
let element
|
||||
let selectedIndex = 0
|
||||
let currentProps = null
|
||||
|
||||
const createDropdown = () => {
|
||||
const dropdown = document.createElement('div')
|
||||
dropdown.className = 'fi-dropdown-panel fi-dropdown-list'
|
||||
dropdown.style.minWidth = '12rem'
|
||||
|
||||
return dropdown
|
||||
}
|
||||
|
||||
const renderItems = () => {
|
||||
if (!element || !currentProps) return
|
||||
|
||||
const items = currentProps.items || []
|
||||
|
||||
element.innerHTML = ''
|
||||
|
||||
if (items.length) {
|
||||
items.forEach((item, index) => {
|
||||
const button = document.createElement('button')
|
||||
button.className = `fi-dropdown-list-item fi-dropdown-list-item-label ${index === selectedIndex ? 'fi-selected' : ''}`
|
||||
button.textContent = item.label
|
||||
button.type = 'button'
|
||||
button.addEventListener('click', () => selectItem(index))
|
||||
element.appendChild(button)
|
||||
})
|
||||
} else {
|
||||
const messageElement = document.createElement('div')
|
||||
messageElement.className = 'fi-dropdown-header'
|
||||
|
||||
const messageSpan = document.createElement('span')
|
||||
messageSpan.style.whiteSpace = 'normal'
|
||||
messageSpan.textContent = noMergeTagSearchResultsMessage
|
||||
messageElement.appendChild(messageSpan)
|
||||
|
||||
element.appendChild(messageElement)
|
||||
}
|
||||
}
|
||||
|
||||
const selectItem = (index) => {
|
||||
if (!currentProps) return
|
||||
|
||||
const items = currentProps.items || []
|
||||
const item = items[index]
|
||||
|
||||
if (item) {
|
||||
currentProps.command({ id: item.id })
|
||||
}
|
||||
}
|
||||
|
||||
const scrollToSelected = () => {
|
||||
if (!element || !currentProps || currentProps.items.length === 0)
|
||||
return
|
||||
|
||||
const selectedButton = element.children[selectedIndex]
|
||||
|
||||
if (selectedButton) {
|
||||
const rect = selectedButton.getBoundingClientRect()
|
||||
const containerRect = element.getBoundingClientRect()
|
||||
if (
|
||||
rect.top < containerRect.top ||
|
||||
rect.bottom > containerRect.bottom
|
||||
) {
|
||||
selectedButton.scrollIntoView({ block: 'nearest' })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const upHandler = () => {
|
||||
if (!currentProps) return
|
||||
|
||||
const items = currentProps.items || []
|
||||
if (items.length === 0) return
|
||||
|
||||
selectedIndex = (selectedIndex + items.length - 1) % items.length
|
||||
renderItems()
|
||||
scrollToSelected()
|
||||
}
|
||||
|
||||
const downHandler = () => {
|
||||
if (!currentProps) return
|
||||
|
||||
const items = currentProps.items || []
|
||||
if (items.length === 0) return
|
||||
|
||||
selectedIndex = (selectedIndex + 1) % items.length
|
||||
renderItems()
|
||||
scrollToSelected()
|
||||
}
|
||||
|
||||
const enterHandler = () => {
|
||||
selectItem(selectedIndex)
|
||||
}
|
||||
|
||||
return {
|
||||
onStart: (props) => {
|
||||
currentProps = props
|
||||
selectedIndex = 0
|
||||
|
||||
element = createDropdown()
|
||||
element.style.position = 'absolute'
|
||||
element.style.zIndex = '50'
|
||||
|
||||
renderItems()
|
||||
|
||||
document.body.appendChild(element)
|
||||
|
||||
if (!props.clientRect) {
|
||||
return
|
||||
}
|
||||
|
||||
updatePosition(props.editor, element)
|
||||
},
|
||||
|
||||
onUpdate: (props) => {
|
||||
currentProps = props
|
||||
selectedIndex = 0
|
||||
|
||||
renderItems()
|
||||
scrollToSelected()
|
||||
|
||||
if (!props.clientRect) {
|
||||
return
|
||||
}
|
||||
|
||||
updatePosition(props.editor, element)
|
||||
},
|
||||
|
||||
onKeyDown: (props) => {
|
||||
if (props.event.key === 'Escape') {
|
||||
if (element && element.parentNode) {
|
||||
element.parentNode.removeChild(element)
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
if (props.event.key === 'ArrowUp') {
|
||||
upHandler()
|
||||
return true
|
||||
}
|
||||
|
||||
if (props.event.key === 'ArrowDown') {
|
||||
downHandler()
|
||||
return true
|
||||
}
|
||||
|
||||
if (props.event.key === 'Enter') {
|
||||
enterHandler()
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
},
|
||||
|
||||
onExit: () => {
|
||||
if (element && element.parentNode) {
|
||||
element.parentNode.removeChild(element)
|
||||
}
|
||||
},
|
||||
}
|
||||
},
|
||||
})
|
||||
112
vendor/filament/forms/resources/js/components/select.js
vendored
Normal file
112
vendor/filament/forms/resources/js/components/select.js
vendored
Normal file
|
|
@ -0,0 +1,112 @@
|
|||
import { Select } from '../../../../support/resources/js/utilities/select.js'
|
||||
|
||||
export default function selectFormComponent({
|
||||
canOptionLabelsWrap,
|
||||
canSelectPlaceholder,
|
||||
clearButtonLabel,
|
||||
getOptionLabelUsing,
|
||||
getOptionLabelsUsing,
|
||||
getOptionsUsing,
|
||||
getSearchResultsUsing,
|
||||
hasDynamicOptions,
|
||||
hasDynamicSearchResults,
|
||||
hasInitialNoOptionsMessage,
|
||||
id,
|
||||
initialOptionLabel,
|
||||
initialOptionLabels,
|
||||
initialState,
|
||||
isAutofocused,
|
||||
isDisabled,
|
||||
isHtmlAllowed,
|
||||
isMultiple,
|
||||
isReorderable,
|
||||
isSearchable,
|
||||
livewireId,
|
||||
loadingMessage,
|
||||
maxItems,
|
||||
maxItemsMessage,
|
||||
noOptionsMessage,
|
||||
noSearchResultsMessage,
|
||||
options,
|
||||
optionsLimit,
|
||||
placeholder,
|
||||
position,
|
||||
removeButtonLabel,
|
||||
searchDebounce,
|
||||
searchingMessage,
|
||||
searchLabel,
|
||||
searchPrompt,
|
||||
searchableOptionFields,
|
||||
state,
|
||||
statePath,
|
||||
}) {
|
||||
return {
|
||||
select: null,
|
||||
|
||||
state,
|
||||
|
||||
init() {
|
||||
this.select = new Select({
|
||||
canOptionLabelsWrap,
|
||||
canSelectPlaceholder,
|
||||
clearButtonLabel,
|
||||
element: this.$refs.select,
|
||||
getOptionLabelUsing,
|
||||
getOptionLabelsUsing,
|
||||
getOptionsUsing,
|
||||
getSearchResultsUsing,
|
||||
hasDynamicOptions,
|
||||
hasDynamicSearchResults,
|
||||
hasInitialNoOptionsMessage,
|
||||
id,
|
||||
initialOptionLabel,
|
||||
initialOptionLabels,
|
||||
initialState,
|
||||
isAutofocused,
|
||||
isDisabled,
|
||||
isHtmlAllowed,
|
||||
isMultiple,
|
||||
isReorderable,
|
||||
isSearchable,
|
||||
livewireId,
|
||||
loadingMessage,
|
||||
maxItems,
|
||||
maxItemsMessage,
|
||||
noOptionsMessage,
|
||||
noSearchResultsMessage,
|
||||
onStateChange: (newState) => {
|
||||
this.state = newState
|
||||
},
|
||||
options,
|
||||
optionsLimit,
|
||||
placeholder,
|
||||
position,
|
||||
removeButtonLabel,
|
||||
searchableOptionFields,
|
||||
searchDebounce,
|
||||
searchingMessage,
|
||||
searchLabel,
|
||||
searchPrompt,
|
||||
state: this.state,
|
||||
statePath,
|
||||
})
|
||||
|
||||
this.$watch('state', (newState) => {
|
||||
this.$nextTick(() => {
|
||||
if (this.select && this.select.state !== newState) {
|
||||
this.select.state = newState
|
||||
this.select.updateSelectedDisplay()
|
||||
this.select.renderOptions()
|
||||
}
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
destroy() {
|
||||
if (this.select) {
|
||||
this.select.destroy()
|
||||
this.select = null
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
98
vendor/filament/forms/resources/js/components/slider.js
vendored
Normal file
98
vendor/filament/forms/resources/js/components/slider.js
vendored
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
import noUiSlider from 'nouislider'
|
||||
|
||||
export default function sliderFormComponent({
|
||||
arePipsStepped,
|
||||
behavior,
|
||||
decimalPlaces,
|
||||
fillTrack,
|
||||
isDisabled,
|
||||
isRtl,
|
||||
isVertical,
|
||||
maxDifference,
|
||||
minDifference,
|
||||
maxValue,
|
||||
minValue,
|
||||
nonLinearPoints,
|
||||
pipsDensity,
|
||||
pipsFilter,
|
||||
pipsFormatter,
|
||||
pipsMode,
|
||||
pipsValues,
|
||||
rangePadding,
|
||||
state,
|
||||
step,
|
||||
tooltips,
|
||||
}) {
|
||||
return {
|
||||
state,
|
||||
|
||||
slider: null,
|
||||
|
||||
init() {
|
||||
this.slider = noUiSlider.create(this.$el, {
|
||||
behaviour: behavior,
|
||||
direction: isRtl ? 'rtl' : 'ltr',
|
||||
connect: fillTrack,
|
||||
format: {
|
||||
from: (value) => +value,
|
||||
to: (value) =>
|
||||
decimalPlaces !== null
|
||||
? +value.toFixed(decimalPlaces)
|
||||
: value,
|
||||
},
|
||||
limit: maxDifference,
|
||||
margin: minDifference,
|
||||
orientation: isVertical ? 'vertical' : 'horizontal',
|
||||
padding: rangePadding,
|
||||
pips: pipsMode
|
||||
? {
|
||||
density: pipsDensity ?? 10,
|
||||
filter: pipsFilter,
|
||||
format: pipsFormatter,
|
||||
mode: pipsMode,
|
||||
stepped: arePipsStepped,
|
||||
values: pipsValues,
|
||||
}
|
||||
: null,
|
||||
range: {
|
||||
min: minValue,
|
||||
...(nonLinearPoints ?? {}),
|
||||
max: maxValue,
|
||||
},
|
||||
start: Alpine.raw(this.state),
|
||||
step,
|
||||
tooltips,
|
||||
})
|
||||
|
||||
if (this.$el.id) {
|
||||
// `noUiSlider` handles are focusable `role="slider"` elements, but it does not
|
||||
// give them an accessible name, so they inherit the field's label element.
|
||||
this.$el
|
||||
.querySelectorAll('.noUi-handle')
|
||||
.forEach((handle) =>
|
||||
handle.setAttribute(
|
||||
'aria-labelledby',
|
||||
`${this.$el.id}-label`,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
if (isDisabled) {
|
||||
this.slider.disable()
|
||||
}
|
||||
|
||||
this.slider.on('change', (values) => {
|
||||
this.state = values.length > 1 ? values : values[0]
|
||||
})
|
||||
|
||||
this.$watch('state', () => {
|
||||
this.slider.set(Alpine.raw(this.state))
|
||||
})
|
||||
},
|
||||
|
||||
destroy() {
|
||||
this.slider.destroy()
|
||||
this.slider = null
|
||||
},
|
||||
}
|
||||
}
|
||||
108
vendor/filament/forms/resources/js/components/tags-input.js
vendored
Normal file
108
vendor/filament/forms/resources/js/components/tags-input.js
vendored
Normal file
|
|
@ -0,0 +1,108 @@
|
|||
export default function tagsInputFormComponent({
|
||||
state,
|
||||
splitKeys,
|
||||
tagAddedMessage,
|
||||
tagRemovedMessage,
|
||||
}) {
|
||||
return {
|
||||
newTag: '',
|
||||
|
||||
state,
|
||||
|
||||
liveRegionClearTimeout: null,
|
||||
|
||||
announce(message) {
|
||||
// A published pre-change view override has no `liveRegion` ref, so bail out
|
||||
// instead of throwing and breaking tag entry for those users.
|
||||
const liveRegion = this.$refs.liveRegion
|
||||
|
||||
if (!liveRegion) {
|
||||
return
|
||||
}
|
||||
|
||||
if (this.liveRegionClearTimeout !== null) {
|
||||
clearTimeout(this.liveRegionClearTimeout)
|
||||
}
|
||||
|
||||
liveRegion.textContent = message
|
||||
|
||||
// Clear the announcement once it has been read, so stale messages do not
|
||||
// remain reachable by the screen reader virtual cursor.
|
||||
this.liveRegionClearTimeout = setTimeout(() => {
|
||||
liveRegion.textContent = ''
|
||||
|
||||
this.liveRegionClearTimeout = null
|
||||
}, 3000)
|
||||
},
|
||||
|
||||
createTag() {
|
||||
this.newTag = this.newTag.trim()
|
||||
|
||||
if (this.newTag === '') {
|
||||
return
|
||||
}
|
||||
|
||||
if (this.state.includes(this.newTag)) {
|
||||
this.newTag = ''
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
this.state.push(this.newTag)
|
||||
|
||||
// A function replacement inserts the tag literally, so `$` sequences in it are not treated as substitution patterns by `String.replace()`. The message is optional so a published pre-change view override does not throw.
|
||||
this.announce(tagAddedMessage?.replace(':tag', () => this.newTag))
|
||||
|
||||
this.newTag = ''
|
||||
},
|
||||
|
||||
deleteTag(tagToDelete) {
|
||||
this.state = this.state.filter((tag) => tag !== tagToDelete)
|
||||
|
||||
this.announce(tagRemovedMessage?.replace(':tag', () => tagToDelete))
|
||||
},
|
||||
|
||||
reorderTags(event) {
|
||||
const reordered = this.state.splice(event.oldIndex, 1)[0]
|
||||
this.state.splice(event.newIndex, 0, reordered)
|
||||
|
||||
this.state = [...this.state]
|
||||
},
|
||||
|
||||
input: {
|
||||
['x-on:blur']: 'createTag()',
|
||||
['x-model']: 'newTag',
|
||||
['x-on:keydown'](event) {
|
||||
if (['Enter', ...splitKeys].includes(event.key)) {
|
||||
event.preventDefault()
|
||||
event.stopPropagation()
|
||||
|
||||
this.createTag()
|
||||
}
|
||||
},
|
||||
['x-on:paste']() {
|
||||
this.$nextTick(() => {
|
||||
if (splitKeys.length === 0) {
|
||||
this.createTag()
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
const pattern = splitKeys
|
||||
.map((key) =>
|
||||
key.replace(/[/\-\\^$*+?.()|[\]{}]/g, '\\$&'),
|
||||
)
|
||||
.join('|')
|
||||
|
||||
this.newTag
|
||||
.split(new RegExp(pattern, 'g'))
|
||||
.forEach((tag) => {
|
||||
this.newTag = tag
|
||||
|
||||
this.createTag()
|
||||
})
|
||||
})
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
70
vendor/filament/forms/resources/js/components/textarea.js
vendored
Normal file
70
vendor/filament/forms/resources/js/components/textarea.js
vendored
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
export default function textareaFormComponent({
|
||||
initialHeight,
|
||||
shouldAutosize,
|
||||
state,
|
||||
}) {
|
||||
return {
|
||||
state,
|
||||
|
||||
resizeObserver: null,
|
||||
|
||||
wrapperEl: null,
|
||||
|
||||
init() {
|
||||
this.wrapperEl = this.$el.parentNode
|
||||
|
||||
this.setInitialHeight()
|
||||
|
||||
if (shouldAutosize) {
|
||||
this.$watch('state', () => {
|
||||
this.resize()
|
||||
})
|
||||
} else {
|
||||
this.setUpResizeObserver()
|
||||
}
|
||||
},
|
||||
|
||||
setInitialHeight() {
|
||||
if (this.$el.scrollHeight <= 0) {
|
||||
return
|
||||
}
|
||||
|
||||
this.wrapperEl.style.height = initialHeight + 'rem'
|
||||
},
|
||||
|
||||
resize() {
|
||||
if (this.$el.scrollHeight <= 0) {
|
||||
return
|
||||
}
|
||||
|
||||
const previousHeight = this.$el.style.height
|
||||
this.$el.style.height = '0px'
|
||||
|
||||
const contentHeight = this.$el.scrollHeight
|
||||
this.$el.style.height = previousHeight
|
||||
|
||||
const minHeightPx =
|
||||
parseFloat(initialHeight) *
|
||||
parseFloat(getComputedStyle(document.documentElement).fontSize)
|
||||
const newHeight = Math.max(contentHeight, minHeightPx) + 'px'
|
||||
|
||||
if (this.wrapperEl.style.height === newHeight) {
|
||||
return
|
||||
}
|
||||
|
||||
this.wrapperEl.style.height = newHeight
|
||||
},
|
||||
|
||||
setUpResizeObserver() {
|
||||
this.resizeObserver = new ResizeObserver(() => {
|
||||
this.wrapperEl.style.height = this.$el.style.height
|
||||
})
|
||||
|
||||
this.resizeObserver.observe(this.$el)
|
||||
},
|
||||
|
||||
destroy() {
|
||||
this.resizeObserver?.disconnect()
|
||||
},
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue