select-kit initial plugin api implementation (0.8.13)

```
api.modifySelectKit("identifier-of-the-select-targeted")
  .modifyContent((context, existingContent) => {})
  .appendContent(() => {})
  .prependContent(() => {})
  .onSelect((context, val) => {});
```
This commit is contained in:
Joffrey JAFFEUX
2017-11-22 10:34:12 +01:00
committed by GitHub
parent 211dac6f71
commit b2b565c2fb
6 changed files with 88 additions and 25 deletions
@@ -2,6 +2,9 @@ import SelectKitComponent from "select-kit/components/select-kit";
import computed from "ember-addons/ember-computed-decorators";
import { on } from "ember-addons/ember-computed-decorators";
const { get, isNone, isEmpty, makeArray } = Ember;
import {
applyOnSelectPluginApiCallbacks
} from "select-kit/mixins/plugin-api";
export default SelectKitComponent.extend({
pluginApiIdentifiers: ["multi-select"],
@@ -81,10 +84,14 @@ export default SelectKitComponent.extend({
Ember.run.next(() => {
this.mutateContent(this.get("computedContent"));
this.mutateValues(this.get("computedValues"));
applyOnSelectPluginApiCallbacks(this.get("pluginApiIdentifiers"), this.get("computedValues"), this);
this.set("headerComputedContent", this.computeHeaderContent());
});
},
mutateValues(computedValues) { this.set("values", computedValues); },
mutateValues(computedValues) {
this.set("values", computedValues);
},
mutateContent() { },
filterComputedContent(computedContent, computedValues, filter) {
const lowerFilter = filter.toLowerCase();
@@ -1,10 +1,12 @@
const { isNone, run, makeArray } = Ember;
const { isNone, makeArray } = Ember;
import computed from "ember-addons/ember-computed-decorators";
import UtilsMixin from "select-kit/mixins/utils";
import DomHelpersMixin from "select-kit/mixins/dom-helpers";
import EventsMixin from "select-kit/mixins/events";
import PluginApiMixin from "select-kit/mixins/plugin-api";
import { applyContentPluginApiCallbacks } from "select-kit/mixins/plugin-api";
import {
applyContentPluginApiCallbacks
} from "select-kit/mixins/plugin-api";
export default Ember.Component.extend(UtilsMixin, PluginApiMixin, DomHelpersMixin, EventsMixin, {
pluginApiIdentifiers: ["select-kit"],
@@ -81,7 +83,7 @@ export default Ember.Component.extend(UtilsMixin, PluginApiMixin, DomHelpersMixi
willComputeContent(content) { return content; },
computeContent(content) { return content; },
_beforeDidComputeContent(content) {
content = applyContentPluginApiCallbacks(this.get("pluginApiIdentifiers"), content);
content = applyContentPluginApiCallbacks(this.get("pluginApiIdentifiers"), content, this);
const existingCreatedComputedContent = this.get("computedContent").filterBy("created", true);
this.setProperties({
@@ -91,16 +93,6 @@ export default Ember.Component.extend(UtilsMixin, PluginApiMixin, DomHelpersMixi
},
didComputeContent() {},
mutateAttributes() {
run.next(() => {
this.mutateContent(this.get("computedContent"));
this.mutateValue(this.get("computedValue"));
this.set("headerComputedContent", this.computeHeaderContent());
});
},
mutateContent() {},
mutateValue(computedValue) { this.set("value", computedValue); },
computeHeaderContent() {
return this.baseHeaderComputedContent();
},
@@ -1,7 +1,10 @@
import SelectKitComponent from "select-kit/components/select-kit";
import { on } from "ember-addons/ember-computed-decorators";
import computed from "ember-addons/ember-computed-decorators";
const { get, isNone, isEmpty, isPresent } = Ember;
const { get, isNone, isEmpty, isPresent, run } = Ember;
import {
applyOnSelectPluginApiCallbacks
} from "select-kit/mixins/plugin-api";
export default SelectKitComponent.extend({
pluginApiIdentifiers: ["single-select"],
@@ -44,6 +47,19 @@ export default SelectKitComponent.extend({
});
},
mutateAttributes() {
run.next(() => {
this.mutateContent(this.get("computedContent"));
this.mutateValue(this.get("computedValue"));
applyOnSelectPluginApiCallbacks(this.get("pluginApiIdentifiers"), this.get("computedValue"), this);
this.set("headerComputedContent", this.computeHeaderContent());
});
},
mutateContent() {},
mutateValue(computedValue) {
this.set("value", computedValue);
},
_beforeWillComputeValue(value) {
switch (typeof value) {
case "string":