129 | );
130 | }
131 |
--------------------------------------------------------------------------------
/readme.txt:
--------------------------------------------------------------------------------
1 | === Block Pattern Explorer ===
2 | Author URI: https://wwww.nickdiego.com
3 | Contributors: ndiego, bgardner, wpengine
4 | Tags: patterns, blocks, block patterns, starter content
5 | Requires at least: 5.8
6 | Tested up to: 5.9
7 | Requires PHP: 7.1
8 | Stable tag: 0.3.0
9 | License: GPLv2 or later
10 | License URI: https://www.gnu.org/licenses/gpl-2.0.html
11 |
12 | An experimental plugin to preview and insert block patterns in the Block Editor.
13 |
14 | == Description ==
15 |
16 | An experimental plugin to preview and insert block patterns in the Block Editor (Gutenberg).
17 |
18 | Please note that no block patterns are included with this plugin. Patterns must be provided by your theme or another plugin. You can also use the patterns provided by WordPress if enabled by your theme.
19 |
20 | Furthermore, this plugin should be used in conjunction with the [Gutenberg plugin](https://wordpress.org/plugins/gutenberg/) until WordPress 5.9 is officially released on January 25, 2022.
21 |
22 | === Mission ===
23 |
24 | The Block Pattern Explorer is heavily influenced by the work currently being done in the Gutenberg [GitHub repository](https://github.com/WordPress/gutenberg) on pattern previews.
25 |
26 | The purpose of this project is to isolate the pattern explorer into a standalone plugin that WordPress users/developers can interact with immediately, provide feedback on, and begin implementing into their own websites. Ideally, this initiative will also help inform the direction of core development.
27 |
28 | Once the pattern explorer is fully integrated into WordPress proper, this project will be sunsetted in favor of the core offering.
29 |
30 | == Screenshots ==
31 |
32 | 1. Inserting a pattern from the upcoming Twenty Twenty-Two theme into the Block Editor using the block pattern explorer.
33 |
34 | === Stay Connected ===
35 |
36 | Stay up-to-date on the Block Pattern Explorer, and Gutenberg development, using the links below. The plugin is also being built transparently on GitHub, so give it a star and follow along! 😉
37 |
38 | * [Follow on Twitter](https://twitter.com/nickmdiego)
39 | * [View on GitHub](https://github.com/wpengine/block-pattern-explorer)
40 | * [Gutenberg plugin](https://wordpress.org/plugins/gutenberg/)
41 | * [Gutenberg on GitHub](https://github.com/WordPress/gutenberg)
42 |
43 | == Installation ==
44 |
45 | 1. You have a couple options:
46 | * Go to Plugins → Add New and search for "Block Pattern Explorer". Once found, click "Install".
47 | * Download the Block Pattern Explorer from WordPress.org and make sure the folder is zipped. Then upload via Plugins → Add New → Upload.
48 | 2. Activate the plugin through the 'Plugins' menu in WordPress.
49 | 3. Once activated, navigate to the Block Editor and you will see the "Insert Pattern" button in header toolbar. See the plugin screenshots for reference.
50 |
51 | == Changelog ==
52 |
53 | = 0.3.0 - 2022-01-13 =
54 |
55 | **Changed**
56 |
57 | * Replaced custom search component with core version.
58 | * Updated modal styling to match core pattern explorer.
59 | * Updated screenshots.
60 |
61 | **Fixed**
62 |
63 | * Fixed API bug causing the pattern explorer to be inaccessible on themes that do not utilize pattern category types.
64 | * Fixed linting and code quality errors.
65 |
66 | = 0.2.1 - 2021-11-23 =
67 |
68 | **Changed**
69 |
70 | * The button used to launch the Pattern Explorer is now disabled while pattern category types are being retrieved from the REST API.
71 | * Updated tooltip on the button used to launch the Pattern Explorer.
72 |
73 | = 0.2.0 - 2021-11-22 =
74 |
75 | **Added**
76 |
77 | * Added support for the experimental block pattern category types.
78 |
79 | = 0.1.0 - 2021-11-09 =
80 |
81 | Initial release! 🎉
82 |
--------------------------------------------------------------------------------
/src/sidebar.js:
--------------------------------------------------------------------------------
1 | /**
2 | * WordPress dependencies
3 | */
4 | import { __ } from '@wordpress/i18n';
5 | import {
6 | MenuGroup,
7 | MenuItem,
8 | SearchControl,
9 | VisuallyHidden,
10 | } from '@wordpress/components';
11 | import { useMemo } from '@wordpress/element';
12 |
13 | /**
14 | * Renders the block pattern category sidebar control.
15 | *
16 | * @since 0.1.0
17 | * @param {Object} props All the props passed to this function
18 | * @return {string} Return the rendered JSX
19 | */
20 | export default function PatternExplorerSidebar( props ) {
21 | const {
22 | patternCategories,
23 | patternCategoryTypes,
24 | selectedCategory,
25 | setSelectedCategory,
26 | searchValue,
27 | setSearchValue,
28 | } = props;
29 |
30 | function onClickCategory( category ) {
31 | setSelectedCategory( category );
32 | setSearchValue( '' );
33 | }
34 |
35 | const registeredCategoryTypes = useMemo(
36 | () =>
37 | patternCategoryTypes.map(
38 | ( patternCategoryType ) => patternCategoryType.name
39 | ),
40 | [ patternCategoryTypes ]
41 | );
42 |
43 | const baseClassName = 'block-pattern-explorer__sidebar';
44 |
45 | return (
46 |
47 |
48 |
53 |
54 | { patternCategoryTypes.map( ( categoryType ) => {
55 | const categoriesOfType = patternCategories.filter(
56 | ( category ) => {
57 | // If the selected category is uncategorized, return all
58 | // pattern categories without assigned category types.
59 | if ( categoryType.name === 'uncategorized' ) {
60 | return (
61 | ! category?.categoryTypes ||
62 | category.categoryTypes.every(
63 | ( type ) =>
64 | ! registeredCategoryTypes.includes(
65 | type
66 | )
67 | )
68 | );
69 | }
70 | return category.categoryTypes?.includes(
71 | categoryType.name
72 | );
73 | }
74 | );
75 |
76 | // If there are no categories in the current type, bail.
77 | if ( ! categoriesOfType.length ) {
78 | return null;
79 | }
80 |
81 | return (
82 |
149 | );
150 | }
151 |
--------------------------------------------------------------------------------
/src/core-hooks/use-insertion-point.js:
--------------------------------------------------------------------------------
1 | /**
2 | * External dependencies
3 | */
4 | import { castArray } from 'lodash';
5 |
6 | /**
7 | * WordPress dependencies
8 | */
9 | import { useDispatch, useSelect } from '@wordpress/data';
10 | import { isUnmodifiedDefaultBlock } from '@wordpress/blocks';
11 | import { _n, sprintf } from '@wordpress/i18n';
12 | import { speak } from '@wordpress/a11y';
13 | import { useCallback } from '@wordpress/element';
14 | import { store as blockEditorStore } from '@wordpress/block-editor';
15 |
16 | /**
17 | * @typedef WPInserterConfig
18 | * @property {string=} rootClientId If set, insertion will be into the block with this ID.
19 | * @property {number=} insertionIndex If set, insertion will be into this explicit position.
20 | * @property {string=} clientId If set, insertion will be after the block with this ID.
21 | * @property {boolean=} isAppender Whether the inserter is an appender or not.
22 | * @property {Function=} onSelect Called after insertion.
23 | */
24 |
25 | /**
26 | * Returns the insertion point state given the inserter config.
27 | *
28 | * @param {WPInserterConfig} config Inserter Config.
29 | * @return {Array} Insertion Point State (rootClientID, onInsertBlocks and onToggle).
30 | */
31 | export default function useInsertionPoint( {
32 | rootClientId = '',
33 | insertionIndex,
34 | clientId,
35 | isAppender,
36 | onSelect,
37 | shouldFocusBlock = true,
38 | } ) {
39 | const { getSelectedBlock } = useSelect( blockEditorStore );
40 | const { destinationRootClientId, destinationIndex } = useSelect(
41 | ( select ) => {
42 | const {
43 | getSelectedBlockClientId,
44 | getBlockRootClientId,
45 | getBlockIndex,
46 | getBlockOrder,
47 | } = select( blockEditorStore );
48 | const selectedBlockClientId = getSelectedBlockClientId();
49 |
50 | let _destinationRootClientId = rootClientId;
51 | let _destinationIndex;
52 |
53 | if ( insertionIndex !== undefined ) {
54 | // Insert into a specific index.
55 | _destinationIndex = insertionIndex;
56 | } else if ( clientId ) {
57 | // Insert after a specific client ID.
58 | _destinationIndex = getBlockIndex(
59 | clientId,
60 | _destinationRootClientId
61 | );
62 | } else if ( ! isAppender && selectedBlockClientId ) {
63 | _destinationRootClientId = getBlockRootClientId(
64 | selectedBlockClientId
65 | );
66 | _destinationIndex =
67 | getBlockIndex(
68 | selectedBlockClientId,
69 | _destinationRootClientId
70 | ) + 1;
71 | } else {
72 | // Insert at the end of the list.
73 | _destinationIndex = getBlockOrder( _destinationRootClientId )
74 | .length;
75 | }
76 |
77 | return {
78 | destinationRootClientId: _destinationRootClientId,
79 | destinationIndex: _destinationIndex,
80 | };
81 | },
82 | [ rootClientId, insertionIndex, clientId, isAppender ]
83 | );
84 |
85 | const {
86 | replaceBlocks,
87 | insertBlocks,
88 | showInsertionPoint,
89 | hideInsertionPoint,
90 | } = useDispatch( blockEditorStore );
91 |
92 | const onInsertBlocks = useCallback(
93 | ( blocks, meta, shouldForceFocusBlock = false ) => {
94 | const selectedBlock = getSelectedBlock();
95 |
96 | if (
97 | ! isAppender &&
98 | selectedBlock &&
99 | isUnmodifiedDefaultBlock( selectedBlock )
100 | ) {
101 | replaceBlocks(
102 | selectedBlock.clientId,
103 | blocks,
104 | null,
105 | shouldFocusBlock || shouldForceFocusBlock ? 0 : null,
106 | meta
107 | );
108 | } else {
109 | insertBlocks(
110 | blocks,
111 | destinationIndex,
112 | destinationRootClientId,
113 | true,
114 | shouldFocusBlock || shouldForceFocusBlock ? 0 : null,
115 | meta
116 | );
117 | }
118 | const message = sprintf(
119 | // translators: %d: the name of the block that has been added
120 | _n(
121 | '%d block added.',
122 | '%d blocks added.',
123 | castArray( blocks ).length
124 | ),
125 | castArray( blocks ).length
126 | );
127 | speak( message );
128 |
129 | if ( onSelect ) {
130 | onSelect();
131 | }
132 | },
133 | [
134 | isAppender,
135 | getSelectedBlock,
136 | replaceBlocks,
137 | insertBlocks,
138 | destinationRootClientId,
139 | destinationIndex,
140 | onSelect,
141 | shouldFocusBlock,
142 | ]
143 | );
144 |
145 | const onToggleInsertionPoint = useCallback(
146 | ( show ) => {
147 | if ( show ) {
148 | showInsertionPoint( destinationRootClientId, destinationIndex );
149 | } else {
150 | hideInsertionPoint();
151 | }
152 | },
153 | [
154 | showInsertionPoint,
155 | hideInsertionPoint,
156 | destinationRootClientId,
157 | destinationIndex,
158 | ]
159 | );
160 |
161 | return [ destinationRootClientId, onInsertBlocks, onToggleInsertionPoint ];
162 | }
163 |
--------------------------------------------------------------------------------
/includes/class-bpe-block-pattern-category-types-registry.php:
--------------------------------------------------------------------------------
1 | registered_category_types[ $category_type_name ] = array_merge(
54 | array( 'name' => $category_type_name ),
55 | $category_type_properties
56 | );
57 |
58 | return true;
59 | }
60 |
61 | /**
62 | * Unregisters a pattern category type.
63 | *
64 | * @since 0.2.0
65 | *
66 | * @param string $category_type_name Pattern category type name including namespace.
67 | * @return bool True if the pattern category type was unregistered with success and false otherwise.
68 | */
69 | public function unregister( $category_type_name ) {
70 | if ( ! $this->is_registered( $category_type_name ) ) {
71 | _doing_it_wrong(
72 | __METHOD__,
73 | esc_html(
74 | sprintf(
75 | /* translators: %s: Block pattern categpry type name. */
76 | __(
77 | 'Block pattern category type "%s" not found.',
78 | 'block-pattern-explorer'
79 | ),
80 | $category_type_name
81 | )
82 | ),
83 | '0.2.0'
84 | );
85 | return false;
86 | }
87 |
88 | unset( $this->registered_category_types[ $category_type_name ] );
89 |
90 | return true;
91 | }
92 |
93 | /**
94 | * Retrieves an array containing the properties of a registered pattern category type.
95 | *
96 | * @since 0.2.0
97 | *
98 | * @param string $category_type_name Pattern category type name including namespace.
99 | * @return array Registered pattern category type properties.
100 | */
101 | public function get_registered( $category_type_name ) {
102 | if ( ! $this->is_registered( $category_type_name ) ) {
103 | return null;
104 | }
105 |
106 | return $this->registered_category_types[ $category_type_name ];
107 | }
108 |
109 | /**
110 | * Retrieves all registered pattern category types.
111 | *
112 | * @since 0.2.0
113 | *
114 | * @return array Array of arrays containing the registered pattern category types.
115 | */
116 | public function get_all_registered() {
117 | return array_values( $this->registered_category_types );
118 | }
119 |
120 | /**
121 | * Checks if a pattern category type is registered.
122 | *
123 | * @since 0.2.0
124 | *
125 | * @param string $category_type_name Pattern category name including namespace.
126 | * @return bool True if the pattern category type is registered, false otherwise.
127 | */
128 | public function is_registered( $category_type_name ) {
129 | return isset( $this->registered_category_types[ $category_type_name ] );
130 | }
131 |
132 | /**
133 | * Utility method to retrieve the main instance of the class.
134 | *
135 | * The instance will be created if it does not exist yet.
136 | *
137 | * @since 0.2.0
138 | *
139 | * @return BPE_Block_Pattern_Category_Types_Registry The main instance.
140 | */
141 | public static function get_instance() {
142 | if ( null === self::$instance ) {
143 | self::$instance = new self();
144 | }
145 |
146 | return self::$instance;
147 | }
148 | }
149 |
150 | /**
151 | * Registers a new pattern category type.
152 | *
153 | * Note: This function is purposefully not namespaced/prefixed. It is designed
154 | * to emulate a similar function that will be proposed for inclusion in core.
155 | *
156 | * @since 0.2.0
157 | *
158 | * @param string $category_type_name Pattern category type name including namespace.
159 | * @param array $category_type_properties Array containing the properties of the category type.
160 | * @return bool True if the pattern category type was registered with success and false otherwise.
161 | */
162 | // phpcs:ignore
163 | function register_block_pattern_category_type( $category_type_name, $category_type_properties ) {
164 | return BPE_Block_Pattern_Category_Types_Registry::get_instance()->register( $category_type_name, $category_type_properties );
165 | }
166 |
167 | /**
168 | * Unregisters a pattern category type.
169 | *
170 | * Note: This function is purposefully not namespaced/prefixed. It is designed
171 | * to emulate a similar function that will be proposed for inclusion in core.
172 | *
173 | * @since 0.2.0
174 | *
175 | * @param string $category_type_name Pattern category type name including namespace.
176 | * @return bool True if the pattern category type was unregistered with success and false otherwise.
177 | */
178 | // phpcs:ignore
179 | function unregister_block_pattern_category_type( $category_type_name ) {
180 | return BPE_Block_Pattern_Category_Types_Registry::get_instance()->unregister( $category_type_name );
181 | }
182 |
--------------------------------------------------------------------------------
/src/style.scss:
--------------------------------------------------------------------------------
1 | .block-pattern-explorer__modal {
2 | .components-modal__content {
3 | flex: 1; /* Will likely not be needed in WP 5.9 */
4 | overflow: auto;
5 | padding: 0;
6 |
7 | &:before {
8 | margin-bottom: 0;
9 | }
10 | }
11 | }
12 |
13 | .block-pattern-explorer {
14 | align-items: stretch;
15 | display: flex;
16 | height: 100%;
17 |
18 | &.is-error {
19 | display: block;
20 | margin: 24px 32px;
21 | }
22 |
23 | .components-notice {
24 | margin: 0;
25 |
26 | .components-notice__content {
27 | margin-top: 8px;
28 | margin-bottom: 8px;
29 | }
30 |
31 | &.is-error {
32 | background-color: #f8ebea;
33 | }
34 |
35 | p {
36 | margin: 12px 0 0;
37 |
38 | &:first-child {
39 | margin-top: 0;
40 | }
41 | }
42 | }
43 |
44 | .block-pattern-explorer__preview {
45 | display: flex;
46 | flex-direction: column;
47 | flex-shrink: 0;
48 | overflow: auto;
49 | padding: 32px 32px 100px;
50 | width: calc(100% - 281px);
51 |
52 | .block-editor-inserter__no-results {
53 | align-items: center;
54 | display: flex;
55 | height: 100%;
56 | justify-content: center;
57 | }
58 | }
59 |
60 | .block-pattern-explorer__preview-header {
61 | align-items: center;
62 | display: inline-flex;
63 | justify-content: space-between;
64 | margin-bottom: 2rem;
65 |
66 | &__search-results {
67 | display: inline-flex;
68 |
69 | .components-spinner {
70 | margin: 0 12px 0 0;
71 | }
72 | }
73 |
74 | &__controls {
75 | display: inline-flex;
76 |
77 | .viewport-toggle {
78 | margin-right: 6px;
79 | }
80 |
81 | &>button {
82 | margin-left: 6px;
83 | }
84 | }
85 |
86 | /* Temp fix for DropdownMenu component. */
87 | .components-popover__content {
88 | margin-top: -50px;
89 | margin-right: 48px !important;
90 | }
91 | }
92 |
93 | .block-pattern-explorer__preview-pattern-list {
94 | width: 100%;
95 |
96 | &>div {
97 | margin-bottom: 2rem;
98 | }
99 |
100 | &.preview-tablet {
101 | &>div {
102 | max-width: 790px;
103 | margin: 0 auto 4rem;
104 | }
105 | }
106 |
107 | &.preview-mobile {
108 | &>div {
109 | max-width: 358px;
110 | margin: 0 auto 4rem;
111 | }
112 | }
113 |
114 | &.is-grid {
115 | display: grid;
116 | grid-gap: 32px;
117 | grid-template: inherit;
118 | grid-template-columns: repeat(1,1fr);
119 |
120 | @media (min-width: 1080px) {
121 | grid-template-columns: repeat(2,1fr);
122 | }
123 |
124 | @media ( min-width: 1440px ) {
125 | grid-template-columns: repeat(3,1fr);
126 | }
127 |
128 | &>div {
129 | margin-bottom: 0;
130 | }
131 |
132 | &.preview-tablet,
133 | &.preview-mobile {
134 | &>div {
135 | margin: 0;
136 | }
137 | }
138 |
139 | .block-editor-block-preview__container {
140 | max-height: 400px;
141 | overflow: scroll;
142 | }
143 | }
144 |
145 | &.no-results {
146 | align-items: center;
147 | display: flex;
148 | height: 100%;
149 | justify-content: center;
150 | }
151 |
152 | &__item {
153 | border: 1px solid #dddddd;
154 | border-radius: 2px;
155 | display: flex;
156 | flex-direction: column;
157 | justify-content: space-between;
158 | position: relative;
159 | transition: all .05s ease-in-out;
160 | width: 100%;
161 |
162 | &:hover {
163 | border-color: var(--wp-admin-theme-color);
164 | }
165 |
166 | &-preview {
167 | align-items: center;
168 | background: #f0f0f0;
169 | cursor: pointer;
170 | display: flex;
171 | flex-grow: 1;
172 | min-height: 200px;
173 |
174 | img {
175 | width: 100%;
176 | }
177 | }
178 |
179 | &-actions {
180 | align-items: center;
181 | background: #fff;
182 | border-top: 1px solid #ddd;
183 | display: flex;
184 | justify-content: space-between;
185 | padding: 10px;
186 | }
187 |
188 | &-title {
189 | font-size: 12px;
190 | padding: 6px;
191 | text-align: center;
192 | }
193 | }
194 | }
195 |
196 | .block-pattern-explorer__preview-loading {
197 | display: flex;
198 | justify-content: center;
199 | margin: 64px 0;
200 | width: 100%;
201 | }
202 |
203 | .block-pattern-explorer__sidebar {
204 | border-right: 1px solid #ddd;
205 | display: flex;
206 | flex-direction: column;
207 | flex-shrink: 0;
208 | overflow-y: scroll;
209 | padding: 32px;
210 | width: 280px;
211 |
212 | &__search {
213 | margin-bottom: 16px;
214 |
215 | .components-base-control__field {
216 | margin-bottom: 0;
217 | }
218 | }
219 |
220 | &__category-type {
221 | &__title {
222 | color: #757575;
223 | font-size: 11px;
224 | font-weight: 500;
225 | margin: 0;
226 | padding: 16px 12px 0;
227 | text-transform: uppercase;
228 | }
229 |
230 | &__categories {
231 | padding: 16px 0;
232 | }
233 | }
234 | }
235 | }
236 |
--------------------------------------------------------------------------------
/src/index.js:
--------------------------------------------------------------------------------
1 | /**
2 | * External dependencies.
3 | */
4 | import { isEmpty } from 'lodash';
5 |
6 | /**
7 | * WordPress dependencies.
8 | */
9 | import { __ } from '@wordpress/i18n';
10 | import { render, useState, useMemo, useCallback } from '@wordpress/element';
11 | import { dispatch, subscribe } from '@wordpress/data';
12 | import { Button, Modal } from '@wordpress/components';
13 | import { layout } from '@wordpress/icons';
14 |
15 | /**
16 | * Internal dependencies
17 | */
18 | import PatternExplorer from './pattern-explorer';
19 | import usePatternsState from './core-hooks/use-patterns-state';
20 |
21 | /**
22 | * Render the header toolbar button and the accompanying pattern explorer modal.
23 | *
24 | * @since 0.1.0
25 | * @return {string} Return the rendered JSX for the Pattern Explorer Button
26 | */
27 | function HeaderToolbarButton() {
28 | const [ isModalOpen, setIsModalOpen ] = useState( false );
29 | const [ allPatterns, allCategories, allCategoryTypes ] = usePatternsState();
30 |
31 | const fetchedCategoryTypes =
32 | allCategoryTypes === 'fetching' ? [] : allCategoryTypes;
33 |
34 | // Check if a pattern has an assigned pattern category.
35 | const hasRegisteredCategory = useCallback(
36 | ( pattern ) => {
37 | if ( ! pattern.categories || ! pattern.categories.length ) {
38 | return false;
39 | }
40 |
41 | return pattern.categories.some( ( cat ) =>
42 | allCategories.some( ( category ) => category.name === cat )
43 | );
44 | },
45 | [ allCategories ]
46 | );
47 |
48 | // Check if a pattern category has an assigned pattern category type.
49 | const hasRegisteredCategoryType = useCallback(
50 | ( category ) => {
51 | if ( ! category.categoryTypes || ! category.categoryTypes.length ) {
52 | return false;
53 | }
54 |
55 | return category.categoryTypes.some( ( type ) =>
56 | fetchedCategoryTypes.some(
57 | ( categoryType ) => categoryType.name === type
58 | )
59 | );
60 | },
61 | [ fetchedCategoryTypes ]
62 | );
63 |
64 | // Remove any categories without patterns.
65 | const populatedCategories = useMemo( () => {
66 | const categories = allCategories
67 | .filter( ( category ) =>
68 | allPatterns.some( ( pattern ) =>
69 | pattern.categories?.includes( category.name )
70 | )
71 | )
72 | .sort( ( { name: currentName }, { name: nextName } ) => {
73 | if ( ! [ currentName, nextName ].includes( 'featured' ) ) {
74 | return 0;
75 | }
76 | return currentName === 'featured' ? -1 : 1;
77 | } );
78 |
79 | // If there are patterns without categories, create Uncategorized.
80 | if (
81 | allPatterns.some(
82 | ( pattern ) => ! hasRegisteredCategory( pattern )
83 | ) &&
84 | ! categories.find(
85 | ( category ) => category.name === 'uncategorized'
86 | )
87 | ) {
88 | categories.push( {
89 | name: 'uncategorized',
90 | label: __( 'Uncategorized', 'block-pattern-explorer' ),
91 | } );
92 | }
93 |
94 | return categories;
95 | }, [ allPatterns, allCategories ] );
96 |
97 | // Remove any pattern category type without populated pattern categories.
98 | const populatedCategoryTypes = useMemo( () => {
99 | const categoryTypes = fetchedCategoryTypes.filter( ( type ) =>
100 | populatedCategories.some( ( category ) =>
101 | category.categoryTypes?.includes( type.name )
102 | )
103 | );
104 |
105 | // If there are categories without types, create the Uncategorized type.
106 | if (
107 | populatedCategories.some(
108 | ( category ) => ! hasRegisteredCategoryType( category )
109 | ) &&
110 | ! categoryTypes.find( ( type ) => type.name === 'uncategorized' )
111 | ) {
112 | categoryTypes.unshift( {
113 | name: 'uncategorized',
114 | label: __( 'Uncategorized', 'block-pattern-explorer' ),
115 | hideLabelFromVision: true,
116 | } );
117 | }
118 |
119 | return categoryTypes;
120 | }, [ populatedCategories, fetchedCategoryTypes ] );
121 |
122 | // Could expand on this in the future, i.e. allow for a configurable
123 | // initial category. For now the initial category is the first category in
124 | // the first category type.
125 | const initialCategory = populatedCategories.filter( ( category ) => {
126 | // If the first category type is 'uncategorized', filter all categories
127 | // without types and all categories with the type 'uncategorized'.
128 | if ( populatedCategoryTypes[ 0 ].name === 'uncategorized' ) {
129 | return (
130 | ! category.categoryTypes ||
131 | ! category.categoryTypes.length ||
132 | category.categoryTypes?.includes( 'uncategorized' )
133 | );
134 | }
135 |
136 | // If the first type is not 'uncategorized', filter all the categories in the
137 | // first type.
138 | return category.categoryTypes?.includes(
139 | populatedCategoryTypes[ 0 ].name
140 | );
141 | } )[ 0 ];
142 |
143 | // If there are no patterns, do not display the pattern explorer button.
144 | if ( isEmpty( allPatterns ) ) {
145 | return null;
146 | }
147 |
148 | return (
149 | <>
150 | setIsModalOpen( true ) }
154 | />
155 | { isModalOpen && (
156 | setIsModalOpen( false ) }
160 | className="block-pattern-explorer__modal"
161 | isFullScreen
162 | >
163 |
170 |
171 | ) }
172 | >
173 | );
174 | }
175 |
176 | /**
177 | * Add the header toolbar button to the block editor.
178 | */
179 | subscribe( () => {
180 | const inserter = document.querySelector( '#block-pattern-explorer' );
181 |
182 | // If the inserter already exists, bail.
183 | if ( inserter ) {
184 | return;
185 | }
186 |
187 | wp.domReady( () => {
188 | const toolbar = document.querySelector(
189 | '.edit-post-header-toolbar__left'
190 | );
191 |
192 | // If no toolbar can be found at all, bail.
193 | if ( ! toolbar ) {
194 | return;
195 | }
196 |
197 | const buttonContainer = document.createElement( 'div' );
198 | buttonContainer.id = 'block-pattern-explorer';
199 |
200 | toolbar.appendChild( buttonContainer );
201 |
202 | render(
203 | ,
204 | document.getElementById( 'block-pattern-explorer' )
205 | );
206 | } );
207 | } );
208 |
209 | /**
210 | * (Experimental) Add support for the pattern category type setting.
211 | *
212 | * @param {Array} settings All editor settings
213 | * @since 0.2.0
214 | */
215 | // function addCategoryTypeSupport( settings ) {
216 | // settings.push( '__experimentalBlockPatternCategoryTypes' );
217 | //
218 | // return settings;
219 | // }
220 | // addFilter(
221 | // 'editor.SupportedEditorSettings',
222 | // 'block-pattern-explorer/add-category-type-support',
223 | // addCategoryTypeSupport
224 | // );
225 |
226 | /**
227 | * Add our custom entities for retrieving external data in the Block Editor.
228 | *
229 | * @since 0.2.0
230 | */
231 | dispatch( 'core' ).addEntities( [
232 | {
233 | label: __( 'Pattern Category Types', 'block-pattern-explorer' ),
234 | kind: 'block-pattern-explorer/v1',
235 | name: 'patternCategoryTypes',
236 | baseURL: '/block-pattern-explorer/v1/pattern-category-types',
237 | },
238 | ] );
239 |
--------------------------------------------------------------------------------
/composer.lock:
--------------------------------------------------------------------------------
1 | {
2 | "_readme": [
3 | "This file locks the dependencies of your project to a known state",
4 | "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
5 | "This file is @generated automatically"
6 | ],
7 | "content-hash": "f1208c6a6b41cd7604bb032736117d31",
8 | "packages": [],
9 | "packages-dev": [
10 | {
11 | "name": "dealerdirect/phpcodesniffer-composer-installer",
12 | "version": "v0.7.1",
13 | "source": {
14 | "type": "git",
15 | "url": "https://github.com/Dealerdirect/phpcodesniffer-composer-installer.git",
16 | "reference": "fe390591e0241955f22eb9ba327d137e501c771c"
17 | },
18 | "dist": {
19 | "type": "zip",
20 | "url": "https://api.github.com/repos/Dealerdirect/phpcodesniffer-composer-installer/zipball/fe390591e0241955f22eb9ba327d137e501c771c",
21 | "reference": "fe390591e0241955f22eb9ba327d137e501c771c",
22 | "shasum": ""
23 | },
24 | "require": {
25 | "composer-plugin-api": "^1.0 || ^2.0",
26 | "php": ">=5.3",
27 | "squizlabs/php_codesniffer": "^2.0 || ^3.0 || ^4.0"
28 | },
29 | "require-dev": {
30 | "composer/composer": "*",
31 | "phpcompatibility/php-compatibility": "^9.0",
32 | "sensiolabs/security-checker": "^4.1.0"
33 | },
34 | "type": "composer-plugin",
35 | "extra": {
36 | "class": "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin"
37 | },
38 | "autoload": {
39 | "psr-4": {
40 | "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\": "src/"
41 | }
42 | },
43 | "notification-url": "https://packagist.org/downloads/",
44 | "license": [
45 | "MIT"
46 | ],
47 | "authors": [
48 | {
49 | "name": "Franck Nijhof",
50 | "email": "franck.nijhof@dealerdirect.com",
51 | "homepage": "http://www.frenck.nl",
52 | "role": "Developer / IT Manager"
53 | }
54 | ],
55 | "description": "PHP_CodeSniffer Standards Composer Installer Plugin",
56 | "homepage": "http://www.dealerdirect.com",
57 | "keywords": [
58 | "PHPCodeSniffer",
59 | "PHP_CodeSniffer",
60 | "code quality",
61 | "codesniffer",
62 | "composer",
63 | "installer",
64 | "phpcs",
65 | "plugin",
66 | "qa",
67 | "quality",
68 | "standard",
69 | "standards",
70 | "style guide",
71 | "stylecheck",
72 | "tests"
73 | ],
74 | "support": {
75 | "issues": "https://github.com/dealerdirect/phpcodesniffer-composer-installer/issues",
76 | "source": "https://github.com/dealerdirect/phpcodesniffer-composer-installer"
77 | },
78 | "time": "2020-12-07T18:04:37+00:00"
79 | },
80 | {
81 | "name": "phpcompatibility/php-compatibility",
82 | "version": "9.3.5",
83 | "source": {
84 | "type": "git",
85 | "url": "https://github.com/PHPCompatibility/PHPCompatibility.git",
86 | "reference": "9fb324479acf6f39452e0655d2429cc0d3914243"
87 | },
88 | "dist": {
89 | "type": "zip",
90 | "url": "https://api.github.com/repos/PHPCompatibility/PHPCompatibility/zipball/9fb324479acf6f39452e0655d2429cc0d3914243",
91 | "reference": "9fb324479acf6f39452e0655d2429cc0d3914243",
92 | "shasum": ""
93 | },
94 | "require": {
95 | "php": ">=5.3",
96 | "squizlabs/php_codesniffer": "^2.3 || ^3.0.2"
97 | },
98 | "conflict": {
99 | "squizlabs/php_codesniffer": "2.6.2"
100 | },
101 | "require-dev": {
102 | "phpunit/phpunit": "~4.5 || ^5.0 || ^6.0 || ^7.0"
103 | },
104 | "suggest": {
105 | "dealerdirect/phpcodesniffer-composer-installer": "^0.5 || This Composer plugin will sort out the PHPCS 'installed_paths' automatically.",
106 | "roave/security-advisories": "dev-master || Helps prevent installing dependencies with known security issues."
107 | },
108 | "type": "phpcodesniffer-standard",
109 | "notification-url": "https://packagist.org/downloads/",
110 | "license": [
111 | "LGPL-3.0-or-later"
112 | ],
113 | "authors": [
114 | {
115 | "name": "Wim Godden",
116 | "homepage": "https://github.com/wimg",
117 | "role": "lead"
118 | },
119 | {
120 | "name": "Juliette Reinders Folmer",
121 | "homepage": "https://github.com/jrfnl",
122 | "role": "lead"
123 | },
124 | {
125 | "name": "Contributors",
126 | "homepage": "https://github.com/PHPCompatibility/PHPCompatibility/graphs/contributors"
127 | }
128 | ],
129 | "description": "A set of sniffs for PHP_CodeSniffer that checks for PHP cross-version compatibility.",
130 | "homepage": "http://techblog.wimgodden.be/tag/codesniffer/",
131 | "keywords": [
132 | "compatibility",
133 | "phpcs",
134 | "standards"
135 | ],
136 | "support": {
137 | "issues": "https://github.com/PHPCompatibility/PHPCompatibility/issues",
138 | "source": "https://github.com/PHPCompatibility/PHPCompatibility"
139 | },
140 | "time": "2019-12-27T09:44:58+00:00"
141 | },
142 | {
143 | "name": "phpcompatibility/phpcompatibility-paragonie",
144 | "version": "1.3.1",
145 | "source": {
146 | "type": "git",
147 | "url": "https://github.com/PHPCompatibility/PHPCompatibilityParagonie.git",
148 | "reference": "ddabec839cc003651f2ce695c938686d1086cf43"
149 | },
150 | "dist": {
151 | "type": "zip",
152 | "url": "https://api.github.com/repos/PHPCompatibility/PHPCompatibilityParagonie/zipball/ddabec839cc003651f2ce695c938686d1086cf43",
153 | "reference": "ddabec839cc003651f2ce695c938686d1086cf43",
154 | "shasum": ""
155 | },
156 | "require": {
157 | "phpcompatibility/php-compatibility": "^9.0"
158 | },
159 | "require-dev": {
160 | "dealerdirect/phpcodesniffer-composer-installer": "^0.7",
161 | "paragonie/random_compat": "dev-master",
162 | "paragonie/sodium_compat": "dev-master"
163 | },
164 | "suggest": {
165 | "dealerdirect/phpcodesniffer-composer-installer": "^0.7 || This Composer plugin will sort out the PHP_CodeSniffer 'installed_paths' automatically.",
166 | "roave/security-advisories": "dev-master || Helps prevent installing dependencies with known security issues."
167 | },
168 | "type": "phpcodesniffer-standard",
169 | "notification-url": "https://packagist.org/downloads/",
170 | "license": [
171 | "LGPL-3.0-or-later"
172 | ],
173 | "authors": [
174 | {
175 | "name": "Wim Godden",
176 | "role": "lead"
177 | },
178 | {
179 | "name": "Juliette Reinders Folmer",
180 | "role": "lead"
181 | }
182 | ],
183 | "description": "A set of rulesets for PHP_CodeSniffer to check for PHP cross-version compatibility issues in projects, while accounting for polyfills provided by the Paragonie polyfill libraries.",
184 | "homepage": "http://phpcompatibility.com/",
185 | "keywords": [
186 | "compatibility",
187 | "paragonie",
188 | "phpcs",
189 | "polyfill",
190 | "standards"
191 | ],
192 | "support": {
193 | "issues": "https://github.com/PHPCompatibility/PHPCompatibilityParagonie/issues",
194 | "source": "https://github.com/PHPCompatibility/PHPCompatibilityParagonie"
195 | },
196 | "time": "2021-02-15T10:24:51+00:00"
197 | },
198 | {
199 | "name": "phpcompatibility/phpcompatibility-wp",
200 | "version": "2.1.3",
201 | "source": {
202 | "type": "git",
203 | "url": "https://github.com/PHPCompatibility/PHPCompatibilityWP.git",
204 | "reference": "d55de55f88697b9cdb94bccf04f14eb3b11cf308"
205 | },
206 | "dist": {
207 | "type": "zip",
208 | "url": "https://api.github.com/repos/PHPCompatibility/PHPCompatibilityWP/zipball/d55de55f88697b9cdb94bccf04f14eb3b11cf308",
209 | "reference": "d55de55f88697b9cdb94bccf04f14eb3b11cf308",
210 | "shasum": ""
211 | },
212 | "require": {
213 | "phpcompatibility/php-compatibility": "^9.0",
214 | "phpcompatibility/phpcompatibility-paragonie": "^1.0"
215 | },
216 | "require-dev": {
217 | "dealerdirect/phpcodesniffer-composer-installer": "^0.7"
218 | },
219 | "suggest": {
220 | "dealerdirect/phpcodesniffer-composer-installer": "^0.7 || This Composer plugin will sort out the PHP_CodeSniffer 'installed_paths' automatically.",
221 | "roave/security-advisories": "dev-master || Helps prevent installing dependencies with known security issues."
222 | },
223 | "type": "phpcodesniffer-standard",
224 | "notification-url": "https://packagist.org/downloads/",
225 | "license": [
226 | "LGPL-3.0-or-later"
227 | ],
228 | "authors": [
229 | {
230 | "name": "Wim Godden",
231 | "role": "lead"
232 | },
233 | {
234 | "name": "Juliette Reinders Folmer",
235 | "role": "lead"
236 | }
237 | ],
238 | "description": "A ruleset for PHP_CodeSniffer to check for PHP cross-version compatibility issues in projects, while accounting for polyfills provided by WordPress.",
239 | "homepage": "http://phpcompatibility.com/",
240 | "keywords": [
241 | "compatibility",
242 | "phpcs",
243 | "standards",
244 | "wordpress"
245 | ],
246 | "support": {
247 | "issues": "https://github.com/PHPCompatibility/PHPCompatibilityWP/issues",
248 | "source": "https://github.com/PHPCompatibility/PHPCompatibilityWP"
249 | },
250 | "time": "2021-12-30T16:37:40+00:00"
251 | },
252 | {
253 | "name": "squizlabs/php_codesniffer",
254 | "version": "3.6.2",
255 | "source": {
256 | "type": "git",
257 | "url": "https://github.com/squizlabs/PHP_CodeSniffer.git",
258 | "reference": "5e4e71592f69da17871dba6e80dd51bce74a351a"
259 | },
260 | "dist": {
261 | "type": "zip",
262 | "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/5e4e71592f69da17871dba6e80dd51bce74a351a",
263 | "reference": "5e4e71592f69da17871dba6e80dd51bce74a351a",
264 | "shasum": ""
265 | },
266 | "require": {
267 | "ext-simplexml": "*",
268 | "ext-tokenizer": "*",
269 | "ext-xmlwriter": "*",
270 | "php": ">=5.4.0"
271 | },
272 | "require-dev": {
273 | "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0"
274 | },
275 | "bin": [
276 | "bin/phpcs",
277 | "bin/phpcbf"
278 | ],
279 | "type": "library",
280 | "extra": {
281 | "branch-alias": {
282 | "dev-master": "3.x-dev"
283 | }
284 | },
285 | "notification-url": "https://packagist.org/downloads/",
286 | "license": [
287 | "BSD-3-Clause"
288 | ],
289 | "authors": [
290 | {
291 | "name": "Greg Sherwood",
292 | "role": "lead"
293 | }
294 | ],
295 | "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.",
296 | "homepage": "https://github.com/squizlabs/PHP_CodeSniffer",
297 | "keywords": [
298 | "phpcs",
299 | "standards"
300 | ],
301 | "support": {
302 | "issues": "https://github.com/squizlabs/PHP_CodeSniffer/issues",
303 | "source": "https://github.com/squizlabs/PHP_CodeSniffer",
304 | "wiki": "https://github.com/squizlabs/PHP_CodeSniffer/wiki"
305 | },
306 | "time": "2021-12-12T21:44:58+00:00"
307 | },
308 | {
309 | "name": "wp-coding-standards/wpcs",
310 | "version": "2.3.0",
311 | "source": {
312 | "type": "git",
313 | "url": "https://github.com/WordPress/WordPress-Coding-Standards.git",
314 | "reference": "7da1894633f168fe244afc6de00d141f27517b62"
315 | },
316 | "dist": {
317 | "type": "zip",
318 | "url": "https://api.github.com/repos/WordPress/WordPress-Coding-Standards/zipball/7da1894633f168fe244afc6de00d141f27517b62",
319 | "reference": "7da1894633f168fe244afc6de00d141f27517b62",
320 | "shasum": ""
321 | },
322 | "require": {
323 | "php": ">=5.4",
324 | "squizlabs/php_codesniffer": "^3.3.1"
325 | },
326 | "require-dev": {
327 | "dealerdirect/phpcodesniffer-composer-installer": "^0.5 || ^0.6",
328 | "phpcompatibility/php-compatibility": "^9.0",
329 | "phpcsstandards/phpcsdevtools": "^1.0",
330 | "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0"
331 | },
332 | "suggest": {
333 | "dealerdirect/phpcodesniffer-composer-installer": "^0.6 || This Composer plugin will sort out the PHPCS 'installed_paths' automatically."
334 | },
335 | "type": "phpcodesniffer-standard",
336 | "notification-url": "https://packagist.org/downloads/",
337 | "license": [
338 | "MIT"
339 | ],
340 | "authors": [
341 | {
342 | "name": "Contributors",
343 | "homepage": "https://github.com/WordPress/WordPress-Coding-Standards/graphs/contributors"
344 | }
345 | ],
346 | "description": "PHP_CodeSniffer rules (sniffs) to enforce WordPress coding conventions",
347 | "keywords": [
348 | "phpcs",
349 | "standards",
350 | "wordpress"
351 | ],
352 | "support": {
353 | "issues": "https://github.com/WordPress/WordPress-Coding-Standards/issues",
354 | "source": "https://github.com/WordPress/WordPress-Coding-Standards",
355 | "wiki": "https://github.com/WordPress/WordPress-Coding-Standards/wiki"
356 | },
357 | "time": "2020-05-13T23:57:56+00:00"
358 | }
359 | ],
360 | "aliases": [],
361 | "minimum-stability": "stable",
362 | "stability-flags": [],
363 | "prefer-stable": false,
364 | "prefer-lowest": false,
365 | "platform": {
366 | "php": ">=5.6"
367 | },
368 | "platform-dev": [],
369 | "plugin-api-version": "2.2.0"
370 | }
371 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 2, June 1991
3 |
4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6 | Everyone is permitted to copy and distribute verbatim copies
7 | of this license document, but changing it is not allowed.
8 |
9 | Preamble
10 |
11 | The licenses for most software are designed to take away your
12 | freedom to share and change it. By contrast, the GNU General Public
13 | License is intended to guarantee your freedom to share and change free
14 | software--to make sure the software is free for all its users. This
15 | General Public License applies to most of the Free Software
16 | Foundation's software and to any other program whose authors commit to
17 | using it. (Some other Free Software Foundation software is covered by
18 | the GNU Lesser General Public License instead.) You can apply it to
19 | your programs, too.
20 |
21 | When we speak of free software, we are referring to freedom, not
22 | price. Our General Public Licenses are designed to make sure that you
23 | have the freedom to distribute copies of free software (and charge for
24 | this service if you wish), that you receive source code or can get it
25 | if you want it, that you can change the software or use pieces of it
26 | in new free programs; and that you know you can do these things.
27 |
28 | To protect your rights, we need to make restrictions that forbid
29 | anyone to deny you these rights or to ask you to surrender the rights.
30 | These restrictions translate to certain responsibilities for you if you
31 | distribute copies of the software, or if you modify it.
32 |
33 | For example, if you distribute copies of such a program, whether
34 | gratis or for a fee, you must give the recipients all the rights that
35 | you have. You must make sure that they, too, receive or can get the
36 | source code. And you must show them these terms so they know their
37 | rights.
38 |
39 | We protect your rights with two steps: (1) copyright the software, and
40 | (2) offer you this license which gives you legal permission to copy,
41 | distribute and/or modify the software.
42 |
43 | Also, for each author's protection and ours, we want to make certain
44 | that everyone understands that there is no warranty for this free
45 | software. If the software is modified by someone else and passed on, we
46 | want its recipients to know that what they have is not the original, so
47 | that any problems introduced by others will not reflect on the original
48 | authors' reputations.
49 |
50 | Finally, any free program is threatened constantly by software
51 | patents. We wish to avoid the danger that redistributors of a free
52 | program will individually obtain patent licenses, in effect making the
53 | program proprietary. To prevent this, we have made it clear that any
54 | patent must be licensed for everyone's free use or not licensed at all.
55 |
56 | The precise terms and conditions for copying, distribution and
57 | modification follow.
58 |
59 | GNU GENERAL PUBLIC LICENSE
60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61 |
62 | 0. This License applies to any program or other work which contains
63 | a notice placed by the copyright holder saying it may be distributed
64 | under the terms of this General Public License. The "Program", below,
65 | refers to any such program or work, and a "work based on the Program"
66 | means either the Program or any derivative work under copyright law:
67 | that is to say, a work containing the Program or a portion of it,
68 | either verbatim or with modifications and/or translated into another
69 | language. (Hereinafter, translation is included without limitation in
70 | the term "modification".) Each licensee is addressed as "you".
71 |
72 | Activities other than copying, distribution and modification are not
73 | covered by this License; they are outside its scope. The act of
74 | running the Program is not restricted, and the output from the Program
75 | is covered only if its contents constitute a work based on the
76 | Program (independent of having been made by running the Program).
77 | Whether that is true depends on what the Program does.
78 |
79 | 1. You may copy and distribute verbatim copies of the Program's
80 | source code as you receive it, in any medium, provided that you
81 | conspicuously and appropriately publish on each copy an appropriate
82 | copyright notice and disclaimer of warranty; keep intact all the
83 | notices that refer to this License and to the absence of any warranty;
84 | and give any other recipients of the Program a copy of this License
85 | along with the Program.
86 |
87 | You may charge a fee for the physical act of transferring a copy, and
88 | you may at your option offer warranty protection in exchange for a fee.
89 |
90 | 2. You may modify your copy or copies of the Program or any portion
91 | of it, thus forming a work based on the Program, and copy and
92 | distribute such modifications or work under the terms of Section 1
93 | above, provided that you also meet all of these conditions:
94 |
95 | a) You must cause the modified files to carry prominent notices
96 | stating that you changed the files and the date of any change.
97 |
98 | b) You must cause any work that you distribute or publish, that in
99 | whole or in part contains or is derived from the Program or any
100 | part thereof, to be licensed as a whole at no charge to all third
101 | parties under the terms of this License.
102 |
103 | c) If the modified program normally reads commands interactively
104 | when run, you must cause it, when started running for such
105 | interactive use in the most ordinary way, to print or display an
106 | announcement including an appropriate copyright notice and a
107 | notice that there is no warranty (or else, saying that you provide
108 | a warranty) and that users may redistribute the program under
109 | these conditions, and telling the user how to view a copy of this
110 | License. (Exception: if the Program itself is interactive but
111 | does not normally print such an announcement, your work based on
112 | the Program is not required to print an announcement.)
113 |
114 | These requirements apply to the modified work as a whole. If
115 | identifiable sections of that work are not derived from the Program,
116 | and can be reasonably considered independent and separate works in
117 | themselves, then this License, and its terms, do not apply to those
118 | sections when you distribute them as separate works. But when you
119 | distribute the same sections as part of a whole which is a work based
120 | on the Program, the distribution of the whole must be on the terms of
121 | this License, whose permissions for other licensees extend to the
122 | entire whole, and thus to each and every part regardless of who wrote it.
123 |
124 | Thus, it is not the intent of this section to claim rights or contest
125 | your rights to work written entirely by you; rather, the intent is to
126 | exercise the right to control the distribution of derivative or
127 | collective works based on the Program.
128 |
129 | In addition, mere aggregation of another work not based on the Program
130 | with the Program (or with a work based on the Program) on a volume of
131 | a storage or distribution medium does not bring the other work under
132 | the scope of this License.
133 |
134 | 3. You may copy and distribute the Program (or a work based on it,
135 | under Section 2) in object code or executable form under the terms of
136 | Sections 1 and 2 above provided that you also do one of the following:
137 |
138 | a) Accompany it with the complete corresponding machine-readable
139 | source code, which must be distributed under the terms of Sections
140 | 1 and 2 above on a medium customarily used for software interchange; or,
141 |
142 | b) Accompany it with a written offer, valid for at least three
143 | years, to give any third party, for a charge no more than your
144 | cost of physically performing source distribution, a complete
145 | machine-readable copy of the corresponding source code, to be
146 | distributed under the terms of Sections 1 and 2 above on a medium
147 | customarily used for software interchange; or,
148 |
149 | c) Accompany it with the information you received as to the offer
150 | to distribute corresponding source code. (This alternative is
151 | allowed only for noncommercial distribution and only if you
152 | received the program in object code or executable form with such
153 | an offer, in accord with Subsection b above.)
154 |
155 | The source code for a work means the preferred form of the work for
156 | making modifications to it. For an executable work, complete source
157 | code means all the source code for all modules it contains, plus any
158 | associated interface definition files, plus the scripts used to
159 | control compilation and installation of the executable. However, as a
160 | special exception, the source code distributed need not include
161 | anything that is normally distributed (in either source or binary
162 | form) with the major components (compiler, kernel, and so on) of the
163 | operating system on which the executable runs, unless that component
164 | itself accompanies the executable.
165 |
166 | If distribution of executable or object code is made by offering
167 | access to copy from a designated place, then offering equivalent
168 | access to copy the source code from the same place counts as
169 | distribution of the source code, even though third parties are not
170 | compelled to copy the source along with the object code.
171 |
172 | 4. You may not copy, modify, sublicense, or distribute the Program
173 | except as expressly provided under this License. Any attempt
174 | otherwise to copy, modify, sublicense or distribute the Program is
175 | void, and will automatically terminate your rights under this License.
176 | However, parties who have received copies, or rights, from you under
177 | this License will not have their licenses terminated so long as such
178 | parties remain in full compliance.
179 |
180 | 5. You are not required to accept this License, since you have not
181 | signed it. However, nothing else grants you permission to modify or
182 | distribute the Program or its derivative works. These actions are
183 | prohibited by law if you do not accept this License. Therefore, by
184 | modifying or distributing the Program (or any work based on the
185 | Program), you indicate your acceptance of this License to do so, and
186 | all its terms and conditions for copying, distributing or modifying
187 | the Program or works based on it.
188 |
189 | 6. Each time you redistribute the Program (or any work based on the
190 | Program), the recipient automatically receives a license from the
191 | original licensor to copy, distribute or modify the Program subject to
192 | these terms and conditions. You may not impose any further
193 | restrictions on the recipients' exercise of the rights granted herein.
194 | You are not responsible for enforcing compliance by third parties to
195 | this License.
196 |
197 | 7. If, as a consequence of a court judgment or allegation of patent
198 | infringement or for any other reason (not limited to patent issues),
199 | conditions are imposed on you (whether by court order, agreement or
200 | otherwise) that contradict the conditions of this License, they do not
201 | excuse you from the conditions of this License. If you cannot
202 | distribute so as to satisfy simultaneously your obligations under this
203 | License and any other pertinent obligations, then as a consequence you
204 | may not distribute the Program at all. For example, if a patent
205 | license would not permit royalty-free redistribution of the Program by
206 | all those who receive copies directly or indirectly through you, then
207 | the only way you could satisfy both it and this License would be to
208 | refrain entirely from distribution of the Program.
209 |
210 | If any portion of this section is held invalid or unenforceable under
211 | any particular circumstance, the balance of the section is intended to
212 | apply and the section as a whole is intended to apply in other
213 | circumstances.
214 |
215 | It is not the purpose of this section to induce you to infringe any
216 | patents or other property right claims or to contest validity of any
217 | such claims; this section has the sole purpose of protecting the
218 | integrity of the free software distribution system, which is
219 | implemented by public license practices. Many people have made
220 | generous contributions to the wide range of software distributed
221 | through that system in reliance on consistent application of that
222 | system; it is up to the author/donor to decide if he or she is willing
223 | to distribute software through any other system and a licensee cannot
224 | impose that choice.
225 |
226 | This section is intended to make thoroughly clear what is believed to
227 | be a consequence of the rest of this License.
228 |
229 | 8. If the distribution and/or use of the Program is restricted in
230 | certain countries either by patents or by copyrighted interfaces, the
231 | original copyright holder who places the Program under this License
232 | may add an explicit geographical distribution limitation excluding
233 | those countries, so that distribution is permitted only in or among
234 | countries not thus excluded. In such case, this License incorporates
235 | the limitation as if written in the body of this License.
236 |
237 | 9. The Free Software Foundation may publish revised and/or new versions
238 | of the General Public License from time to time. Such new versions will
239 | be similar in spirit to the present version, but may differ in detail to
240 | address new problems or concerns.
241 |
242 | Each version is given a distinguishing version number. If the Program
243 | specifies a version number of this License which applies to it and "any
244 | later version", you have the option of following the terms and conditions
245 | either of that version or of any later version published by the Free
246 | Software Foundation. If the Program does not specify a version number of
247 | this License, you may choose any version ever published by the Free Software
248 | Foundation.
249 |
250 | 10. If you wish to incorporate parts of the Program into other free
251 | programs whose distribution conditions are different, write to the author
252 | to ask for permission. For software which is copyrighted by the Free
253 | Software Foundation, write to the Free Software Foundation; we sometimes
254 | make exceptions for this. Our decision will be guided by the two goals
255 | of preserving the free status of all derivatives of our free software and
256 | of promoting the sharing and reuse of software generally.
257 |
258 | NO WARRANTY
259 |
260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268 | REPAIR OR CORRECTION.
269 |
270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278 | POSSIBILITY OF SUCH DAMAGES.
279 |
280 | END OF TERMS AND CONDITIONS
281 |
282 | How to Apply These Terms to Your New Programs
283 |
284 | If you develop a new program, and you want it to be of the greatest
285 | possible use to the public, the best way to achieve this is to make it
286 | free software which everyone can redistribute and change under these terms.
287 |
288 | To do so, attach the following notices to the program. It is safest
289 | to attach them to the start of each source file to most effectively
290 | convey the exclusion of warranty; and each file should have at least
291 | the "copyright" line and a pointer to where the full notice is found.
292 |
293 |
294 | Copyright (C)
295 |
296 | This program is free software; you can redistribute it and/or modify
297 | it under the terms of the GNU General Public License as published by
298 | the Free Software Foundation; either version 2 of the License, or
299 | (at your option) any later version.
300 |
301 | This program is distributed in the hope that it will be useful,
302 | but WITHOUT ANY WARRANTY; without even the implied warranty of
303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304 | GNU General Public License for more details.
305 |
306 | You should have received a copy of the GNU General Public License along
307 | with this program; if not, write to the Free Software Foundation, Inc.,
308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
309 |
310 | Also add information on how to contact you by electronic and paper mail.
311 |
312 | If the program is interactive, make it output a short notice like this
313 | when it starts in an interactive mode:
314 |
315 | Gnomovision version 69, Copyright (C) year name of author
316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317 | This is free software, and you are welcome to redistribute it
318 | under certain conditions; type `show c' for details.
319 |
320 | The hypothetical commands `show w' and `show c' should show the appropriate
321 | parts of the General Public License. Of course, the commands you use may
322 | be called something other than `show w' and `show c'; they could even be
323 | mouse-clicks or menu items--whatever suits your program.
324 |
325 | You should also get your employer (if you work as a programmer) or your
326 | school, if any, to sign a "copyright disclaimer" for the program, if
327 | necessary. Here is a sample; alter the names:
328 |
329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330 | `Gnomovision' (which makes passes at compilers) written by James Hacker.
331 |
332 | , 1 April 1989
333 | Ty Coon, President of Vice
334 |
335 | This General Public License does not permit incorporating your program into
336 | proprietary programs. If your program is a subroutine library, you may
337 | consider it more useful to permit linking proprietary applications with the
338 | library. If this is what you want to do, use the GNU Lesser General
339 | Public License instead of this License.
340 |
--------------------------------------------------------------------------------