@projectcaluma/ember-form 11.0.0-beta.15 → 11.0.0-beta.16

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ # [@projectcaluma/ember-form-v11.0.0-beta.16](https://github.com/projectcaluma/ember-caluma/compare/@projectcaluma/ember-form-v11.0.0-beta.15...@projectcaluma/ember-form-v11.0.0-beta.16) (2022-03-23)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **embroider:** add missing dependency on @ember/string ([3a6e6bb](https://github.com/projectcaluma/ember-caluma/commit/3a6e6bb39a8c1a40a2ae00b3d4ea00606a755e25))
7
+ * **embroider:** fix dynamic component usage ([1cf0f6e](https://github.com/projectcaluma/ember-caluma/commit/1cf0f6e2914651bbb0ec70d1f7485fd9db90c9b5))
8
+ * **embroider:** remove obsolete export for getWidget helper function ([94fb461](https://github.com/projectcaluma/ember-caluma/commit/94fb461aaa7cac6af9f5612b8f34ad047a2b67bb))
9
+
1
10
  # [@projectcaluma/ember-form-v11.0.0-beta.15](https://github.com/projectcaluma/ember-caluma/compare/@projectcaluma/ember-form-v11.0.0-beta.14...@projectcaluma/ember-form-v11.0.0-beta.15) (2022-03-16)
2
11
 
3
12
 
@@ -1,17 +1,23 @@
1
- <DocumentValidity
2
- @document={{@field.document}}
3
- @validateOnEnter={{this.validateOnEnter}}
4
- as |isValid validate|
5
- >
6
- <WorkItemButton
7
- @workItemId={{this.workItem}}
8
- @mutation={{this.action}}
9
- @label={{@field.question.raw.label}}
10
- @disabled={{or (and (not-eq isValid null) (not isValid)) @disabled}}
11
- @color={{this.color}}
12
- @beforeMutate={{fn this.beforeMutate validate}}
13
- @onSuccess={{this.onSuccess}}
14
- @onError={{this.onError}}
15
- class={{if @disabled "uk-hidden"}}
16
- />
17
- </DocumentValidity>
1
+ {{#if
2
+ (macroCondition
3
+ (macroDependencySatisfies "@projectcaluma/ember-workflow" "*")
4
+ )
5
+ }}
6
+ <DocumentValidity
7
+ @document={{@field.document}}
8
+ @validateOnEnter={{this.validateOnEnter}}
9
+ as |isValid validate|
10
+ >
11
+ <WorkItemButton
12
+ @workItemId={{this.workItem}}
13
+ @mutation={{this.action}}
14
+ @label={{@field.question.raw.label}}
15
+ @disabled={{or (and (not-eq isValid null) (not isValid)) @disabled}}
16
+ @color={{this.color}}
17
+ @beforeMutate={{fn this.beforeMutate validate}}
18
+ @onSuccess={{this.onSuccess}}
19
+ @onError={{this.onError}}
20
+ class={{if @disabled "uk-hidden"}}
21
+ />
22
+ </DocumentValidity>
23
+ {{/if}}
@@ -1,61 +1,78 @@
1
1
  import { assert } from "@ember/debug";
2
2
  import { action } from "@ember/object";
3
+ import { dependencySatisfies, macroCondition } from "@embroider/macros";
3
4
  import Component from "@glimmer/component";
4
5
  import { confirm } from "ember-uikit";
5
6
 
6
- export default class CfFieldInputActionButtonComponent extends Component {
7
- constructor(...args) {
8
- super(...args);
9
-
10
- assert(
11
- "The document must have a `workItemUuid` for `<CfField::Input::ActionButton />` to work.",
12
- this.args.field.document.workItemUuid
13
- );
14
- }
15
-
16
- get workItem() {
17
- return (
18
- this.args.context?.actionButtonWorkItemId ||
19
- this.args.field.document.workItemUuid
20
- );
21
- }
22
-
23
- get action() {
24
- return this.args.field.question.raw.action.toLowerCase();
25
- }
26
-
27
- get color() {
28
- return this.args.field.question.raw.color.toLowerCase();
29
- }
30
-
31
- get validateOnEnter() {
32
- return (
33
- this.args.field.question.raw.action === "COMPLETE" &&
34
- this.args.field.question.raw.validateOnEnter
35
- );
36
- }
37
-
38
- @action
39
- async beforeMutate(validateFn) {
40
- if (
41
- this.args.field.question.raw.action === "COMPLETE" &&
42
- !(await validateFn())
43
- ) {
44
- return false;
45
- }
46
-
47
- const confirmText = this.args.field.question.raw.infoText;
48
-
49
- return !confirmText || confirm(confirmText);
50
- }
51
-
52
- @action
53
- onSuccess() {
54
- return this.args.context?.actionButtonOnSuccess?.();
55
- }
56
-
57
- @action
58
- onError(error) {
59
- return this.args.context?.actionButtonOnError?.(error);
60
- }
7
+ let CfFieldInputActionButtonComponent;
8
+
9
+ if (macroCondition(dependencySatisfies("@projectcaluma/ember-workflow", ""))) {
10
+ CfFieldInputActionButtonComponent = class extends Component {
11
+ constructor(...args) {
12
+ super(...args);
13
+
14
+ assert(
15
+ "The document must have a `workItemUuid` for `<CfField::Input::ActionButton />` to work.",
16
+ this.args.field.document.workItemUuid
17
+ );
18
+ }
19
+
20
+ get workItem() {
21
+ return (
22
+ this.args.context?.actionButtonWorkItemId ||
23
+ this.args.field.document.workItemUuid
24
+ );
25
+ }
26
+
27
+ get action() {
28
+ return this.args.field.question.raw.action.toLowerCase();
29
+ }
30
+
31
+ get color() {
32
+ return this.args.field.question.raw.color.toLowerCase();
33
+ }
34
+
35
+ get validateOnEnter() {
36
+ return (
37
+ this.args.field.question.raw.action === "COMPLETE" &&
38
+ this.args.field.question.raw.validateOnEnter
39
+ );
40
+ }
41
+
42
+ @action
43
+ async beforeMutate(validateFn) {
44
+ if (
45
+ this.args.field.question.raw.action === "COMPLETE" &&
46
+ !(await validateFn())
47
+ ) {
48
+ return false;
49
+ }
50
+
51
+ const confirmText = this.args.field.question.raw.infoText;
52
+
53
+ return !confirmText || confirm(confirmText);
54
+ }
55
+
56
+ @action
57
+ onSuccess() {
58
+ return this.args.context?.actionButtonOnSuccess?.();
59
+ }
60
+
61
+ @action
62
+ onError(error) {
63
+ return this.args.context?.actionButtonOnError?.(error);
64
+ }
65
+ };
66
+ } else {
67
+ CfFieldInputActionButtonComponent = class extends Component {
68
+ constructor(...args) {
69
+ super(...args);
70
+
71
+ assert(
72
+ "@projectcaluma/ember-workflow must be installed to enable the usage of the action button questions"
73
+ );
74
+ }
75
+ };
61
76
  }
77
+
78
+ export default CfFieldInputActionButtonComponent;
@@ -1,8 +1,7 @@
1
1
  {{#each @field.options as |option i|}}
2
- {{#if (gt i 0)}}<br />{{/if}}
2
+ {{#if (and (gt i 0) (not @field.raw.question.meta.vertical))}}<br />{{/if}}
3
3
  <label
4
- class="cf-checkbox_label
5
- {{if @field.isInvalid 'uk-form-danger'}}
4
+ class="{{if @field.isInvalid 'uk-form-danger'}}
6
5
  {{if @field.raw.question.meta.vertical 'uk-margin-large-right'}}"
7
6
  >
8
7
  <input
@@ -1,29 +1,27 @@
1
- {{#let (component this.componentName) as |DynamicSelect|}}
2
- <DynamicSelect
3
- @options={{@field.options}}
4
- @selected={{@field.selected}}
5
- @disabled={{@disabled}}
6
- @allowClear={{true}}
7
- @preventScroll={{true}}
8
- @searchEnabled={{this.searchEnabled}}
9
- @searchField="label"
10
- @triggerId={{@field.pk}}
11
- @renderInPlace={{true}}
12
- @placeholder={{this.placeholder}}
13
- @loadingMessage={{t "caluma.form.power-select.options-loading"}}
14
- @searchMessage={{t "caluma.form.power-select.options-empty"}}
15
- @searchPlaceholder={{t "caluma.form.power-select.search-placeholder"}}
16
- @noMatchesMessage={{t "caluma.form.power-select.search-empty"}}
17
- @onChange={{this.change}}
18
- as |option|
19
- >
20
- {{#if (and option.disabled (not @disabled))}}
21
- <del
22
- class="uk-text-muted"
23
- title={{t "caluma.form.optionNotAvailable"}}
24
- >{{option.label}}</del>
25
- {{else}}
26
- {{option.label}}
27
- {{/if}}
28
- </DynamicSelect>
29
- {{/let}}
1
+ <this.selectComponent
2
+ @options={{@field.options}}
3
+ @selected={{@field.selected}}
4
+ @disabled={{@disabled}}
5
+ @allowClear={{true}}
6
+ @preventScroll={{true}}
7
+ @searchEnabled={{this.searchEnabled}}
8
+ @searchField="label"
9
+ @triggerId={{@field.pk}}
10
+ @renderInPlace={{true}}
11
+ @placeholder={{this.placeholder}}
12
+ @loadingMessage={{t "caluma.form.power-select.options-loading"}}
13
+ @searchMessage={{t "caluma.form.power-select.options-empty"}}
14
+ @searchPlaceholder={{t "caluma.form.power-select.search-placeholder"}}
15
+ @noMatchesMessage={{t "caluma.form.power-select.search-empty"}}
16
+ @onChange={{this.change}}
17
+ as |option|
18
+ >
19
+ {{#if (and option.disabled (not @disabled))}}
20
+ <del
21
+ class="uk-text-muted"
22
+ title={{t "caluma.form.optionNotAvailable"}}
23
+ >{{option.label}}</del>
24
+ {{else}}
25
+ {{option.label}}
26
+ {{/if}}
27
+ </this.selectComponent>
@@ -1,7 +1,10 @@
1
1
  import { getOwner } from "@ember/application";
2
2
  import { action } from "@ember/object";
3
3
  import { inject as service } from "@ember/service";
4
+ import { ensureSafeComponent } from "@embroider/util";
4
5
  import Component from "@glimmer/component";
6
+ import PowerSelectComponent from "ember-power-select/components/power-select";
7
+ import PowerSelectMultipleComponent from "ember-power-select/components/power-select-multiple";
5
8
 
6
9
  /**
7
10
  * Dropdown component for the single and multiple choice question type
@@ -16,8 +19,11 @@ export default class CfFieldInputPowerselectComponent extends Component {
16
19
  return this.args.field?.question.isMultipleChoice;
17
20
  }
18
21
 
19
- get componentName() {
20
- return this.multiple ? "power-select-multiple" : "power-select";
22
+ get selectComponent() {
23
+ return ensureSafeComponent(
24
+ this.multiple ? PowerSelectMultipleComponent : PowerSelectComponent,
25
+ this
26
+ );
21
27
  }
22
28
 
23
29
  get searchEnabled() {
@@ -1,5 +1,5 @@
1
1
  {{#each @field.options as |option i|}}
2
- {{#if (gt i 0)}}<br />{{/if}}
2
+ {{#if (and (gt i 0) (not @field.raw.question.meta.vertical))}}<br />{{/if}}
3
3
  <label
4
4
  class="{{if @field.isInvalid 'uk-form-danger'}}
5
5
  {{if @field.raw.question.meta.vertical 'uk-margin-large-right'}}"
@@ -1,21 +1,8 @@
1
- {{#if this.type}}
2
- {{#let (component (concat "cf-field/input/" this.type)) as |InputComponent|}}
3
- <div
4
- class="uk-form-controls
5
- {{if
6
- (and
7
- (has-question-type @field.question 'multiple-choice' 'choice')
8
- @field.question.raw.meta.vertical
9
- )
10
- 'uk-flex'
11
- }}"
12
- >
13
- <InputComponent
14
- @field={{@field}}
15
- @disabled={{@disabled}}
16
- @onSave={{@onSave}}
17
- @context={{@context}}
18
- />
19
- </div>
20
- {{/let}}
21
- {{/if}}
1
+ <div class="uk-form-controls">
2
+ <this.inputComponent
3
+ @field={{@field}}
4
+ @disabled={{@disabled}}
5
+ @onSave={{@onSave}}
6
+ @context={{@context}}
7
+ />
8
+ </div>
@@ -1,12 +1,33 @@
1
- import { dasherize } from "@ember/string";
1
+ import { ensureSafeComponent } from "@embroider/util";
2
2
  import Component from "@glimmer/component";
3
3
 
4
- const mapping = {
5
- MultipleChoiceQuestion: "checkbox",
6
- ChoiceQuestion: "radio",
7
- DynamicMultipleChoiceQuestion: "checkbox",
8
- DynamicChoiceQuestion: "radio",
9
- CalculatedFloatQuestion: "float",
4
+ import ActionButtonComponent from "@projectcaluma/ember-form/components/cf-field/input/action-button";
5
+ import CheckboxComponent from "@projectcaluma/ember-form/components/cf-field/input/checkbox";
6
+ import DateComponent from "@projectcaluma/ember-form/components/cf-field/input/date";
7
+ import FileComponent from "@projectcaluma/ember-form/components/cf-field/input/file";
8
+ import FloatComponent from "@projectcaluma/ember-form/components/cf-field/input/float";
9
+ import IntegerComponent from "@projectcaluma/ember-form/components/cf-field/input/integer";
10
+ import RadioComponent from "@projectcaluma/ember-form/components/cf-field/input/radio";
11
+ import StaticComponent from "@projectcaluma/ember-form/components/cf-field/input/static";
12
+ import TableComponent from "@projectcaluma/ember-form/components/cf-field/input/table";
13
+ import TextComponent from "@projectcaluma/ember-form/components/cf-field/input/text";
14
+ import TextareaComponent from "@projectcaluma/ember-form/components/cf-field/input/textarea";
15
+
16
+ const COMPONENT_MAPPING = {
17
+ ActionButtonQuestion: ActionButtonComponent,
18
+ CalculatedFloatQuestion: FloatComponent,
19
+ ChoiceQuestion: RadioComponent,
20
+ DateQuestion: DateComponent,
21
+ DynamicChoiceQuestion: RadioComponent,
22
+ DynamicMultipleChoiceQuestion: CheckboxComponent,
23
+ FileQuestion: FileComponent,
24
+ FloatQuestion: FloatComponent,
25
+ IntegerQuestion: IntegerComponent,
26
+ MultipleChoiceQuestion: CheckboxComponent,
27
+ StaticQuestion: StaticComponent,
28
+ TableQuestion: TableComponent,
29
+ TextareaQuestion: TextareaComponent,
30
+ TextQuestion: TextComponent,
10
31
  };
11
32
 
12
33
  /**
@@ -16,17 +37,14 @@ const mapping = {
16
37
  */
17
38
  export default class CfFieldInputComponent extends Component {
18
39
  /**
19
- * The input component type
40
+ * The input component
20
41
  *
21
- * @property {String} type
42
+ * @property {Component} inputComponent
22
43
  * @accessor
23
44
  */
24
- get type() {
45
+ get inputComponent() {
25
46
  const typename = this.args.field?.question.raw.__typename;
26
47
 
27
- return (
28
- typename &&
29
- (mapping[typename] || dasherize(typename.replace(/Question$/, "")))
30
- );
48
+ return ensureSafeComponent(COMPONENT_MAPPING[typename], this);
31
49
  }
32
50
  }
@@ -1,4 +1 @@
1
- export {
2
- default,
3
- getWidget,
4
- } from "@projectcaluma/ember-form/helpers/get-widget";
1
+ export { default } from "@projectcaluma/ember-form/helpers/get-widget";
@@ -9,20 +9,3 @@
9
9
  min-height: 20px;
10
10
  min-width: 20px;
11
11
  }
12
-
13
- .cf-checkbox_label {
14
- display: block;
15
- position: relative;
16
- padding-left: 26px;
17
-
18
- .uk-checkbox {
19
- position: absolute;
20
- top: 0.25em;
21
- left: 0;
22
- margin: 0;
23
- }
24
-
25
- & + br {
26
- display: none;
27
- }
28
- }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@projectcaluma/ember-form",
3
- "version": "11.0.0-beta.15",
3
+ "version": "11.0.0-beta.16",
4
4
  "description": "Ember addon for rendering Caluma forms.",
5
5
  "keywords": [
6
6
  "ember-addon"
@@ -14,11 +14,13 @@
14
14
  "test:ember-compatibility": "ember try:each"
15
15
  },
16
16
  "dependencies": {
17
+ "@ember/string": "^3.0.0",
17
18
  "@embroider/macros": "^1.5.0",
19
+ "@embroider/util": "^1.5.0",
18
20
  "@glimmer/component": "^1.0.4",
19
21
  "@glimmer/tracking": "^1.0.4",
20
- "@projectcaluma/ember-core": "^11.0.0-beta.5",
21
- "ember-apollo-client": "^3.2.1",
22
+ "@projectcaluma/ember-core": "^11.0.0-beta.6",
23
+ "ember-apollo-client": "^4.0.2",
22
24
  "ember-auto-import": "^2.4.0",
23
25
  "ember-autoresize-modifier": "^0.5.0",
24
26
  "ember-cli-babel": "^7.26.11",
@@ -33,7 +35,7 @@
33
35
  "ember-pikaday": "^4.0.0",
34
36
  "ember-power-select": "^5.0.4",
35
37
  "ember-resources": "^4.4.0",
36
- "ember-uikit": "^5.1.0",
38
+ "ember-uikit": "^5.1.1",
37
39
  "ember-validators": "^4.1.2",
38
40
  "graphql": "^15.8.0",
39
41
  "jexl": "^2.3.0",
@@ -45,8 +47,8 @@
45
47
  "@ember/optional-features": "2.0.0",
46
48
  "@ember/test-helpers": "2.6.0",
47
49
  "@embroider/test-setup": "1.5.0",
48
- "@faker-js/faker": "6.0.0-beta.0",
49
- "@projectcaluma/ember-testing": "11.0.0-beta.4",
50
+ "@faker-js/faker": "6.0.0",
51
+ "@projectcaluma/ember-testing": "11.0.0-beta.5",
50
52
  "@projectcaluma/ember-workflow": "11.0.0-beta.5",
51
53
  "broccoli-asset-rev": "3.0.0",
52
54
  "ember-cli": "3.28.5",
@@ -73,6 +75,14 @@
73
75
  "uuid": "8.3.2",
74
76
  "webpack": "5.70.0"
75
77
  },
78
+ "peerDependencies": {
79
+ "@projectcaluma/ember-workflow": "^11.0.0-beta.5"
80
+ },
81
+ "peerDependenciesMeta": {
82
+ "@projectcaluma/ember-workflow": {
83
+ "optional": true
84
+ }
85
+ },
76
86
  "engines": {
77
87
  "node": "12.* || 14.* || >= 16"
78
88
  },