create-fesd-app 1.0.17 → 1.0.18

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-fesd-app",
3
- "version": "1.0.17",
3
+ "version": "1.0.18",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "dev": "vite",
@@ -24,7 +24,7 @@
24
24
  "dependencies": {
25
25
  "@tailwindcss/postcss": "^4.1.10",
26
26
  "@tailwindcss/vite": "^4.1.10",
27
- "@xwadex/fesd": "0.0.40",
27
+ "@xwadex/fesd": "0.0.41",
28
28
  "ansi-colors": "^4.1.3",
29
29
  "chalk": "^5.3.0",
30
30
  "clsx": "^2.1.1",
@@ -223,13 +223,14 @@ cookieAdvanced.switchState = () => {
223
223
  if (isSyncing) return
224
224
  isSyncing = true
225
225
 
226
- const $step1Switch = $(`[t4-id='step1'] input[type="checkbox"][data-name='${parent}']:not(.disabled)`)
227
226
  const key = $(this).data("name")
228
227
  const parent = $(this).data("parent")
229
228
  const val = $(this).prop('checked') ? 0 : 1
229
+ const $step1Switch = $(`[t4-id='step1'] input[type="checkbox"][data-name='${parent}']:not(.disabled)`)
230
230
  const total = $($step2contentSwitch).length
231
231
  const checked = $($step2contentSwitch).filter(':checked').length
232
232
 
233
+
233
234
  // 改變 cookieNewObj 的值
234
235
  cookieNewObj[parent].list[key].close = val
235
236
 
@@ -255,7 +256,6 @@ cookieAdvanced.switchState = () => {
255
256
  $(document).off("change.step2top").on("change.step2top", $step2topSwitch, function () {
256
257
  if (isSyncing) return
257
258
  isSyncing = true
258
-
259
259
  const $this = $(this)
260
260
  const key = $this.data("name")
261
261
  const isChecked = $this.prop("checked")
@@ -310,7 +310,7 @@ cookieAdvanced.clickEvent = () => {
310
310
 
311
311
  // 打開進階版 cookie 介面
312
312
  $settingBtn.on("click", () => cookieSetting.openEvent($settingBlock));
313
- // 綁定按鈕
313
+ // 全開
314
314
  $("[data-cookie-all]").on('click', cookieSetting.enableAll)
315
315
  // 儲存
316
316
  $("[data-cookie-save]").on('click', cookieAdvanced.cookieSaveFn)
@@ -360,59 +360,46 @@ cookieSetting.rejectAll = () => {
360
360
  $('.main-option:not([data-name="required"]),.list-option:not([data-name="required"])').removeClass("checked")
361
361
  cookieNewObj.close = 1
362
362
  Object.keys(cookieNewObj).forEach(data => {
363
- cookieNewObj[data].close = 1
363
+ cookieNewObj[data].close == 1
364
364
  })
365
365
  }
366
366
 
367
367
  // 判斷該分類底下細項按鈕狀態
368
368
  cookieSetting.hasAnyListItemsOpen = (key) => {
369
- const targetList = cookieNewObj[key]?.list;
369
+ const category = cookieNewObj[key];
370
+ if (!category) return false;
371
+
372
+ const targetList = category.list;
373
+
374
+ // 沒有子 list,就看自己這一層
370
375
  if (!targetList) {
371
- if (cookieNewObj[key].close == 0) {
372
- return true;
373
- } else {
374
- return false;
375
- }
376
+ return category.close === 0;
376
377
  }
377
- const childKeys = Object.keys(targetList);
378
- const isOpen = childKeys.some(childKey => {
379
- return targetList[childKey]?.close === 0;
380
- });
381
- return isOpen;
378
+
379
+ // 有子 list,就看子項目有沒有任何一個是 open
380
+ return Object.values(targetList).some(item => item?.close === 0);
381
+ };
382
+
383
+ cookieSetting.isCategoryChecked = (key) => {
384
+ if (key === "required") return true;
385
+ return cookieSetting.hasAnyListItemsOpen(key);
386
+ };
387
+
388
+ // 共用:產生 step 元件用的 getter
389
+ const createStepElement = (templateFn) => {
390
+ return (opt, index) => {
391
+ const isDisabled = opt.disabled ? "disabled" : "";
392
+ const isChecked = () =>
393
+ cookieSetting.isCategoryChecked(opt.key) ? "checked" : "";
394
+
395
+ return templateFn(opt, index, isDisabled, isChecked);
396
+ };
382
397
  };
383
398
 
384
399
  // step 1 結構
385
- cookieElements.getStep1Element = (opt, index) => {
386
- const isDisabled = opt.disabled ? "disabled" : ""
387
- const isChecked = () => {
388
- if (opt.key == "required") {
389
- return "checked"
390
- } else {
391
- if (cookieSetting.hasAnyListItemsOpen(opt.key)) {
392
- return "checked"
393
- } else {
394
- return ""
395
- }
396
- }
397
- }
398
- return cookieStep1El(opt, index, isDisabled, isChecked)
399
- }
400
+ cookieElements.getStep1Element = createStepElement(cookieStep1El);
400
401
  // step 2 上面結構
401
- cookieElements.getStep2TopElement = (opt, index) => {
402
- const isDisabled = opt.disabled ? "disabled" : ""
403
- const isChecked = () => {
404
- if (opt.key == "required") {
405
- return "checked"
406
- } else {
407
- if (cookieSetting.hasAnyListItemsOpen(opt.key)) {
408
- return "checked"
409
- } else {
410
- return ""
411
- }
412
- }
413
- }
414
- return cookieStep2TittleEl(opt, index, isDisabled, isChecked)
415
- }
402
+ cookieElements.getStep2TopElement = createStepElement(cookieStep2TittleEl);
416
403
 
417
404
  // 頁籤
418
405
  cookieSetting.goToTab = (el = true) => {