plugins: new frontend event "afterEntryName"
Massimo Melina committed
Feb 14, 2023 at 11:06 UTC
cf44758f960678d3bc759652a7387942388a7463
3 files changed
+18
-7
dev-plugins.md
+9
-3
@@ -146,11 +146,11 @@ There you'll find `HFS.onEvent` function that is the base of communication.
146
`onEvent(eventName:string, callback: (object) => any)` your callback will be called on the specified event.
147
Depending on the event you'll have an object with parameters in it, and may return some output. Refer to the specific event for further information.
148
149
-This is a list of available frontend events, with respective parameters and output.
149
+This is a list of available frontend events, with respective object parameter and output.
150
151
- `additionalEntryProps`
152
- you receive each entry of the list, and optionally produce HTML code that will be added in the `entry-props` container.
153
- - parameters `{ entry: Entry }`
153
+ - parameter `{ entry: Entry }`
154
155
The `Entry` type is an object with the following properties:
156
- `n: string` name of the entry, including relative path in some cases.
@@ -158,7 +158,11 @@ This is a list of available frontend events, with respective parameters and outp
158
- `t?: Date` generic timestamp, combination of creation-time and modified-time.
159
- `c?: Date` creation-time.
160
- `m?: Date` modified-time.
161
- - output `string | void`
161
+ - output `string | falsy`
162
+- `afterEntryName`
163
+ - you receive each entry of the list, and optionally produce HTML code that will be added after the name of the entry.
164
+ - parameter `{ entry: Entry }` (refer above for Entry object)
165
+ - output `string | falsy`
166
167
## Publish your plug-in
168
@@ -179,6 +183,8 @@ HFS will scan through them in alphabetical order searching for a compatible one.
183
184
## API version history
185
186
+- 5 (v0.33.0)
187
+ - event.afterEntryName
188
- 4.1 (v0.23.4)
189
- config.type:array added $width, $column and fixed height
190
- 4 (v0.23.0)
frontend/src/BrowseFiles.ts
+8
-3
@@ -189,6 +189,7 @@ const Entry = memo((entry: DirEntry & { midnight: Date, separator?: string }) =>
189
containerDir && h(Link, { to: base+fixUrl(containerDir), className:'container-folder' }, hIcon('file'), containerDir ),
190
h('a', { href }, !containerDir && hIcon('file'), name)
191
),
192
+ useEntryCustomCode('afterEntryName', entry),
193
h(EntryProps, entry),
194
h('div', { style:{ clear:'both' } })
195
)
@@ -198,14 +199,18 @@ function fixUrl(s:string) {
199
return s.replace(/[#%]/g, encodeURIComponent)
200
}
201
202
+function useEntryCustomCode(name: string, entry: DirEntry) {
203
+ const code = useMemo(()=> hfsEvent(name, { entry }).filter(Boolean).join(''),
204
+ [entry])
205
+ return h(Html, { code, className: name })
206
+}
207
+
208
const EntryProps = memo((entry: DirEntry & { midnight: Date }) => {
209
const { t, s } = entry
210
const today = t && t > entry.midnight
211
const shortTs = isMobile()
205
- const code = useMemo(()=> hfsEvent('additionalEntryProps', { entry }).join(''),
206
- [entry])
212
return h('div', { className: 'entry-props' },
208
- h(Html, { code, className: 'add-props' }),
213
+ useEntryCustomCode('additionalEntryProps', entry),
214
h(EntrySize, { s }),
215
t && h('span', {
216
className: 'entry-ts',
src/const.ts
+1
-1
@@ -17,7 +17,7 @@ export const VERSION = pkg.version
17
export const DAY = 86_400_000
18
export const SESSION_DURATION = DAY
19
20
-export const API_VERSION = 4.1 // array.$width
20
+export const API_VERSION = 5 // afterEntryName
21
export const COMPATIBLE_API_VERSION = 1 // while changes in the api are not breaking, this number stays the same, otherwise is made equal to API_VERSION
22
23
export const SPECIAL_URI = '/~/'