@secretstache/wordpress-gutenberg 0.1.2 → 0.2.1

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": "@secretstache/wordpress-gutenberg",
3
- "version": "0.1.2",
3
+ "version": "0.2.1",
4
4
  "description": "",
5
5
  "author": "Secret Stache",
6
6
  "license": "GPL-2.0-or-later",
@@ -12,6 +12,10 @@
12
12
  "node": ">=20"
13
13
  },
14
14
  "main": "build/index.js",
15
+ "module": "build/index.es.js",
16
+ "files": [
17
+ "build"
18
+ ],
15
19
  "type": "module",
16
20
  "scripts": {
17
21
  "build": "rollup -c",
@@ -30,16 +34,23 @@
30
34
  "@rollup/plugin-terser": "^0.4.4",
31
35
  "@wordpress/api-fetch": "^6.52.0",
32
36
  "@wordpress/block-editor": "^12.22.0",
37
+ "@wordpress/blocks": "^12.34.0",
33
38
  "@wordpress/components": "^27.2.0",
34
39
  "@wordpress/data": "^9.24.0",
35
40
  "@wordpress/element": "^5.32.0",
41
+ "@wordpress/hooks": "^3.57.0",
36
42
  "@wordpress/icons": "^9.45.0",
37
43
  "babel-core": "^6.26.3",
38
44
  "babel-loader": "^9.1.3",
45
+ "node-sass": "^9.0.0",
46
+ "postcss": "^8.4.38",
39
47
  "rollup": "^4.16.4",
40
- "rollup-plugin-peer-deps-external": "^2.2.4"
48
+ "rollup-plugin-peer-deps-external": "^2.2.4",
49
+ "rollup-plugin-postcss": "^4.0.2"
41
50
  },
42
51
  "dependencies": {
52
+ "react-select": "5.7.5",
53
+ "react-sortable-hoc": "2.0.0",
43
54
  "slugify": "^1.6.6"
44
55
  },
45
56
  "peerDependencies": {
@@ -49,6 +60,7 @@
49
60
  "@wordpress/data": "^9.24.0",
50
61
  "@wordpress/element": "^5.32.0",
51
62
  "@wordpress/icons": "^9.45.0",
63
+ "@wordpress/hooks": "^3.57.0",
52
64
  "react": "^18.0.0",
53
65
  "react-dom": "^18.0.0"
54
66
  },
@@ -57,8 +69,5 @@
57
69
  "not dead",
58
70
  "not ie <= 11",
59
71
  "not op_mini all"
60
- ],
61
- "publishConfig": {
62
- "access": "public"
63
- }
72
+ ]
64
73
  }
package/.editorconfig DELETED
@@ -1,18 +0,0 @@
1
- root = true
2
-
3
- [*]
4
- charset = utf-8
5
- end_of_line = lf
6
- insert_final_newline = true
7
- indent_style = space
8
- indent_size = 2
9
- trim_trailing_whitespace = true
10
-
11
- [*.md]
12
- trim_trailing_whitespace = false
13
-
14
- [*.js]
15
- indent_size = 4
16
-
17
- [*.scss]
18
- indent_size = 4
package/rollup.config.js DELETED
@@ -1,40 +0,0 @@
1
- import resolve from '@rollup/plugin-node-resolve';
2
- import commonjs from '@rollup/plugin-commonjs';
3
- import babel from '@rollup/plugin-babel';
4
- import terser from '@rollup/plugin-terser';
5
- import external from 'rollup-plugin-peer-deps-external';
6
-
7
- export default {
8
- input: './src/index.js',
9
- output: {
10
- dir: 'build',
11
- format: 'es',
12
- exports: 'named',
13
- sourcemap: true,
14
- },
15
- plugins: [
16
- external(),
17
- babel({
18
- babelHelpers: 'runtime',
19
- exclude: /node_modules/,
20
- presets: [
21
- '@babel/preset-env',
22
- ['@babel/preset-react', {
23
- runtime: 'automatic',
24
- }],
25
- ],
26
- plugins: [
27
- ['@babel/plugin-transform-runtime', {
28
- helpers: true,
29
- regenerator: true,
30
- }],
31
- ],
32
- extensions: ['.js', '.jsx'],
33
- }),
34
- commonjs({
35
- extensions: ['.js', '.jsx'],
36
- }),
37
- resolve({ extensions: ['.js', '.jsx'] }),
38
- terser(),
39
- ],
40
- };
@@ -1,16 +0,0 @@
1
- import { ColorPalette } from '@wordpress/components';
2
- import { useThemeColors, useColorChange } from '../utils/index';
3
-
4
- export const ColorPaletteControl = ({ allowedColors, colorAttribute, attributeName, setAttributes }) => {
5
- const colors = useThemeColors(allowedColors);
6
- const onColorChange = useColorChange(colors, setAttributes);
7
-
8
- return (
9
- <ColorPalette
10
- colors={colors}
11
- value={colorAttribute?.value}
12
- disableCustomColors={true}
13
- onChange={(colorValue) => onColorChange(colorValue, attributeName)}
14
- />
15
- );
16
- };
@@ -1,73 +0,0 @@
1
- import {
2
- MediaPlaceholder,
3
- MediaUpload,
4
- MediaUploadCheck,
5
- } from '@wordpress/block-editor';
6
- import { Button, Icon } from '@wordpress/components';
7
- import { edit as editIcon, trash as trashIcon } from '@wordpress/icons';
8
-
9
- export const IconPicker = ({ imageId, imageUrl, imageAlt, svgCode, onSelect, onRemove }) => {
10
- const hasImage = imageId && imageUrl;
11
- const isSvg = hasImage && svgCode;
12
-
13
- return (
14
- <MediaUploadCheck>
15
- <MediaUpload
16
- onSelect={onSelect}
17
- allowedTypes={['image']}
18
- value={imageId}
19
- render={({ open }) => {
20
- return hasImage ? (
21
- <div className="bc-image-wrapper">
22
- {hasImage && (
23
- isSvg ? (
24
- <div
25
- className="svg-container"
26
- dangerouslySetInnerHTML={{ __html: svgCode }}
27
- />
28
- ) : (
29
- <img src={imageUrl} alt={imageAlt || 'icon'} />
30
- )
31
- )}
32
-
33
- <div className="bc-image-wrapper__actions">
34
- <Button
35
- className="bc-image-wrapper__btn bc-image-wrapper__replace-btn"
36
- type="button"
37
- onClick={open}
38
- >
39
- <Icon
40
- icon={editIcon}
41
- size={20}
42
- className="bc-image-wrapper__btn-icon"
43
- />
44
- </Button>
45
-
46
- <Button
47
- className="bc-image-wrapper__btn bc-image-wrapper__remove-btn"
48
- type="button"
49
- onClick={onRemove}
50
- >
51
- <Icon
52
- icon={trashIcon}
53
- size={20}
54
- className="bc-image-wrapper__btn-icon"
55
- />
56
- </Button>
57
- </div>
58
-
59
- <div className="bc-image-wrapper__overlay" />
60
- </div>
61
- ) : (
62
- <MediaPlaceholder
63
- icon="format-image"
64
- onSelect={onSelect}
65
- allowedTypes={['image', 'image/svg+xml']}
66
- labels={{ title: 'Icon Image' }}
67
- />
68
- );
69
- }}
70
- />
71
- </MediaUploadCheck>
72
- );
73
- };
@@ -1,59 +0,0 @@
1
- import { MediaUpload, MediaUploadCheck, MediaPlaceholder } from '@wordpress/block-editor';
2
- import { Button } from '@wordpress/components';
3
-
4
- export const ImageActions = ({
5
- imageId,
6
- imageUrl,
7
- imageAlt,
8
- placeholder = false,
9
- onSelectImage,
10
- onRemoveImage,
11
- className = '',
12
- }) => {
13
- const hasImage = imageId && imageUrl;
14
-
15
- return (
16
- <MediaUploadCheck>
17
- <MediaUpload
18
- onSelect={onSelectImage}
19
- allowedTypes={['image']}
20
- value={imageId}
21
- render={({ open }) => {
22
- return hasImage ? (
23
- <div className={`bc-image-wrapper ${className}`}>
24
- <img src={imageUrl} alt={imageAlt} onClick={open} />
25
- <div className="bc-image-wrapper__actions">
26
- <Button
27
- className="bc-image-wrapper__btn bc-image-wrapper__replace-btn"
28
- type="button"
29
- onClick={open}
30
- >
31
- Replace
32
- </Button>
33
- <Button
34
- className="bc-image-wrapper__btn bc-image-wrapper__remove-btn"
35
- type="button"
36
- onClick={onRemoveImage}
37
- >
38
- Remove
39
- </Button>
40
- </div>
41
- <div className="bc-image-wrapper__overlay" />
42
- </div>
43
- ) : placeholder ? (
44
- <MediaPlaceholder
45
- className="media-placeholder"
46
- icon="format-image"
47
- onSelect={onSelectImage}
48
- allowedTypes={['image']}
49
- labels={{
50
- title: 'Image',
51
- instructions: 'Upload an image file or pick one from your media library.',
52
- }}
53
- />
54
- ) : null;
55
- }}
56
- />
57
- </MediaUploadCheck>
58
- );
59
- };
@@ -1,31 +0,0 @@
1
- import { BaseControl, CheckboxControl } from '@wordpress/components';
2
- import { URLInput } from '@wordpress/block-editor';
3
- import { useLinkChange } from '../utils/index';
4
-
5
- // TODO: refactor props names
6
- export const LinkControl = ({
7
- buttonSource,
8
- isButtonOpenInNewTab,
9
- setAttributes,
10
- }) => {
11
- const onLinkChange = useLinkChange(setAttributes);
12
-
13
- return (
14
- <>
15
- <BaseControl label="Source">
16
- <URLInput
17
- className="bc-url-input"
18
- value={buttonSource}
19
- // TODO: this doesn't work if the attribute has a different name
20
- onChange={(newUrl) => onLinkChange(newUrl, 'buttonSource')}
21
- />
22
- </BaseControl>
23
- <CheckboxControl
24
- checked={isButtonOpenInNewTab}
25
- label="Open in a new tab"
26
- onChange={(newIsOpenInNewTab) =>
27
- onLinkChange(newIsOpenInNewTab, 'isButtonOpenInNewTab')}
28
- />
29
- </>
30
- );
31
- };
@@ -1,130 +0,0 @@
1
- import { Button } from '@wordpress/components';
2
- import { MediaUpload, MediaUploadCheck } from '@wordpress/block-editor';
3
-
4
- export const BCImageRenderer = ({
5
- imageId,
6
- imageUrl,
7
- onImageClick,
8
- onRemoveClick,
9
- onSelectClick,
10
- }) => {
11
- return imageId && imageUrl ? (
12
- <>
13
- <div className="bc-selected-media-wrapper">
14
- <img
15
- src={imageUrl}
16
- className="bc-selected-media bc-selected-media--image"
17
- alt="Selected Image"
18
- onClick={onImageClick}
19
- />
20
- </div>
21
-
22
- <Button
23
- className="bc-remove-btn"
24
- onClick={onRemoveClick}
25
- isSecondary
26
- isDestructive
27
- >
28
- Remove Image
29
- </Button>
30
- </>
31
- ) : (
32
- <Button
33
- variant="secondary"
34
- onClick={onSelectClick}
35
- className="bc-select-btn"
36
- >
37
- Select Image
38
- </Button>
39
- );
40
- };
41
-
42
- export const BCVideoRenderer = ({
43
- videoId,
44
- videoUrl,
45
- onRemoveClick,
46
- onSelectClick,
47
- }) => {
48
- return videoId && videoUrl ? (
49
- <>
50
- <div className="bc-selected-media-wrapper">
51
- <video src={videoUrl} className="bc-selected-media bc-selected-media--video" controls />
52
- </div>
53
-
54
- <Button
55
- className="bc-remove-btn"
56
- onClick={onRemoveClick}
57
- isSecondary
58
- isDestructive
59
- >
60
- Remove Video
61
- </Button>
62
- </>
63
- ) : (
64
- <Button
65
- variant="secondary"
66
- onClick={onSelectClick}
67
- className="bc-select-btn"
68
- >
69
- Select Video
70
- </Button>
71
- );
72
- };
73
-
74
- const MEDIA_TYPES = {
75
- IMAGE: 'image',
76
- VIDEO: 'video',
77
- };
78
-
79
- export const BCMediaPicker = ({
80
- mediaId,
81
- mediaUrl,
82
- onSelect,
83
- onRemove,
84
- type = MEDIA_TYPES.IMAGE,
85
- ...other
86
- }) => {
87
- if (type === MEDIA_TYPES.IMAGE) {
88
- return (
89
- <MediaUploadCheck>
90
- <MediaUpload
91
- onSelect={onSelect}
92
- allowedTypes={['image', 'image/svg+xml']}
93
- accept="image/*"
94
- value={mediaId}
95
- render={({ open }) => (
96
- <BCImageRenderer
97
- imageId={mediaId}
98
- imageUrl={mediaUrl}
99
- onImageClick={open}
100
- onSelectClick={open}
101
- onRemoveClick={onRemove}
102
- />
103
- )}
104
- { ...other }
105
- />
106
- </MediaUploadCheck>
107
- );
108
- } else if (type === MEDIA_TYPES.VIDEO) {
109
- return (
110
- <MediaUploadCheck>
111
- <MediaUpload
112
- onSelect={onSelect}
113
- allowedTypes={['video']}
114
- value={mediaId}
115
- render={({ open }) => (
116
- <BCVideoRenderer
117
- videoId={mediaId}
118
- videoUrl={mediaUrl}
119
- onSelectClick={open}
120
- onRemoveClick={onRemove}
121
- />
122
- )}
123
- { ...other }
124
- />
125
- </MediaUploadCheck>
126
- );
127
- } else {
128
- throw new Error('Unrecognized media type.');
129
- }
130
- };
@@ -1,23 +0,0 @@
1
- import { ToggleControl } from '@wordpress/components';
2
-
3
- export const PreviewToggle = ({ attributes, setAttributes, disabled }) => {
4
- const { isPreview } = attributes;
5
-
6
- // TODO: useState instead of attributes
7
- const handlePreviewChange = () => {
8
- setAttributes({ isPreview: !isPreview });
9
- };
10
-
11
- // TODO: <BlockControls> will be duplicated if the parent block has the another one <BlockControls>
12
- return (
13
- <>
14
- <ToggleControl
15
- label="Enable Preview"
16
- help="Please check this option to see how the block will actually look and behave on the frontend."
17
- checked={isPreview}
18
- onChange={handlePreviewChange}
19
- disabled={disabled}
20
- />
21
- </>
22
- );
23
- };
package/src/index.js DELETED
@@ -1,8 +0,0 @@
1
- export { ColorPaletteControl } from './components/ColorPaletteControl';
2
- export { IconPicker } from './components/IconPicker';
3
- export { ImageActions } from './components/ImageActions';
4
- export { LinkControl } from './components/LinkControl';
5
- export { BCImageRenderer, BCVideoRenderer, BCMediaPicker } from './components/MediaPicker';
6
- export { PreviewToggle } from './components/PreviewToggle';
7
-
8
- export * from './utils';