@projectcaluma/ember-form-builder 14.5.1 → 14.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,7 +11,7 @@
11
11
  {{did-insert this.didInsertNode}}
12
12
  {{will-destroy this.willDestroyNode}}
13
13
  {{autoresize mode="height"}}
14
- {{on "blur" this.onBlur}}
14
+ {{on "blur" @setDirty}}
15
15
  ></div>
16
16
  </div>
17
17
 
@@ -2,6 +2,7 @@ import { action } from "@ember/object";
2
2
  import { addObserver } from "@ember/object/observers";
3
3
  import Component from "@glimmer/component";
4
4
  import { CodeJar } from "codejar";
5
+ import { task, timeout } from "ember-concurrency";
5
6
  import hljs from "highlight.js/lib/core";
6
7
  import json from "highlight.js/lib/languages/json";
7
8
  import markdown from "highlight.js/lib/languages/markdown";
@@ -15,22 +16,34 @@ hljs.registerLanguage("json", json);
15
16
  hljs.registerLanguage("markdown", markdown);
16
17
  hljs.registerLanguage("jexl", jexl);
17
18
 
19
+ const simplify = (value) => {
20
+ if (typeof value === "object") {
21
+ value = JSON.stringify(value?.unwrap?.() ?? value);
22
+ }
23
+
24
+ return value?.replace(/\s/g, "");
25
+ };
26
+
18
27
  export default class CfbCodeEditorComponent extends Component {
19
28
  _editor = null;
20
- _lastValue = this.args.value;
29
+ _lastValue = null;
21
30
 
22
31
  get stringValue() {
23
32
  if (this.args.language === "json" && typeof this.args.value === "object") {
24
33
  return JSON.stringify(
25
34
  this.args.value?.unwrap?.() ?? this.args.value,
26
35
  null,
27
- 2,
36
+ "\t",
28
37
  );
29
38
  }
30
39
 
31
40
  return this.args.value;
32
41
  }
33
42
 
43
+ _didChange(value) {
44
+ return !isEqual(this._lastValue, simplify(value));
45
+ }
46
+
34
47
  @action
35
48
  onUpdate(value) {
36
49
  if (this.args.language === "json") {
@@ -41,24 +54,22 @@ export default class CfbCodeEditorComponent extends Component {
41
54
  }
42
55
  }
43
56
 
44
- if (isEqual(this._lastValue, value)) return;
57
+ if (!this._didChange(value)) return;
45
58
 
46
- this._lastValue = value;
59
+ this._lastValue = simplify(value);
47
60
  this.args.update(value);
48
61
  }
49
62
 
50
- @action
51
- updateCode() {
52
- if (isEqual(this._lastValue, this.args.value)) return;
63
+ updateEditorContent = task({ restartable: true }, async () => {
64
+ // This function is called everytime `this.args.value` changes. In order to
65
+ // not trigger too many updates, we debounce it for 10ms.
66
+ await timeout(10);
53
67
 
54
- this._editor.updateCode(this.stringValue, false);
55
- }
68
+ if (!this._didChange(this.args.value)) return;
56
69
 
57
- @action
58
- onBlur() {
59
- this._editor.updateCode(this.stringValue);
60
- this.args.setDirty();
61
- }
70
+ this._lastValue = simplify(this.args.value);
71
+ this._editor.updateCode(this.stringValue, false);
72
+ });
62
73
 
63
74
  @action
64
75
  didInsertNode(element) {
@@ -68,13 +79,14 @@ export default class CfbCodeEditorComponent extends Component {
68
79
  });
69
80
 
70
81
  // set initial value
71
- this._editor.updateCode(this.stringValue);
82
+ this._editor.updateCode(this.stringValue, false);
83
+ this._lastValue = simplify(this.args.value);
72
84
 
73
85
  // register update method
74
86
  this._editor.onUpdate(this.onUpdate);
75
87
 
76
88
  // eslint-disable-next-line ember/no-observers
77
- addObserver(this.args, "value", this, "updateCode");
89
+ addObserver(this.args, "value", this.updateEditorContent, "perform");
78
90
  }
79
91
 
80
92
  @action
@@ -12,7 +12,6 @@ module.exports = {
12
12
  */
13
13
  return this.addAddonsToProject({
14
14
  packages: [
15
- { name: "@ember/legacy-built-in-components" },
16
15
  { name: "@projectcaluma/ember-core" },
17
16
  { name: "@projectcaluma/ember-form" },
18
17
  { name: "ember-changeset" },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@projectcaluma/ember-form-builder",
3
- "version": "14.5.1",
3
+ "version": "14.6.0",
4
4
  "description": "Ember engine for building Caluma forms.",
5
5
  "keywords": [
6
6
  "ember-addon",
@@ -11,13 +11,10 @@
11
11
  "repository": "github:projectcaluma/ember-caluma",
12
12
  "dependencies": {
13
13
  "@babel/core": "^7.26.0",
14
- "@ember/legacy-built-in-components": "^0.5.0",
15
14
  "@ember/render-modifiers": "^2.1.0 || ^3.0.0",
16
15
  "@ember/string": "^3.1.1 || ^4.0.0",
17
16
  "@embroider/macros": "^1.16.10",
18
- "@glimmer/component": "^1.1.2",
19
- "@glimmer/tracking": "^1.1.2",
20
- "codejar": "~4.2.0",
17
+ "codejar": "^4.3.0",
21
18
  "ember-apollo-client": "^5.0.0",
22
19
  "ember-auto-import": "^2.10.0",
23
20
  "ember-basic-dropdown": "^8.4.0",
@@ -28,7 +25,6 @@
28
25
  "ember-composable-helpers": "^5.0.0",
29
26
  "ember-concurrency": "^4.0.2",
30
27
  "ember-engines-router-service": "^0.6.0",
31
- "ember-fetch": "^8.1.2",
32
28
  "ember-flatpickr": "^8.0.1",
33
29
  "ember-intl": "^7.1.1",
34
30
  "ember-load-initializers": "^2.1.2 || ^3.0.1",
@@ -48,8 +44,8 @@
48
44
  "lodash.isequal": "^4.5.0",
49
45
  "reactiveweb": "^1.3.0",
50
46
  "uikit": "^3.22.0",
51
- "@projectcaluma/ember-form": "^14.5.1",
52
- "@projectcaluma/ember-core": "^14.5.1"
47
+ "@projectcaluma/ember-core": "^14.6.0",
48
+ "@projectcaluma/ember-form": "^14.6.0"
53
49
  },
54
50
  "//": [
55
51
  "TODO: remove obsolete dependency to `ember-data` which is only necessary",
@@ -62,6 +58,8 @@
62
58
  "@ember/test-helpers": "4.0.4",
63
59
  "@embroider/test-setup": "4.0.0",
64
60
  "@faker-js/faker": "10.0.0",
61
+ "@glimmer/component": "1.1.2",
62
+ "@glimmer/tracking": "1.1.2",
65
63
  "broccoli-asset-rev": "3.0.0",
66
64
  "ember-autoresize-modifier": "0.8.0",
67
65
  "ember-cli": "6.1.0",
@@ -85,7 +83,7 @@
85
83
  "qunit-dom": "3.5.0",
86
84
  "sinon": "21.0.0",
87
85
  "webpack": "5.101.3",
88
- "@projectcaluma/ember-testing": "14.5.1"
86
+ "@projectcaluma/ember-testing": "14.6.0"
89
87
  },
90
88
  "peerDependencies": {
91
89
  "ember-engines": "^0.11.0",