[增添]添加了datasource的setting数据库以及默认值
This commit is contained in:
116
vendor/filament/support/resources/js/index.js
vendored
Normal file
116
vendor/filament/support/resources/js/index.js
vendored
Normal file
@@ -0,0 +1,116 @@
|
||||
import AlpineFloatingUI from '@awcodes/alpine-floating-ui'
|
||||
import AlpineLazyLoadAssets from 'alpine-lazy-load-assets'
|
||||
// import { clearAllBodyScrollLocks, disableBodyScroll } from 'body-scroll-lock'
|
||||
import { md5 } from 'js-md5'
|
||||
import Sortable from './sortable'
|
||||
import Tooltip from '@ryangjchandler/alpine-tooltip'
|
||||
|
||||
import '../css/components/pagination.css'
|
||||
import 'tippy.js/dist/tippy.css'
|
||||
import 'tippy.js/themes/light.css'
|
||||
import '../css/sortable.css'
|
||||
|
||||
document.addEventListener('alpine:init', () => {
|
||||
window.Alpine.plugin(AlpineFloatingUI)
|
||||
window.Alpine.plugin(AlpineLazyLoadAssets)
|
||||
window.Alpine.plugin(Sortable)
|
||||
window.Alpine.plugin(Tooltip)
|
||||
})
|
||||
|
||||
// document.addEventListener('livewire:navigating', () => {
|
||||
// clearAllBodyScrollLocks()
|
||||
// })
|
||||
|
||||
// https://github.com/laravel/framework/blob/5299c22321c0f1ea8ff770b84a6c6469c4d6edec/src/Illuminate/Translation/MessageSelector.php#L15
|
||||
const pluralize = function (text, number, variables) {
|
||||
function extract(segments, number) {
|
||||
for (const part of segments) {
|
||||
const line = extractFromString(part, number)
|
||||
|
||||
if (line !== null) {
|
||||
return line
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function extractFromString(part, number) {
|
||||
const matches = part.match(/^[\{\[]([^\[\]\{\}]*)[\}\]](.*)/s)
|
||||
|
||||
if (matches === null || matches.length !== 3) {
|
||||
return null
|
||||
}
|
||||
|
||||
const condition = matches[1]
|
||||
|
||||
const value = matches[2]
|
||||
|
||||
if (condition.includes(',')) {
|
||||
const [from, to] = condition.split(',', 2)
|
||||
|
||||
if (to === '*' && number >= from) {
|
||||
return value
|
||||
} else if (from === '*' && number <= to) {
|
||||
return value
|
||||
} else if (number >= from && number <= to) {
|
||||
return value
|
||||
}
|
||||
}
|
||||
|
||||
return condition == number ? value : null
|
||||
}
|
||||
|
||||
function ucfirst(string) {
|
||||
return (
|
||||
string.toString().charAt(0).toUpperCase() +
|
||||
string.toString().slice(1)
|
||||
)
|
||||
}
|
||||
|
||||
function replace(line, replace) {
|
||||
if (replace.length === 0) {
|
||||
return line
|
||||
}
|
||||
|
||||
const shouldReplace = {}
|
||||
|
||||
for (let [key, value] of Object.entries(replace)) {
|
||||
shouldReplace[':' + ucfirst(key ?? '')] = ucfirst(value ?? '')
|
||||
shouldReplace[':' + key.toUpperCase()] = value
|
||||
.toString()
|
||||
.toUpperCase()
|
||||
shouldReplace[':' + key] = value
|
||||
}
|
||||
|
||||
Object.entries(shouldReplace).forEach(([key, value]) => {
|
||||
line = line.replaceAll(key, value)
|
||||
})
|
||||
|
||||
return line
|
||||
}
|
||||
|
||||
function stripConditions(segments) {
|
||||
return segments.map((part) =>
|
||||
part.replace(/^[\{\[]([^\[\]\{\}]*)[\}\]]/, ''),
|
||||
)
|
||||
}
|
||||
|
||||
let segments = text.split('|')
|
||||
|
||||
const value = extract(segments, number)
|
||||
|
||||
if (value !== null && value !== undefined) {
|
||||
return replace(value.trim(), variables)
|
||||
}
|
||||
|
||||
segments = stripConditions(segments)
|
||||
|
||||
return replace(
|
||||
segments.length > 1 && number > 1 ? segments[1] : segments[0],
|
||||
variables,
|
||||
)
|
||||
}
|
||||
|
||||
// window.clearAllBodyScrollLocks = clearAllBodyScrollLocks
|
||||
// window.disableBodyScroll = disableBodyScroll
|
||||
window.jsMd5 = md5
|
||||
window.pluralize = pluralize
|
||||
22
vendor/filament/support/resources/js/sortable.js
vendored
Normal file
22
vendor/filament/support/resources/js/sortable.js
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
import Sortable from 'sortablejs'
|
||||
|
||||
window.Sortable = Sortable
|
||||
|
||||
export default (Alpine) => {
|
||||
Alpine.directive('sortable', (el) => {
|
||||
let animation = parseInt(el.dataset?.sortableAnimationDuration)
|
||||
|
||||
if (animation !== 0 && !animation) {
|
||||
animation = 300
|
||||
}
|
||||
|
||||
el.sortable = Sortable.create(el, {
|
||||
group: el.getAttribute('x-sortable-group'),
|
||||
draggable: '[x-sortable-item]',
|
||||
handle: '[x-sortable-handle]',
|
||||
dataIdAttr: 'x-sortable-item',
|
||||
animation: animation,
|
||||
ghostClass: 'fi-sortable-ghost',
|
||||
})
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user