itmar-block-packages 1.3.9 → 1.3.10

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": "itmar-block-packages",
3
- "version": "1.3.9",
3
+ "version": "1.3.10",
4
4
  "description": "We have put together a package of common React components used for WordPress custom blocks.",
5
5
  "main": "build/index.js",
6
6
  "scripts": {
package/src/BlockPlace.js CHANGED
@@ -615,3 +615,169 @@ export default function BlockPlace(props) {
615
615
  </>
616
616
  );
617
617
  }
618
+
619
+ export function BlockWidth(props) {
620
+ const { attributes, isMobile, isSubmenu } = props;
621
+ const { default_val, mobile_val } = attributes;
622
+
623
+ //モバイルかデスクトップか
624
+ const sel_pos = isMobile ? mobile_val : default_val;
625
+
626
+ // 翻訳が必要な文字列を直接指定
627
+ const blockMaxWidthMobile = __(
628
+ "Block Max Width(Mobile)",
629
+ "block-collections"
630
+ );
631
+ const blockWidthMobile = __("Block Width(Mobile)", "block-collections");
632
+ const blockMaxWidthDesktop = __(
633
+ "Block Max Width(DeskTop)",
634
+ "block-collections"
635
+ );
636
+ const blockWidthDesktop = __("Block Width(DeskTop)", "block-collections");
637
+
638
+ // 条件に応じて選択
639
+ const blockWidthLabel = isMobile
640
+ ? isSubmenu
641
+ ? blockWidthMobile
642
+ : blockMaxWidthMobile
643
+ : isSubmenu
644
+ ? blockWidthDesktop
645
+ : blockMaxWidthDesktop;
646
+
647
+ return (
648
+ <>
649
+ <p>{blockWidthLabel}</p>
650
+ <ToolbarGroup>
651
+ <ToolbarItem>
652
+ {(itemProps) => (
653
+ <Button
654
+ {...itemProps}
655
+ isPressed={sel_pos.width_val === "full"}
656
+ onClick={() => props.onWidthChange("full")}
657
+ text="full"
658
+ />
659
+ )}
660
+ </ToolbarItem>
661
+ <ToolbarItem>
662
+ {(itemProps) => (
663
+ <Button
664
+ {...itemProps}
665
+ isPressed={sel_pos.width_val === "fit"}
666
+ onClick={() => props.onWidthChange("fit")}
667
+ text="fit"
668
+ />
669
+ )}
670
+ </ToolbarItem>
671
+ <ToolbarItem>
672
+ {(itemProps) => (
673
+ <Button
674
+ {...itemProps}
675
+ isPressed={sel_pos.width_val === "wideSize"}
676
+ onClick={() => props.onWidthChange("wideSize")}
677
+ icon={stretchWide}
678
+ label={__("Wide Size", "block-collections")}
679
+ />
680
+ )}
681
+ </ToolbarItem>
682
+ <ToolbarItem>
683
+ {(itemProps) => (
684
+ <Button
685
+ {...itemProps}
686
+ isPressed={sel_pos.width_val === "contentSize"}
687
+ onClick={() => props.onWidthChange("contentSize")}
688
+ icon={positionCenter}
689
+ label={__("Content Size", "block-collections")}
690
+ />
691
+ )}
692
+ </ToolbarItem>
693
+ <ToolbarItem>
694
+ {(itemProps) => (
695
+ <Button
696
+ {...itemProps}
697
+ isPressed={sel_pos.width_val === "free"}
698
+ onClick={() => props.onWidthChange("free")}
699
+ text="free"
700
+ />
701
+ )}
702
+ </ToolbarItem>
703
+ </ToolbarGroup>
704
+
705
+ {sel_pos.width_val === "free" && (
706
+ <RangeControl
707
+ value={sel_pos.free_width}
708
+ label={__("Max width", "block-collections")}
709
+ max={1800}
710
+ min={50}
711
+ step={10}
712
+ onChange={(newValue) => {
713
+ props.onFreeWidthChange(newValue);
714
+ }}
715
+ withInputField={true}
716
+ />
717
+ )}
718
+ </>
719
+ );
720
+ }
721
+
722
+ export function BlockHeight(props) {
723
+ const { attributes, isMobile } = props;
724
+ const { default_val, mobile_val } = attributes;
725
+
726
+ //モバイルかデスクトップか
727
+ const sel_pos = isMobile ? mobile_val : default_val;
728
+
729
+ return (
730
+ <>
731
+ {isMobile ? (
732
+ <p>{__("Block Height(Mobile)", "block-collections")}</p>
733
+ ) : (
734
+ <p>{__("Block Height(DeskTop)", "block-collections")}</p>
735
+ )}
736
+ <ToolbarGroup>
737
+ <ToolbarItem>
738
+ {(itemProps) => (
739
+ <Button
740
+ {...itemProps}
741
+ isPressed={sel_pos.height_val === "full"}
742
+ onClick={() => props.onHeightChange("full")}
743
+ text="full"
744
+ />
745
+ )}
746
+ </ToolbarItem>
747
+ <ToolbarItem>
748
+ {(itemProps) => (
749
+ <Button
750
+ {...itemProps}
751
+ isPressed={sel_pos.height_val === "fit"}
752
+ onClick={() => props.onHeightChange("fit")}
753
+ text="fit"
754
+ />
755
+ )}
756
+ </ToolbarItem>
757
+ <ToolbarItem>
758
+ {(itemProps) => (
759
+ <Button
760
+ {...itemProps}
761
+ isPressed={sel_pos.height_val === "free"}
762
+ onClick={() => props.onHeightChange("free")}
763
+ text="free"
764
+ />
765
+ )}
766
+ </ToolbarItem>
767
+ </ToolbarGroup>
768
+ {sel_pos.height_val === "free" && (
769
+ <RangeControl
770
+ value={sel_pos.free_height}
771
+ label={__("Height", "block-collections")}
772
+ max={1800}
773
+ min={50}
774
+ step={10}
775
+ onChange={(newValue) => {
776
+ props.onFreeHeightChange(newValue);
777
+ }}
778
+ withInputField={true}
779
+ />
780
+ )}
781
+ </>
782
+ );
783
+ }
@@ -55,7 +55,7 @@ export const max_width_prm = (width, free_val) => {
55
55
  : width === "free"
56
56
  ? `width: 100%; max-width: ${free_val}px;`
57
57
  : width === "full"
58
- ? "width: 100%; max-width: 100%;"
58
+ ? "width: fit-content; max-width: 100%;"
59
59
  : " width: fit-content;";
60
60
  return ret_width_prm;
61
61
  };
@@ -68,6 +68,8 @@ export const width_prm = (width, free_val) => {
68
68
  ? " width: var(--wp--style--global--content-size);"
69
69
  : width === "free"
70
70
  ? ` width: ${free_val}px; `
71
+ : width === "full"
72
+ ? " width: 100%;"
71
73
  : " width: fit-content;";
72
74
  return ret_width_prm;
73
75
  };
@@ -267,33 +267,42 @@ export function useDuplicateBlockRemove(clientId, blockNames) {
267
267
 
268
268
  useEffect(() => {
269
269
  const prevInnerBlocks = prevInnerBlocksRef.current;
270
-
271
- // ブロックが挿入されているか確認(前回と比較)
272
- if (innerBlocks.length > prevInnerBlocks.length) {
273
- // 新しく挿入されたブロックを特定
274
- const newlyInsertedBlock = innerBlocks.find(
275
- (block) =>
276
- !prevInnerBlocks.some(
277
- (prevBlock) => prevBlock.clientId === block.clientId
278
- )
279
- );
280
-
281
- // 新しいブロックが blockNames に含まれている場合、削除
282
- if (newlyInsertedBlock && blockNames.includes(newlyInsertedBlock.name)) {
283
- removeBlock(newlyInsertedBlock.clientId);
284
-
285
- // 通知を作成
286
- createNotice(
287
- "error", // 通知のタイプ(エラー)
288
- __(
289
- "A new block cannot be inserted because a block has already been placed.",
290
- "block-collections"
291
- ), // メッセージ
292
- {
293
- type: "snackbar", // 通知のスタイル
294
- isDismissible: true, // 通知を閉じることができるか
295
- }
270
+ //先に保存したインナーブロックの中に対象となるブロックが存在しなければ何もしない
271
+ const result = prevInnerBlocks.some((block) =>
272
+ blockNames.includes(block.name)
273
+ );
274
+
275
+ if (result) {
276
+ // ブロックが挿入されているか確認(前回と比較)
277
+ if (innerBlocks.length > prevInnerBlocks.length) {
278
+ // 新しく挿入されたブロックを特定
279
+ const newlyInsertedBlock = innerBlocks.find(
280
+ (block) =>
281
+ !prevInnerBlocks.some(
282
+ (prevBlock) => prevBlock.clientId === block.clientId
283
+ )
296
284
  );
285
+
286
+ // 新しいブロックが blockNames に含まれている場合、削除
287
+ if (
288
+ newlyInsertedBlock &&
289
+ blockNames.includes(newlyInsertedBlock.name)
290
+ ) {
291
+ removeBlock(newlyInsertedBlock.clientId);
292
+
293
+ // 通知を作成
294
+ createNotice(
295
+ "error", // 通知のタイプ(エラー)
296
+ __(
297
+ "A new block cannot be inserted because a block has already been placed.",
298
+ "block-collections"
299
+ ), // メッセージ
300
+ {
301
+ type: "snackbar", // 通知のスタイル
302
+ isDismissible: true, // 通知を閉じることができるか
303
+ }
304
+ );
305
+ }
297
306
  }
298
307
  }
299
308
 
package/src/index.js CHANGED
@@ -54,7 +54,7 @@ export { default as DraggableBox, useDraggingMove } from "./DraggableBox";
54
54
  export { default as AnimationBlock, anime_comp } from "./AnimationBlock";
55
55
 
56
56
  //ブロックの配置を設定するコントロール
57
- export { default as BlockPlace } from "./BlockPlace";
57
+ export { default as BlockPlace, BlockWidth, BlockHeight } from "./BlockPlace";
58
58
  export { default as GridControls } from "./GridControls";
59
59
 
60
60
  //DOM要素の表示を反転させるコントロール