ninegrid2 6.1240.0 → 6.1241.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.
@@ -122244,6 +122244,43 @@ class nxPanel extends nxDiv {
122244
122244
 
122245
122245
  customElements.define("nx-panel", nxPanel);
122246
122246
 
122247
+ class nxPanel2 extends nxDiv2 {
122248
+
122249
+ constructor() {
122250
+ super();
122251
+ }
122252
+
122253
+ connectedCallback() {
122254
+ if (super.connectedCallback()) this.#init();
122255
+ }
122256
+
122257
+ #init = () => {
122258
+ const caption = this.getAttribute("caption");
122259
+ const columns = this.getAttribute("columns") || "";
122260
+
122261
+ const htmlTmpl = document.createElement("template");
122262
+ htmlTmpl.innerHTML = `
122263
+ <style>
122264
+ @import "https://cdn.jsdelivr.net/npm/ninegrid@${ninegrid.version}/dist/css/nxPanel.css";
122265
+ ${ninegrid.getCustomPath(this,"nxPanel.css")}
122266
+ </style>
122267
+
122268
+ <div class="head ${caption ? '' : 'hide'}">
122269
+ <div class="caption"><span>${caption}</span></div>
122270
+ </div>
122271
+ <div class="body">
122272
+ <nx-layout2 columns="${columns}">
122273
+ ${this.originContents}
122274
+ </nx-layout2>
122275
+ </div>
122276
+ `;
122277
+
122278
+ this.appendChild(htmlTmpl.content.cloneNode(true));
122279
+ }
122280
+ }
122281
+
122282
+ customElements.define("nx-panel2", nxPanel2);
122283
+
122247
122284
  class nxButtons extends nxDiv {
122248
122285
 
122249
122286
  constructor() {
@@ -122240,6 +122240,43 @@ class nxPanel extends nxDiv {
122240
122240
 
122241
122241
  customElements.define("nx-panel", nxPanel);
122242
122242
 
122243
+ class nxPanel2 extends nxDiv2 {
122244
+
122245
+ constructor() {
122246
+ super();
122247
+ }
122248
+
122249
+ connectedCallback() {
122250
+ if (super.connectedCallback()) this.#init();
122251
+ }
122252
+
122253
+ #init = () => {
122254
+ const caption = this.getAttribute("caption");
122255
+ const columns = this.getAttribute("columns") || "";
122256
+
122257
+ const htmlTmpl = document.createElement("template");
122258
+ htmlTmpl.innerHTML = `
122259
+ <style>
122260
+ @import "https://cdn.jsdelivr.net/npm/ninegrid@${ninegrid.version}/dist/css/nxPanel.css";
122261
+ ${ninegrid.getCustomPath(this,"nxPanel.css")}
122262
+ </style>
122263
+
122264
+ <div class="head ${caption ? '' : 'hide'}">
122265
+ <div class="caption"><span>${caption}</span></div>
122266
+ </div>
122267
+ <div class="body">
122268
+ <nx-layout2 columns="${columns}">
122269
+ ${this.originContents}
122270
+ </nx-layout2>
122271
+ </div>
122272
+ `;
122273
+
122274
+ this.appendChild(htmlTmpl.content.cloneNode(true));
122275
+ }
122276
+ }
122277
+
122278
+ customElements.define("nx-panel2", nxPanel2);
122279
+
122243
122280
  class nxButtons extends nxDiv {
122244
122281
 
122245
122282
  constructor() {
package/dist/index.js CHANGED
@@ -110,6 +110,7 @@ import "./nx/nxTitle2.js";
110
110
  import "./nx/nxLayout.js";
111
111
  import "./nx/nxLayout2.js";
112
112
  import "./nx/nxPanel.js";
113
+ import "./nx/nxPanel2.js";
113
114
  import "./nx/nxButtons.js";
114
115
  import "./nx/nxModal.js";
115
116
 
@@ -0,0 +1,125 @@
1
+ import ninegrid from "../index.js";
2
+
3
+ export class nxDiv2 extends HTMLElement
4
+ {
5
+ originContents;
6
+ #isInitialized = false;
7
+
8
+ constructor () {
9
+ super();
10
+ //this.attachShadow({ mode: 'open' });
11
+ }
12
+
13
+ connectedCallback() {
14
+ if (!this.#isInitialized) {
15
+ this.#init();
16
+ this.#isInitialized = true; // 3. 초기화 후 플래그를 true로 변경합니다.
17
+ return true;
18
+ }
19
+
20
+ return false;
21
+ }
22
+
23
+ getData = () => {
24
+ const jsonData = {};
25
+
26
+ // Shadow DOM 내의 폼 요소만 선택
27
+ ninegrid.querySelectorAll("input[name], textarea[name], select[name]", this).forEach(el => {
28
+ const key = el.name;
29
+ if (!key) return; // name이 없는 요소는 건너뜁니다.
30
+
31
+ let value;
32
+ if (el.tagName === "INPUT" && (el.type === "checkbox" || el.type === "radio")) {
33
+ value = el.checked;
34
+ } else {
35
+ value = el.value;
36
+ }
37
+
38
+ // 중복 name을 대비한 배열 처리
39
+ if (jsonData[key]) {
40
+ if (!Array.isArray(jsonData[key])) {
41
+ jsonData[key] = [jsonData[key]];
42
+ }
43
+ jsonData[key].push(value);
44
+ } else {
45
+ jsonData[key] = value;
46
+ }
47
+ });
48
+
49
+ return jsonData;
50
+ };
51
+
52
+ setData = (jsonData) => {
53
+ ninegrid.querySelectorAll("input[name], textarea[name], select[name]", this).forEach(el => {
54
+ console.log("------", el);
55
+ el.removeEventListener("input", this.#changeHandler);
56
+ el.addEventListener("input", this.#changeHandler);
57
+ });
58
+
59
+ if (!jsonData || typeof jsonData !== 'object') {
60
+ console.error("setData: Invalid data provided. Expected an object.");
61
+ return;
62
+ }
63
+
64
+ let bChanged = false;
65
+ ninegrid.querySelectorAll("input[name], textarea[name], select[name]", this).forEach(el => {
66
+ const key = el.name;
67
+ if (!key || !jsonData.hasOwnProperty(key)) return;
68
+
69
+ const value = jsonData[key];
70
+
71
+ // 폼 요소에만 데이터를 설정합니다.
72
+ if (el.tagName === "INPUT" || el.tagName === "TEXTAREA" || el.tagName === "SELECT") {
73
+ if (el.type === "checkbox" || el.type === "radio") {
74
+ if (el.checked !== (el.value === String(value))) bChanged = true;
75
+ el.checked = (el.value === String(value));
76
+ } else {
77
+ if (el.value !== value) bChanged = true;
78
+ el.value = value;
79
+ }
80
+ } else {
81
+ // 폼 요소가 아닌 경우, textContent를 사용합니다.
82
+ if (el.textContent !== value) bChanged = true;
83
+ el.textContent = value;
84
+ }
85
+ });
86
+
87
+ if (bChanged) this.#changed(bChanged);
88
+ };
89
+
90
+ initData = (jsonData) => {
91
+ this.setData(jsonData);
92
+ this.#changed(false);
93
+ };
94
+
95
+ #changed = (v) => {
96
+ const parent = this.closest(".detail-wrapper");
97
+ if (parent) {
98
+ const el = parent.querySelector("nx-title2");
99
+ if (el) el.changed = v;
100
+ }
101
+ }
102
+
103
+ #changeHandler = (e) => {
104
+ this.#changed(true);
105
+ }
106
+
107
+ #init = () => {
108
+
109
+ //console.log(this);
110
+ //console.log(this.querySelectorAll("input[name], textarea[name], select[name]"));
111
+
112
+ /**
113
+ * css style 적용
114
+ */
115
+ for (const attr of this.attributes) {
116
+ if (attr.name.startsWith("css-")) {
117
+ // "css-" 접두사를 제거하고 CSS 속성명으로 변환
118
+ this.style.setProperty(attr.name.substring(4), attr.value);
119
+ }
120
+ }
121
+
122
+ this.originContents = this.innerHTML.trim();
123
+ this.innerHTML = ""; // 기존 내부 HTML 제거
124
+ };
125
+ }
@@ -0,0 +1,39 @@
1
+ import ninegrid from "../index.js";
2
+ import {nxDiv} from "./_nxDiv.js";
3
+
4
+ class nxPanel2 extends nxDiv2 {
5
+
6
+ constructor() {
7
+ super();
8
+ }
9
+
10
+ connectedCallback() {
11
+ if (super.connectedCallback()) this.#init();
12
+ }
13
+
14
+ #init = () => {
15
+ const caption = this.getAttribute("caption");
16
+ const columns = this.getAttribute("columns") || "";
17
+
18
+ const htmlTmpl = document.createElement("template");
19
+ htmlTmpl.innerHTML = `
20
+ <style>
21
+ @import "https://cdn.jsdelivr.net/npm/ninegrid@${ninegrid.version}/dist/css/nxPanel.css";
22
+ ${ninegrid.getCustomPath(this,"nxPanel.css")}
23
+ </style>
24
+
25
+ <div class="head ${caption ? '' : 'hide'}">
26
+ <div class="caption"><span>${caption}</span></div>
27
+ </div>
28
+ <div class="body">
29
+ <nx-layout2 columns="${columns}">
30
+ ${this.originContents}
31
+ </nx-layout2>
32
+ </div>
33
+ `;
34
+
35
+ this.appendChild(htmlTmpl.content.cloneNode(true));
36
+ }
37
+ }
38
+
39
+ customElements.define("nx-panel2", nxPanel2);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "ninegrid2",
3
3
  "type": "module",
4
- "version": "6.1240.0",
4
+ "version": "6.1241.0",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "exports": {
package/src/index.js CHANGED
@@ -110,6 +110,7 @@ import "./nx/nxTitle2.js";
110
110
  import "./nx/nxLayout.js";
111
111
  import "./nx/nxLayout2.js";
112
112
  import "./nx/nxPanel.js";
113
+ import "./nx/nxPanel2.js";
113
114
  import "./nx/nxButtons.js";
114
115
  import "./nx/nxModal.js";
115
116
 
@@ -0,0 +1,125 @@
1
+ import ninegrid from "../index.js";
2
+
3
+ export class nxDiv2 extends HTMLElement
4
+ {
5
+ originContents;
6
+ #isInitialized = false;
7
+
8
+ constructor () {
9
+ super();
10
+ //this.attachShadow({ mode: 'open' });
11
+ }
12
+
13
+ connectedCallback() {
14
+ if (!this.#isInitialized) {
15
+ this.#init();
16
+ this.#isInitialized = true; // 3. 초기화 후 플래그를 true로 변경합니다.
17
+ return true;
18
+ }
19
+
20
+ return false;
21
+ }
22
+
23
+ getData = () => {
24
+ const jsonData = {};
25
+
26
+ // Shadow DOM 내의 폼 요소만 선택
27
+ ninegrid.querySelectorAll("input[name], textarea[name], select[name]", this).forEach(el => {
28
+ const key = el.name;
29
+ if (!key) return; // name이 없는 요소는 건너뜁니다.
30
+
31
+ let value;
32
+ if (el.tagName === "INPUT" && (el.type === "checkbox" || el.type === "radio")) {
33
+ value = el.checked;
34
+ } else {
35
+ value = el.value;
36
+ }
37
+
38
+ // 중복 name을 대비한 배열 처리
39
+ if (jsonData[key]) {
40
+ if (!Array.isArray(jsonData[key])) {
41
+ jsonData[key] = [jsonData[key]];
42
+ }
43
+ jsonData[key].push(value);
44
+ } else {
45
+ jsonData[key] = value;
46
+ }
47
+ });
48
+
49
+ return jsonData;
50
+ };
51
+
52
+ setData = (jsonData) => {
53
+ ninegrid.querySelectorAll("input[name], textarea[name], select[name]", this).forEach(el => {
54
+ console.log("------", el);
55
+ el.removeEventListener("input", this.#changeHandler);
56
+ el.addEventListener("input", this.#changeHandler);
57
+ });
58
+
59
+ if (!jsonData || typeof jsonData !== 'object') {
60
+ console.error("setData: Invalid data provided. Expected an object.");
61
+ return;
62
+ }
63
+
64
+ let bChanged = false;
65
+ ninegrid.querySelectorAll("input[name], textarea[name], select[name]", this).forEach(el => {
66
+ const key = el.name;
67
+ if (!key || !jsonData.hasOwnProperty(key)) return;
68
+
69
+ const value = jsonData[key];
70
+
71
+ // 폼 요소에만 데이터를 설정합니다.
72
+ if (el.tagName === "INPUT" || el.tagName === "TEXTAREA" || el.tagName === "SELECT") {
73
+ if (el.type === "checkbox" || el.type === "radio") {
74
+ if (el.checked !== (el.value === String(value))) bChanged = true;
75
+ el.checked = (el.value === String(value));
76
+ } else {
77
+ if (el.value !== value) bChanged = true;
78
+ el.value = value;
79
+ }
80
+ } else {
81
+ // 폼 요소가 아닌 경우, textContent를 사용합니다.
82
+ if (el.textContent !== value) bChanged = true;
83
+ el.textContent = value;
84
+ }
85
+ });
86
+
87
+ if (bChanged) this.#changed(bChanged);
88
+ };
89
+
90
+ initData = (jsonData) => {
91
+ this.setData(jsonData);
92
+ this.#changed(false);
93
+ };
94
+
95
+ #changed = (v) => {
96
+ const parent = this.closest(".detail-wrapper");
97
+ if (parent) {
98
+ const el = parent.querySelector("nx-title2");
99
+ if (el) el.changed = v;
100
+ }
101
+ }
102
+
103
+ #changeHandler = (e) => {
104
+ this.#changed(true);
105
+ }
106
+
107
+ #init = () => {
108
+
109
+ //console.log(this);
110
+ //console.log(this.querySelectorAll("input[name], textarea[name], select[name]"));
111
+
112
+ /**
113
+ * css style 적용
114
+ */
115
+ for (const attr of this.attributes) {
116
+ if (attr.name.startsWith("css-")) {
117
+ // "css-" 접두사를 제거하고 CSS 속성명으로 변환
118
+ this.style.setProperty(attr.name.substring(4), attr.value);
119
+ }
120
+ }
121
+
122
+ this.originContents = this.innerHTML.trim();
123
+ this.innerHTML = ""; // 기존 내부 HTML 제거
124
+ };
125
+ }
@@ -0,0 +1,39 @@
1
+ import ninegrid from "../index.js";
2
+ import {nxDiv} from "./_nxDiv.js";
3
+
4
+ class nxPanel2 extends nxDiv2 {
5
+
6
+ constructor() {
7
+ super();
8
+ }
9
+
10
+ connectedCallback() {
11
+ if (super.connectedCallback()) this.#init();
12
+ }
13
+
14
+ #init = () => {
15
+ const caption = this.getAttribute("caption");
16
+ const columns = this.getAttribute("columns") || "";
17
+
18
+ const htmlTmpl = document.createElement("template");
19
+ htmlTmpl.innerHTML = `
20
+ <style>
21
+ @import "https://cdn.jsdelivr.net/npm/ninegrid@${ninegrid.version}/dist/css/nxPanel.css";
22
+ ${ninegrid.getCustomPath(this,"nxPanel.css")}
23
+ </style>
24
+
25
+ <div class="head ${caption ? '' : 'hide'}">
26
+ <div class="caption"><span>${caption}</span></div>
27
+ </div>
28
+ <div class="body">
29
+ <nx-layout2 columns="${columns}">
30
+ ${this.originContents}
31
+ </nx-layout2>
32
+ </div>
33
+ `;
34
+
35
+ this.appendChild(htmlTmpl.content.cloneNode(true));
36
+ }
37
+ }
38
+
39
+ customElements.define("nx-panel2", nxPanel2);