@dooboostore/simple-web-component 1.0.38 → 1.0.39

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.
Files changed (31) hide show
  1. package/README.md +31 -833
  2. package/dist/cjs/decorators/applyNode.js +26 -39
  3. package/dist/cjs/decorators/applyNode.js.map +2 -2
  4. package/dist/cjs/decorators/applySlot.js +69 -64
  5. package/dist/cjs/decorators/applySlot.js.map +3 -3
  6. package/dist/cjs/decorators/elementDefine.js +0 -7
  7. package/dist/cjs/decorators/elementDefine.js.map +2 -2
  8. package/dist/cjs/decorators/state.js +0 -1
  9. package/dist/cjs/decorators/state.js.map +2 -2
  10. package/dist/esm/decorators/applyNode.js +26 -39
  11. package/dist/esm/decorators/applyNode.js.map +2 -2
  12. package/dist/esm/decorators/applySlot.js +69 -64
  13. package/dist/esm/decorators/applySlot.js.map +3 -3
  14. package/dist/esm/decorators/elementDefine.js +0 -7
  15. package/dist/esm/decorators/elementDefine.js.map +2 -2
  16. package/dist/esm/decorators/state.js +0 -1
  17. package/dist/esm/decorators/state.js.map +2 -2
  18. package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +124 -139
  19. package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
  20. package/dist/types/decorators/applyNode.d.ts +2 -2
  21. package/dist/types/decorators/applyNode.d.ts.map +1 -1
  22. package/dist/types/decorators/applySlot.d.ts +14 -12
  23. package/dist/types/decorators/applySlot.d.ts.map +1 -1
  24. package/dist/types/decorators/state.d.ts.map +1 -1
  25. package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +124 -139
  26. package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
  27. package/package.json +3 -3
  28. package/src/decorators/applyNode.ts +43 -51
  29. package/src/decorators/applySlot.ts +97 -86
  30. package/src/decorators/elementDefine.ts +6 -6
  31. package/src/decorators/state.ts +0 -1
@@ -9443,98 +9443,6 @@ var InjectSituationType = /* @__PURE__ */ ((InjectSituationType2) => {
9443
9443
  return InjectSituationType2;
9444
9444
  })(InjectSituationType || {});
9445
9445
 
9446
- // src/decorators/applySlot.ts
9447
- var APPLY_SLOT_METADATA_KEY = Symbol.for("simple-web-component:apply-slot");
9448
- function applySlot(id, options = { position: "replaceChildrenHtml" }) {
9449
- return (targetObj, propertyKey, descriptor) => {
9450
- const type = descriptor === void 0 ? "property" : "method";
9451
- if (type === "property") {
9452
- Object.defineProperty(targetObj, propertyKey, {
9453
- get() {
9454
- const nodeSlot = new NodeSlot(this, `${this._swcId}-${id}`);
9455
- return nodeSlot;
9456
- },
9457
- set(nv) {
9458
- if (nv) {
9459
- } else {
9460
- const nodeSlot = new NodeSlot(this, `${this._swcId}-${id}`);
9461
- nodeSlot.clear();
9462
- }
9463
- },
9464
- configurable: true,
9465
- enumerable: true
9466
- });
9467
- }
9468
- const constructor = targetObj.constructor;
9469
- let metaList = ReflectUtils.getOwnMetadata(APPLY_SLOT_METADATA_KEY, constructor);
9470
- if (!metaList) {
9471
- metaList = [];
9472
- ReflectUtils.defineMetadata(APPLY_SLOT_METADATA_KEY, metaList, constructor);
9473
- }
9474
- metaList.push({ propertyKey, id, type, options });
9475
- if (type === "method") {
9476
- const original = descriptor.value;
9477
- descriptor.value = function(...args) {
9478
- ensureInit(this);
9479
- const conf = getElementConfig(this);
9480
- const currentWin = this._resolveWindow?.(conf) || (typeof window !== "undefined" ? window : void 0);
9481
- const currentDoc = currentWin.document;
9482
- const hostSet = SwcUtils.getHelperAndHostSet(currentWin, this);
9483
- let res = original.apply(this, args);
9484
- if (res) {
9485
- const nodeSlot = new NodeSlot(this, this._swcId);
9486
- const pos = options.position || "replaceChildrenHtml";
9487
- const doc = currentWin.document;
9488
- if (pos === "replaceChildrenHtml") {
9489
- nodeSlot.replaceChildrenHtml(id, res);
9490
- } else if (pos === "replaceChildrenText") {
9491
- nodeSlot.replaceChildrenText(id, res);
9492
- } else if (pos === "appendHtml") {
9493
- nodeSlot.appendHtml(id, res);
9494
- } else if (pos === "appendText") {
9495
- nodeSlot.appendText(id, res);
9496
- } else if (pos === "prependHtml") {
9497
- nodeSlot.prependHtml(id, res);
9498
- } else if (pos === "prependText") {
9499
- nodeSlot.prependText(id, res);
9500
- } else if (pos === "clear") {
9501
- nodeSlot.clear(id);
9502
- }
9503
- }
9504
- return res;
9505
- };
9506
- }
9507
- };
9508
- }
9509
- var findAllApplySlotMetadata = (target) => {
9510
- const constructor = target instanceof Function ? target : target.constructor;
9511
- return ReflectUtils.getMetadata(APPLY_SLOT_METADATA_KEY, constructor);
9512
- };
9513
- function applySlotClear(id) {
9514
- return applySlot(id, { position: "clear" });
9515
- }
9516
- function applySlotPrependHtml(id) {
9517
- return applySlot(id, { position: "prependHtml" });
9518
- }
9519
- var applySlotPrepend = applySlotPrependHtml;
9520
- function applySlotPrependText(id) {
9521
- return applySlot(id, { position: "prependText" });
9522
- }
9523
- function applySlotAppendHtml(id) {
9524
- return applySlot(id, { position: "appendHtml" });
9525
- }
9526
- function applySlotAppendText(id) {
9527
- return applySlot(id, { position: "appendText" });
9528
- }
9529
- var applySlotAppend = applySlotAppendHtml;
9530
- function applySlotReplaceChildrenHtml(id) {
9531
- return applySlot(id, { position: "replaceChildrenHtml" });
9532
- }
9533
- var applySlotReplaceChildren = applySlotReplaceChildrenHtml;
9534
- function applySlotReplaceChildrenText(id) {
9535
- return applySlot(id, { position: "replaceChildrenText" });
9536
- }
9537
-
9538
9446
  // src/decorators/state.ts
9539
9447
  var STATE_METADATA_KEY = Symbol.for("simple-web-component:state");
9540
9448
  function state(nameOrTarget, propertyKey) {
@@ -9542,7 +9450,6 @@ function state(nameOrTarget, propertyKey) {
9542
9450
  let storage = targetObj[stateMetadata.propertyKey];
9543
9451
  Object.defineProperty(targetObj, stateMetadata.propertyKey, {
9544
9452
  set(nv) {
9545
- console.log("setState!!", nv);
9546
9453
  storage = nv;
9547
9454
  const config = getElementConfig(this);
9548
9455
  const ea = new ElementApply(this, { id: this._swcId });
@@ -9624,12 +9531,6 @@ var ensureInit = (inst) => {
9624
9531
  delete inst[meta.propertyKey];
9625
9532
  });
9626
9533
  }
9627
- const slotAllList = findAllApplySlotMetadata(target);
9628
- if (slotAllList) {
9629
- slotAllList.filter((it) => it.type === "property").forEach((meta) => {
9630
- delete inst[meta.propertyKey];
9631
- });
9632
- }
9633
9534
  const stateAllList = findAllStateMetadata(target);
9634
9535
  if (stateAllList) {
9635
9536
  stateAllList.forEach((meta) => {
@@ -10316,56 +10217,42 @@ var findAllAttributeMetadata = (target) => {
10316
10217
 
10317
10218
  // src/decorators/applyNode.ts
10318
10219
  var APPLY_NODE_METADATA_KEY = Symbol.for("simple-web-component:apply-node");
10319
- var normalizeNodes = (res, doc) => {
10320
- const items = Array.isArray(res) ? res : [res];
10321
- return items.map((it) => {
10322
- if (it instanceof Node) return it;
10323
- return doc.createTextNode(it !== void 0 && it !== null ? String(it) : "");
10324
- });
10325
- };
10326
10220
  var applyToDom = (currentThis, targetEl, res, pos, win, host) => {
10327
10221
  if (!targetEl) return;
10328
10222
  const doc = win.document;
10329
10223
  const hostSet = SwcUtils.getHelperAndHostSet(win, currentThis);
10330
10224
  const id = currentThis._swcId;
10331
- try {
10332
- if (typeof res === "string") {
10333
- const processed = SwcUtils.projectProcessHtml(id, res, doc);
10334
- if (processed !== void 0) res = processed;
10335
- } else if (res) {
10336
- SwcUtils.projectProcessHtml(id, res, doc);
10337
- }
10338
- } catch (e) {
10339
- }
10340
- if (pos === "innerHtml") {
10341
- targetEl.innerHTML = res !== void 0 && res !== null ? String(res) : "";
10342
- return;
10343
- }
10344
- if (pos === "innerText") {
10345
- if (targetEl.innerText !== void 0) {
10346
- targetEl.innerText = res !== void 0 && res !== null ? String(res) : "";
10347
- }
10348
- return;
10349
- }
10350
- const stateContext = { ...hostSet };
10351
- findAllStateMetadata(currentThis).forEach((it) => {
10352
- stateContext[it.name] = currentThis[it.propertyKey];
10353
- });
10354
- new ElementApply(currentThis, { id: currentThis._swcId }).apply({ target: "noInitialized", context: stateContext, bind: currentThis });
10225
+ const nodes = [];
10226
+ if (typeof res === "string" && pos === "innerHtml") {
10227
+ const t = win.document.createElement("template");
10228
+ t.innerHTML = res;
10229
+ nodes.push(...Array.from(t.content.childNodes));
10230
+ } else if (typeof res === "string" && pos === "innerText") {
10231
+ nodes.push(win.document.createTextNode(res));
10232
+ }
10233
+ SwcUtils.projectProcessHtml(id, nodes, doc);
10355
10234
  const isShadowRoot = targetEl instanceof win.ShadowRoot;
10356
- const nodes = normalizeNodes(res, doc);
10357
10235
  if (pos === "replace") {
10358
10236
  if (!isShadowRoot) targetEl.replaceWith(...nodes);
10237
+ } else if (pos === "innerHtml") {
10238
+ targetEl.replaceChildren(...nodes);
10239
+ } else if (pos === "innerText") {
10240
+ targetEl.replaceChildren(...nodes);
10359
10241
  } else if (pos === "replaceChildren") {
10360
10242
  targetEl.replaceChildren(...nodes);
10361
10243
  } else {
10362
10244
  if (pos === "beforeEnd") {
10363
- console.log("tarbbbbbbbbbbbbbb");
10364
10245
  targetEl.append(...nodes);
10365
10246
  } else if (pos === "afterBegin") targetEl.prepend(...nodes);
10366
10247
  else if (pos === "beforeBegin" && !isShadowRoot) targetEl.before(...nodes);
10367
10248
  else if (pos === "afterEnd" && !isShadowRoot) targetEl.after(...nodes);
10368
10249
  }
10250
+ const stateContext = { ...hostSet };
10251
+ findAllStateMetadata(currentThis).forEach((it) => {
10252
+ stateContext[it.name] = currentThis[it.propertyKey];
10253
+ });
10254
+ new ElementApply(targetEl, { id }).apply({ target: "noInitialized", context: stateContext, bind: currentThis });
10255
+ return nodes;
10369
10256
  };
10370
10257
  function applyNode(selector, options = { position: "replaceChildren" }) {
10371
10258
  return (targetObj, propertyKey, descriptor) => {
@@ -10412,13 +10299,14 @@ function applyNode(selector, options = { position: "replaceChildren" }) {
10412
10299
  applyToDom(this, target, processedVal, pos, currentWin);
10413
10300
  }
10414
10301
  };
10302
+ const fallbackNodes = [];
10303
+ if (targetEl && options.fallback) {
10304
+ const loadingRes = options.fallback.call(this, hostSet);
10305
+ fallbackNodes.push(...applyToDom(this, targetEl, loadingRes, options.position || "beforeEnd", currentWin));
10306
+ }
10415
10307
  if (res instanceof Promise) {
10416
- if (targetEl && options.fallback) {
10417
- const loadingRes = options.fallback.call(this, hostSet);
10418
- applyToDom(this, targetEl, loadingRes, options.position || "beforeEnd", currentWin);
10419
- }
10420
10308
  return res.then((finalRes) => {
10421
- console.log("amnkj");
10309
+ fallbackNodes.forEach((it) => it.remove());
10422
10310
  if (finalRes !== void 0 && targetEl) runApply(targetEl, finalRes);
10423
10311
  return finalRes;
10424
10312
  });
@@ -10487,7 +10375,7 @@ function applyNodeThisAfterBeginLightDom(targetOrOptions, propertyKey, descripto
10487
10375
  const opt = targetOrOptions || {};
10488
10376
  return applyNode("$this", { ...opt, ...option });
10489
10377
  }
10490
- function applyThisInnerHtmlNode(targetOrOptions, propertyKey, descriptor) {
10378
+ function applyNodeThisInnerHtml(targetOrOptions, propertyKey, descriptor) {
10491
10379
  const option = { position: "innerHtml" };
10492
10380
  if (propertyKey !== void 0) return applyNode("$this", option)(targetOrOptions, propertyKey, descriptor);
10493
10381
  const opt = targetOrOptions || {};
@@ -10983,6 +10871,103 @@ var getPublishSwcAppMessageMetadata = (target) => {
10983
10871
  return ReflectUtils.getOwnMetadata(PUBLISH_SWC_APP_MESSAGE_METADATA_KEY, constructor);
10984
10872
  };
10985
10873
 
10874
+ // src/decorators/applySlot.ts
10875
+ var APPLY_SLOT_METADATA_KEY = Symbol.for("simple-web-component:apply-slot");
10876
+ var applyToDom2 = (swcId, id, pos, nodes) => {
10877
+ const nodeSlot = new NodeSlot(void 0, swcId);
10878
+ if (pos === "replaceChildrenText" || pos === "replaceChildren" || pos === "replaceChildrenHtml") {
10879
+ nodeSlot.replaceChildren(id, ...nodes);
10880
+ } else if (pos === "appendHtml" || pos === "append" || pos === "appendText") {
10881
+ nodeSlot.append(id, ...nodes);
10882
+ } else if (pos === "prependHtml" || pos === "prepend" || pos === "prependText") {
10883
+ nodeSlot.prepend(id, ...nodes);
10884
+ } else if (pos === "clear") {
10885
+ nodeSlot.clear(id);
10886
+ }
10887
+ };
10888
+ function applySlot(targetId, opt) {
10889
+ return (targetObj, propertyKey, descriptor) => {
10890
+ const options = { position: "replaceChildrenHtml", ...opt };
10891
+ const constructor = targetObj.constructor;
10892
+ let metaList = ReflectUtils.getOwnMetadata(APPLY_SLOT_METADATA_KEY, constructor);
10893
+ if (!metaList) {
10894
+ metaList = [];
10895
+ ReflectUtils.defineMetadata(APPLY_SLOT_METADATA_KEY, metaList, constructor);
10896
+ }
10897
+ metaList.push({ propertyKey, targetId, options });
10898
+ const original = descriptor.value;
10899
+ descriptor.value = function(...args) {
10900
+ ensureInit(this);
10901
+ const conf = getElementConfig(this);
10902
+ const currentWin = conf.window;
10903
+ const swcId = this._swcId;
10904
+ const currentDoc = currentWin.document;
10905
+ const hostSet = SwcUtils.getHelperAndHostSet(currentWin, this);
10906
+ const pos = options.position;
10907
+ const resToNodes = (res2) => {
10908
+ const nodes = [];
10909
+ if (typeof res2 === "string" && (pos === "replaceChildrenHtml" || pos === "appendHtml" || pos === "prependHtml")) {
10910
+ const t = currentWin.document.createElement("template");
10911
+ t.innerHTML = res2;
10912
+ nodes.push(...Array.from(t.content.childNodes));
10913
+ } else if (typeof res2 === "string" && (pos === "replaceChildrenText" || pos === "prependText" || pos === "appendText")) {
10914
+ nodes.push(currentWin.document.createTextNode(res2));
10915
+ } else if (typeof res2 === "object") {
10916
+ nodes.push(res2);
10917
+ }
10918
+ SwcUtils.projectProcessHtml(swcId, nodes, currentDoc);
10919
+ return nodes;
10920
+ };
10921
+ const fallbackNodes = [];
10922
+ if (options.fallback) {
10923
+ const res2 = options.fallback.call(this, hostSet);
10924
+ const nodes = resToNodes(res2);
10925
+ fallbackNodes.push(...nodes);
10926
+ applyToDom2(swcId, targetId, options.position, nodes);
10927
+ }
10928
+ let res = original.apply(this, args);
10929
+ if (res instanceof Promise) {
10930
+ return res.then((asyncRes) => {
10931
+ const nodes = resToNodes(asyncRes);
10932
+ fallbackNodes.forEach((it) => it.remove());
10933
+ applyToDom2(swcId, targetId, options.position, nodes);
10934
+ });
10935
+ } else {
10936
+ const nodes = resToNodes(res);
10937
+ applyToDom2(swcId, targetId, options.position, nodes);
10938
+ }
10939
+ };
10940
+ };
10941
+ }
10942
+ var findAllApplySlotMetadata = (target) => {
10943
+ const constructor = target instanceof Function ? target : target.constructor;
10944
+ return ReflectUtils.getMetadata(APPLY_SLOT_METADATA_KEY, constructor);
10945
+ };
10946
+ function applySlotClear(targetId) {
10947
+ return applySlot(targetId, { position: "clear" });
10948
+ }
10949
+ function applySlotPrependHtml(targetId) {
10950
+ return applySlot(targetId, { position: "prependHtml" });
10951
+ }
10952
+ var applySlotPrepend = applySlotPrependHtml;
10953
+ function applySlotPrependText(targetId) {
10954
+ return applySlot(targetId, { position: "prependText" });
10955
+ }
10956
+ function applySlotAppendHtml(targetId) {
10957
+ return applySlot(targetId, { position: "appendHtml" });
10958
+ }
10959
+ function applySlotAppendText(targetId) {
10960
+ return applySlot(targetId, { position: "appendText" });
10961
+ }
10962
+ var applySlotAppend = applySlotAppendHtml;
10963
+ function applySlotReplaceChildrenHtml(targetId) {
10964
+ return applySlot(targetId, { position: "replaceChildrenHtml" });
10965
+ }
10966
+ var applySlotReplaceChildren = applySlotReplaceChildrenHtml;
10967
+ function applySlotReplaceChildrenText(targetId) {
10968
+ return applySlot(targetId, { position: "replaceChildrenText" });
10969
+ }
10970
+
10986
10971
  // ../simple-boot/dist/esm/index.js
10987
10972
  var import_reflect_metadata = __toESM(require_Reflect(), 1);
10988
10973
 
@@ -13675,6 +13660,7 @@ export {
13675
13660
  applyNodeThisBeforeEnd,
13676
13661
  applyNodeThisBeforeEndLightDom,
13677
13662
  applyNodeThisBeforeEndShadow,
13663
+ applyNodeThisInnerHtml,
13678
13664
  applyNodeThisReplaceChildren,
13679
13665
  applyNodeThisReplaceChildrenLightDom,
13680
13666
  applySlot,
@@ -13690,7 +13676,6 @@ export {
13690
13676
  applySlotReplaceChildrenText,
13691
13677
  applyStyle,
13692
13678
  applyStyleThis,
13693
- applyThisInnerHtmlNode,
13694
13679
  applyThisInnerHtmlNodeLightDom,
13695
13680
  applyThisReplaceChildrenNodeLightDom,
13696
13681
  attribute,