@dooboostore/simple-web-component 1.0.7 → 1.0.8

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.
@@ -1 +1 @@
1
- {"version":3,"file":"elementDefine.d.ts","sourceRoot":"","sources":["../../../src/decorators/elementDefine.ts"],"names":[],"mappings":"AAWA,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,kBAAkB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC9B,qBAAqB,CAAC,EAAE,qBAAqB,CAAC;IAC9C,wBAAwB,CAAC,EAAE,OAAO,CAAC;CACpC;AAED,eAAO,MAAM,kBAAkB,eAAgD,CAAC;AAChF,eAAO,MAAM,kBAAkB,qBAAqB,CAAC;AAqErD,eAAO,MAAM,aAAa,GACvB,UAAU,aAAa,GAAG,MAAM,KAAG,cA+WnC,CAAC;AAEJ,eAAO,MAAM,gBAAgB,GAAI,QAAQ,GAAG,KAAG,aAAa,GAAG,SAG9D,CAAC"}
1
+ {"version":3,"file":"elementDefine.d.ts","sourceRoot":"","sources":["../../../src/decorators/elementDefine.ts"],"names":[],"mappings":"AAWA,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,kBAAkB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC9B,qBAAqB,CAAC,EAAE,qBAAqB,CAAC;IAC9C,wBAAwB,CAAC,EAAE,OAAO,CAAC;CACpC;AAED,eAAO,MAAM,kBAAkB,eAAgD,CAAC;AAChF,eAAO,MAAM,kBAAkB,qBAAqB,CAAC;AAqErD,eAAO,MAAM,aAAa,GACvB,UAAU,aAAa,GAAG,MAAM,KAAG,cA+YnC,CAAC;AAEJ,eAAO,MAAM,gBAAgB,GAAI,QAAQ,GAAG,KAAG,aAAa,GAAG,SAG9D,CAAC"}
@@ -1,5 +1,5 @@
1
1
  export declare class SwcUtils {
2
- static getValueByPath(obj: any, path: string, asKey: string): any;
2
+ static getValueByPath(obj: any, path: string, rootName: string): any;
3
3
  static applyData(node: Node, data: any, options: {
4
4
  asKey: string;
5
5
  asIndexKey: string;
@@ -1 +1 @@
1
- {"version":3,"file":"Utils.d.ts","sourceRoot":"","sources":["../../../src/utils/Utils.ts"],"names":[],"mappings":"AAAA,qBAAa,QAAQ;IACnB,MAAM,CAAC,cAAc,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IA8C3D,MAAM,CAAC,SAAS,CACd,IAAI,EAAE,IAAI,EACV,IAAI,EAAE,GAAG,EACT,OAAO,EAAE;QACP,KAAK,EAAE,MAAM,CAAC;QACd,UAAU,EAAE,MAAM,CAAC;QACnB,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB;IAwCH,MAAM,CAAC,mBAAmB,CAAC,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,IAAI,EAAE,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,KAAK,IAAI;CA6BhH"}
1
+ {"version":3,"file":"Utils.d.ts","sourceRoot":"","sources":["../../../src/utils/Utils.ts"],"names":[],"mappings":"AAAA,qBAAa,QAAQ;IACnB,MAAM,CAAC,cAAc,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;IAkC9D,MAAM,CAAC,SAAS,CACd,IAAI,EAAE,IAAI,EACV,IAAI,EAAE,GAAG,EACT,OAAO,EAAE;QACP,KAAK,EAAE,MAAM,CAAC;QACd,UAAU,EAAE,MAAM,CAAC;QACnB,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB;IAwCH,MAAM,CAAC,mBAAmB,CAAC,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,IAAI,EAAE,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,KAAK,IAAI;CA2BhH"}
@@ -1948,36 +1948,27 @@ var dooboostoreSimpleWebComponent = (() => {
1948
1948
 
1949
1949
  // src/utils/Utils.ts
1950
1950
  var SwcUtils = class _SwcUtils {
1951
- static getValueByPath(obj, path, asKey) {
1951
+ static getValueByPath(obj, path, rootName) {
1952
1952
  if (!obj || !path) return void 0;
1953
1953
  const parts = path.split(".");
1954
- let result = obj;
1955
- let success = true;
1956
- for (const part of parts) {
1957
- if (result !== null && typeof result === "object" && part in result) {
1958
- result = result[part];
1959
- } else {
1960
- success = false;
1961
- break;
1962
- }
1963
- }
1964
- if (success && result !== obj && !(result instanceof HTMLElement)) {
1965
- return result;
1966
- }
1967
- if (path === asKey) return obj;
1968
- if (path.startsWith(asKey + ".")) {
1954
+ if (parts[0] === rootName && parts.length > 1) {
1969
1955
  const subParts = parts.slice(1);
1970
1956
  let subResult = obj;
1971
1957
  for (const part of subParts) {
1972
- if (subResult !== null && typeof subResult === "object" && part in subResult) {
1973
- subResult = subResult[part];
1974
- } else {
1975
- return void 0;
1976
- }
1958
+ if (subResult === null || subResult === void 0) return void 0;
1959
+ subResult = subResult[part];
1977
1960
  }
1978
1961
  return subResult;
1979
1962
  }
1980
- if (obj instanceof HTMLElement && obj.parentElement) {
1963
+ let result = obj;
1964
+ for (const part of parts) {
1965
+ if (result === null || result === void 0 || !(part in result)) {
1966
+ return void 0;
1967
+ }
1968
+ result = result[part];
1969
+ }
1970
+ if (result !== obj && !(result instanceof HTMLElement)) {
1971
+ return result;
1981
1972
  }
1982
1973
  return void 0;
1983
1974
  }
@@ -2257,8 +2248,6 @@ var dooboostoreSimpleWebComponent = (() => {
2257
2248
  }
2258
2249
  }
2259
2250
  _buildStateMap() {
2260
- this._stateBindings.clear();
2261
- this._externalSources.clear();
2262
2251
  const scan = (root) => {
2263
2252
  const walker = document.createTreeWalker(root, NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_TEXT);
2264
2253
  let node = null;
@@ -2267,7 +2256,7 @@ var dooboostoreSimpleWebComponent = (() => {
2267
2256
  else if (node.nodeType === Node.ELEMENT_NODE) {
2268
2257
  const el = node;
2269
2258
  const alias = el.getAttribute("as");
2270
- if (alias) {
2259
+ if (alias && !this._externalSources.has(alias)) {
2271
2260
  this._externalSources.set(alias, el);
2272
2261
  el.addEventListener(STATE_CHANGE_EVENT, () => this._updateState(alias));
2273
2262
  }
@@ -2279,9 +2268,12 @@ var dooboostoreSimpleWebComponent = (() => {
2279
2268
  scan(this);
2280
2269
  }
2281
2270
  _parseAndBind(node, type, owner) {
2282
- const content = node.textContent || "";
2271
+ const tplKey = `__swc_original_${this._swcId}`;
2272
+ const isAlreadyBound = node.__swc_bound_ids?.has(this._swcId);
2273
+ const content = node[tplKey] || node.textContent || "";
2283
2274
  const matches = Array.from(content.matchAll(/{{(.*?)}}/g));
2284
2275
  if (matches.length === 0) return;
2276
+ if (isAlreadyBound) return;
2285
2277
  matches.forEach((match) => {
2286
2278
  const fullPath = match[1].trim();
2287
2279
  const rootName = fullPath.split(".")[0];
@@ -2291,8 +2283,9 @@ var dooboostoreSimpleWebComponent = (() => {
2291
2283
  const isSelfAlias = this.getAttribute("as") === rootName;
2292
2284
  if (!isState && !isLogicKey && !isExternal && !isSelfAlias) return;
2293
2285
  if (!this._stateBindings.has(rootName)) this._stateBindings.set(rootName, []);
2294
- const tplKey = `__swc_original_${this._swcId}`;
2295
2286
  if (!node[tplKey]) node[tplKey] = content;
2287
+ if (!node.__swc_bound_ids) node.__swc_bound_ids = /* @__PURE__ */ new Set();
2288
+ node.__swc_bound_ids.add(this._swcId);
2296
2289
  this._stateBindings.get(rootName).push({ node, type, owner, path: fullPath });
2297
2290
  this._updateState(rootName);
2298
2291
  });
@@ -2310,7 +2303,9 @@ var dooboostoreSimpleWebComponent = (() => {
2310
2303
  const tplKey = `__swc_original_${this._swcId}`;
2311
2304
  bindings.forEach((bin) => {
2312
2305
  let text = bin.node[tplKey];
2306
+ if (!text) return;
2313
2307
  const matches = Array.from(text.matchAll(/{{(.*?)}}/g));
2308
+ let updatedText = text;
2314
2309
  for (const match of matches) {
2315
2310
  const path = match[1].trim();
2316
2311
  const root = path.split(".")[0];
@@ -2342,14 +2337,20 @@ var dooboostoreSimpleWebComponent = (() => {
2342
2337
  }
2343
2338
  if (val !== void 0) {
2344
2339
  const strVal = val === null || val === void 0 ? "" : typeof val === "object" ? "[Object]" : String(val);
2345
- text = text.replace(match[0], strVal);
2340
+ updatedText = updatedText.replace(match[0], strVal);
2346
2341
  if (bin.type === "attribute" && bin.owner) {
2347
- if (val === null || val === void 0) bin.owner.removeAttribute(bin.attrName);
2348
- else bin.owner.setAttribute(bin.attrName, text);
2342
+ const attrName = bin.node.name;
2343
+ if (val === null || val === void 0) bin.owner.removeAttribute(attrName);
2344
+ else {
2345
+ bin.owner.setAttribute(attrName, updatedText);
2346
+ if ((attrName === "value" || attrName === "checked") && bin.owner.tagName.match(/INPUT|TEXTAREA|SELECT/)) {
2347
+ bin.owner[attrName] = updatedText;
2348
+ }
2349
+ }
2349
2350
  }
2350
2351
  }
2351
2352
  }
2352
- if (bin.type === "text") bin.node.textContent = text;
2353
+ if (bin.type === "text") bin.node.textContent = updatedText;
2353
2354
  });
2354
2355
  }
2355
2356
  disconnectedCallback() {