FEATURE: select-kit api to modify collection header
This commit is contained in:
parent
0eb71cef98
commit
56834dbd98
|
@ -25,7 +25,7 @@ import { modifySelectKit } from "select-kit/mixins/plugin-api";
|
||||||
import { addGTMPageChangedCallback } from 'discourse/lib/page-tracker';
|
import { addGTMPageChangedCallback } from 'discourse/lib/page-tracker';
|
||||||
|
|
||||||
// If you add any methods to the API ensure you bump up this number
|
// If you add any methods to the API ensure you bump up this number
|
||||||
const PLUGIN_API_VERSION = '0.8.16';
|
const PLUGIN_API_VERSION = '0.8.17';
|
||||||
|
|
||||||
class PluginApi {
|
class PluginApi {
|
||||||
constructor(version, container) {
|
constructor(version, container) {
|
||||||
|
|
|
@ -46,6 +46,7 @@ export default SelectKitComponent.extend({
|
||||||
values = this.computeValues(values);
|
values = this.computeValues(values);
|
||||||
values = this._beforeDidComputeValues(values);
|
values = this._beforeDidComputeValues(values);
|
||||||
this._setHeaderComputedContent();
|
this._setHeaderComputedContent();
|
||||||
|
this._setCollectionHeaderComputedContent();
|
||||||
this.didComputeContent(content);
|
this.didComputeContent(content);
|
||||||
this.didComputeValues(values);
|
this.didComputeValues(values);
|
||||||
this.didComputeAttributes();
|
this.didComputeAttributes();
|
||||||
|
@ -85,6 +86,7 @@ export default SelectKitComponent.extend({
|
||||||
Ember.run.next(() => {
|
Ember.run.next(() => {
|
||||||
this.mutateContent(this.get("computedContent"));
|
this.mutateContent(this.get("computedContent"));
|
||||||
this.mutateValues(this.get("computedValues"));
|
this.mutateValues(this.get("computedValues"));
|
||||||
|
this._setCollectionHeaderComputedContent();
|
||||||
this._setHeaderComputedContent();
|
this._setHeaderComputedContent();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
|
@ -7,7 +7,8 @@ import PluginApiMixin from "select-kit/mixins/plugin-api";
|
||||||
import {
|
import {
|
||||||
applyContentPluginApiCallbacks,
|
applyContentPluginApiCallbacks,
|
||||||
applyHeaderContentPluginApiCallbacks,
|
applyHeaderContentPluginApiCallbacks,
|
||||||
applyOnSelectPluginApiCallbacks
|
applyOnSelectPluginApiCallbacks,
|
||||||
|
applyCollectionHeaderCallbacks
|
||||||
} from "select-kit/mixins/plugin-api";
|
} from "select-kit/mixins/plugin-api";
|
||||||
|
|
||||||
export default Ember.Component.extend(UtilsMixin, PluginApiMixin, DomHelpersMixin, EventsMixin, {
|
export default Ember.Component.extend(UtilsMixin, PluginApiMixin, DomHelpersMixin, EventsMixin, {
|
||||||
|
@ -51,6 +52,7 @@ export default Ember.Component.extend(UtilsMixin, PluginApiMixin, DomHelpersMixi
|
||||||
headerComponent: "select-kit/select-kit-header",
|
headerComponent: "select-kit/select-kit-header",
|
||||||
headerComponentOptions: null,
|
headerComponentOptions: null,
|
||||||
headerComputedContent: null,
|
headerComputedContent: null,
|
||||||
|
collectionHeaderComputedContent: null,
|
||||||
collectionComponent: "select-kit/select-kit-collection",
|
collectionComponent: "select-kit/select-kit-collection",
|
||||||
collectionHeight: 200,
|
collectionHeight: 200,
|
||||||
verticalOffset: 0,
|
verticalOffset: 0,
|
||||||
|
@ -237,6 +239,15 @@ export default Ember.Component.extend(UtilsMixin, PluginApiMixin, DomHelpersMixi
|
||||||
this.setProperties({ filter: "" });
|
this.setProperties({ filter: "" });
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_setCollectionHeaderComputedContent() {
|
||||||
|
const collectionHeaderComputedContent = applyCollectionHeaderCallbacks(
|
||||||
|
this.get("pluginApiIdentifiers"),
|
||||||
|
this.get("collectionHeader"),
|
||||||
|
this
|
||||||
|
);
|
||||||
|
this.set("collectionHeaderComputedContent", collectionHeaderComputedContent);
|
||||||
|
},
|
||||||
|
|
||||||
_setHeaderComputedContent() {
|
_setHeaderComputedContent() {
|
||||||
const headerComputedContent = applyHeaderContentPluginApiCallbacks(
|
const headerComputedContent = applyHeaderContentPluginApiCallbacks(
|
||||||
this.get("pluginApiIdentifiers"),
|
this.get("pluginApiIdentifiers"),
|
||||||
|
|
|
@ -26,6 +26,7 @@ export default SelectKitComponent.extend({
|
||||||
|
|
||||||
if (this.get("allowInitialValueMutation")) this.mutateAttributes();
|
if (this.get("allowInitialValueMutation")) this.mutateAttributes();
|
||||||
|
|
||||||
|
this._setCollectionHeaderComputedContent();
|
||||||
this._setHeaderComputedContent();
|
this._setHeaderComputedContent();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -36,6 +37,7 @@ export default SelectKitComponent.extend({
|
||||||
run.next(() => {
|
run.next(() => {
|
||||||
this.mutateContent(this.get("computedContent"));
|
this.mutateContent(this.get("computedContent"));
|
||||||
this.mutateValue(this.get("computedValue"));
|
this.mutateValue(this.get("computedValue"));
|
||||||
|
this._setCollectionHeaderComputedContent();
|
||||||
this._setHeaderComputedContent();
|
this._setHeaderComputedContent();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
|
@ -80,6 +80,7 @@ export default Ember.Mixin.create({
|
||||||
this.setProperties({ isExpanded: true, renderedBodyOnce: true, isFocused: true });
|
this.setProperties({ isExpanded: true, renderedBodyOnce: true, isFocused: true });
|
||||||
this.focusFilterOrHeader();
|
this.focusFilterOrHeader();
|
||||||
this.autoHighlight();
|
this.autoHighlight();
|
||||||
|
this._setCollectionHeaderComputedContent();
|
||||||
this._setHeaderComputedContent();
|
this._setHeaderComputedContent();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,15 @@ function modifyHeaderComputedContent(pluginApiIdentifiers, contentFunction) {
|
||||||
_modifyHeaderComputedContentCallbacks[pluginApiIdentifiers].push(contentFunction);
|
_modifyHeaderComputedContentCallbacks[pluginApiIdentifiers].push(contentFunction);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let _modifyCollectionHeaderCallbacks = {};
|
||||||
|
function modifyCollectionHeader(pluginApiIdentifiers, contentFunction) {
|
||||||
|
if (Ember.isNone(_modifyCollectionHeaderCallbacks[pluginApiIdentifiers])) {
|
||||||
|
_modifyCollectionHeaderCallbacks[pluginApiIdentifiers] = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
_modifyCollectionHeaderCallbacks[pluginApiIdentifiers].push(contentFunction);
|
||||||
|
}
|
||||||
|
|
||||||
let _onSelectCallbacks = {};
|
let _onSelectCallbacks = {};
|
||||||
function onSelect(pluginApiIdentifiers, mutationFunction) {
|
function onSelect(pluginApiIdentifiers, mutationFunction) {
|
||||||
if (Ember.isNone(_onSelectCallbacks[pluginApiIdentifiers])) {
|
if (Ember.isNone(_onSelectCallbacks[pluginApiIdentifiers])) {
|
||||||
|
@ -69,6 +78,16 @@ export function applyHeaderContentPluginApiCallbacks(identifiers, content, conte
|
||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function applyCollectionHeaderCallbacks(identifiers, content, context) {
|
||||||
|
identifiers.forEach((key) => {
|
||||||
|
(_modifyCollectionHeaderCallbacks[key] || []).forEach((c) => {
|
||||||
|
content = c(context, content);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
|
||||||
export function applyOnSelectPluginApiCallbacks(identifiers, val, context) {
|
export function applyOnSelectPluginApiCallbacks(identifiers, val, context) {
|
||||||
identifiers.forEach((key) => {
|
identifiers.forEach((key) => {
|
||||||
(_onSelectCallbacks[key] || []).forEach((c) => c(context, val));
|
(_onSelectCallbacks[key] || []).forEach((c) => c(context, val));
|
||||||
|
@ -93,6 +112,10 @@ export function modifySelectKit(pluginApiIdentifiers) {
|
||||||
modifyHeaderComputedContent(pluginApiIdentifiers, callback);
|
modifyHeaderComputedContent(pluginApiIdentifiers, callback);
|
||||||
return modifySelectKit(pluginApiIdentifiers);
|
return modifySelectKit(pluginApiIdentifiers);
|
||||||
},
|
},
|
||||||
|
modifyCollectionHeader: (callback) => {
|
||||||
|
modifyCollectionHeader(pluginApiIdentifiers, callback);
|
||||||
|
return modifySelectKit(pluginApiIdentifiers);
|
||||||
|
},
|
||||||
onSelect: (callback) => {
|
onSelect: (callback) => {
|
||||||
onSelect(pluginApiIdentifiers, callback);
|
onSelect(pluginApiIdentifiers, callback);
|
||||||
return modifySelectKit(pluginApiIdentifiers);
|
return modifySelectKit(pluginApiIdentifiers);
|
||||||
|
@ -105,6 +128,7 @@ export function clearCallbacks() {
|
||||||
_prependContentCallbacks = {};
|
_prependContentCallbacks = {};
|
||||||
_modifyContentCallbacks = {};
|
_modifyContentCallbacks = {};
|
||||||
_modifyHeaderComputedContentCallbacks = {};
|
_modifyHeaderComputedContentCallbacks = {};
|
||||||
|
_modifyCollectionHeaderCallbacks = {};
|
||||||
_onSelectCallbacks = {};
|
_onSelectCallbacks = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
|
|
||||||
{{#if renderedBodyOnce}}
|
{{#if renderedBodyOnce}}
|
||||||
{{component collectionComponent
|
{{component collectionComponent
|
||||||
collectionHeader=collectionHeader
|
collectionHeaderComputedContent=collectionHeaderComputedContent
|
||||||
hasSelection=hasSelection
|
hasSelection=hasSelection
|
||||||
noneRowComputedContent=noneRowComputedContent
|
noneRowComputedContent=noneRowComputedContent
|
||||||
createRowComputedContent=createRowComputedContent
|
createRowComputedContent=createRowComputedContent
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{{#if collectionHeader}}
|
{{#if collectionHeaderComputedContent}}
|
||||||
<div class="collection-header">
|
<div class="collection-header">
|
||||||
{{{collectionHeader}}}
|
{{{collectionHeaderComputedContent}}}
|
||||||
</div>
|
</div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue