Skip to content
This repository was archived by the owner on Jul 30, 2025. It is now read-only.

Commit 60d613b

Browse files
committed
feat(packages/core): mode registrations should be overridable
Fixes #3175
1 parent 91cd2cc commit 60d613b

File tree

6 files changed

+42
-7
lines changed

6 files changed

+42
-7
lines changed

packages/core/src/models/mmr/show.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,14 @@ async function renderContent<T extends MetadataBearing>(
114114
} else if (isFunctionContent(content)) {
115115
const actualContent: ScalarResource | ScalarContent = await content.content(tab, bearer)
116116
if (!isScalarContent(actualContent)) {
117-
return {
118-
content: actualContent
117+
if (isTable(actualContent) || isMultiTable(actualContent)) {
118+
return {
119+
content: wrapTable(tab, actualContent)
120+
}
121+
} else {
122+
return {
123+
content: actualContent
124+
}
119125
}
120126
} else {
121127
return actualContent

packages/core/src/models/mmr/types.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,13 @@ export interface ModeTraits {
7171
/** should this mode be given preference as the default selected mode? */
7272
defaultMode?: boolean
7373

74-
/** sort order; default is as given */
74+
/** order in view; lower will be rendered further to the "left" for
75+
* LTR; default order registration order */
7576
order?: number
77+
78+
/** registration tie-breaker: if more than one plugin offers the
79+
* same mode, the one with the highest numeric priority wins */
80+
priority?: number
7681
}
7782

7883
/**

packages/core/src/webapp/views/registrar/modes.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,23 @@ export function apply<Resource extends MetadataBearing>(
9797
const theMode = isButton(theModeOrButton)
9898
? formatButton(tab, resource.resource, theModeOrButton)
9999
: theModeOrButton
100-
if (!modes.find(({ mode }) => mode === theMode.mode)) {
100+
101+
const idxOfPreexistingRegistrationForSameMode = modes.findIndex(({ mode }) => mode === theMode.mode)
102+
if (idxOfPreexistingRegistrationForSameMode < 0) {
101103
modes.push(theMode)
104+
} else {
105+
// two plugins register the same mode; see if we can break the
106+
// tie using the `priority` field of the modes
107+
const oldMode = modes[idxOfPreexistingRegistrationForSameMode]
108+
const prio1 = oldMode.priority || 0
109+
const prio2 = theMode.priority || 0
110+
if (prio2 > prio1) {
111+
// splice the override in place, deleting the existing entry
112+
if (oldMode.defaultMode && theMode.defaultMode !== false) {
113+
theMode.defaultMode = true
114+
}
115+
modes.splice(idxOfPreexistingRegistrationForSameMode, 1, theMode)
116+
}
102117
}
103118

104119
/* if (grabDefaultMode) {

packages/core/src/webapp/views/sidecar.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,10 @@ export const addNameToSidecarHeader = async (
301301
}
302302

303303
// handle ToolbarText
304-
const toolbarTextSpec = isToolbarText(subtext) ? subtext : isCustomSpec(entity) && entity.toolbarText
304+
const toolbarTextSpec = isToolbarText(subtext)
305+
? subtext
306+
: isCustomSpec(entity) &&
307+
(entity.toolbarText || (isMetadataBearingByReference(entity) && entity.resource.toolbarText))
305308
const toolbarTextContainer = element('.sidecar-bottom-stripe-toolbar .sidecar-toolbar-text', sidecar)
306309
const toolbarTextContent = element('.sidecar-toolbar-text-content', toolbarTextContainer)
307310
removeAllDomChildren(toolbarTextContent)

packages/core/src/webapp/views/table.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { Tab } from '../tab'
2121
import { isPopup } from '../popup-core'
2222
import { getCurrentPrompt } from '../prompt'
2323
import { _split as split, Split } from '../../repl/split'
24+
import { isMetadataBearing } from '../../models/entity'
2425
import {
2526
Table,
2627
MultiTable,
@@ -484,6 +485,11 @@ export const formatOneRowResult = (tab: Tab, options: RowFormatOptions = {}) =>
484485
qexec(entity.onclick, undefined, undefined, { tab })
485486
}
486487
}
488+
} else if (isMetadataBearing(entity.onclick)) {
489+
entityNameClickable.onclick = async () => {
490+
const { show } = await import('../../models/mmr/show')
491+
return show(tab, entity.onclick)
492+
}
487493
} else {
488494
entityNameClickable.onclick = entity.onclick
489495
}

packages/core/web/css/kui-tables.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,8 @@ sidecar
190190
/* table row striping */
191191
background-color: var(--color-ui-02);
192192
}
193-
body sidecar .result-table .entity:nth-child(2n + 1) td,
194-
body sidecar .result-table .entity:nth-child(2n + 1) .entity-attributes {
193+
body sidecar .result-table .entity:nth-child(2n) td,
194+
body sidecar .result-table .entity:nth-child(2n) .entity-attributes {
195195
/* table row striping in sidecar (when not full screen) */
196196
background: var(--color-ui-03);
197197
}

0 commit comments

Comments
 (0)