@storepress/create-plugin-html 0.0.6 → 0.1.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/README.md +5 -6
- package/index.js +80 -11
- package/package.json +1 -1
- package/plugin-templates/.github/workflows/deploy-github-pages.yaml.mustache +1 -0
- package/plugin-templates/eslint.config.js.mustache +133 -0
- package/plugin-templates/index-module.html.mustache +30 -0
- package/plugin-templates/index.html.mustache +47 -24
- package/plugin-templates/src/interactive/index.js.mustache +22 -0
- package/plugin-templates/src/react/index.js.mustache +41 -0
- package/{block-templates → plugin-templates/src/storepress}/Plugin.js.mustache +2 -2
- package/plugin-templates/src/storepress/index.js.mustache +20 -0
- package/plugin-templates/src/storepress/script.js.mustache +9 -0
- package/{block-templates → plugin-templates/src/storepress}/style.scss.mustache +2 -2
- package/plugin-templates/tools/changelog.js.mustache +40 -41
- package/plugin-templates/tools/package.js.mustache +47 -39
- package/plugin-templates/tools/packages-install.js.mustache +0 -2
- package/plugin-templates/tools/webpack-helpers.js.mustache +10 -37
- package/plugin-templates/tools/webpack.config.externals.js.mustache +130 -0
- package/plugin-templates/webpack.config.js.mustache +94 -85
- package/block-templates/index.js.mustache +0 -20
- package/plugin-templates/.eslintrc.js.mustache +0 -196
- package/plugin-templates/global-style.css.mustache +0 -14
- package/plugin-templates/script.js.mustache +0 -8
- package/plugin-templates/style.scss.mustache +0 -10
- /package/{block-templates → plugin-templates/src/storepress}/_mixins.scss.mustache +0 -0
package/README.md
CHANGED
|
@@ -7,16 +7,15 @@ This is a template for [`@wordpress/create-block`](https://developer.wordpress.o
|
|
|
7
7
|
This template can be used by running the following command:
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
|
-
npx -y @wordpress/create-block@latest --template @storepress/create-plugin-html
|
|
10
|
+
npx -y @wordpress/create-block@latest --template @storepress/create-plugin-html my-html-extension-name && cd "$_"
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
Navigate to the newly created folder and get started.
|
|
14
14
|
|
|
15
15
|
```
|
|
16
|
-
npm i
|
|
17
|
-
npm run
|
|
18
|
-
|
|
19
|
-
npx -y http-server # Start Server
|
|
16
|
+
npm i && npm run packages-update # Install dependencies and Update package dependency
|
|
17
|
+
npm run build # Build the javascript
|
|
18
|
+
npx -y http-server # Start Server
|
|
20
19
|
```
|
|
21
20
|
|
|
22
21
|
## Development
|
|
@@ -24,7 +23,7 @@ npx -y http-server # Start Server
|
|
|
24
23
|
For development on this tool itself, you can also install from a local directory.
|
|
25
24
|
|
|
26
25
|
```bash
|
|
27
|
-
npx -y @wordpress/create-block@latest --template ./
|
|
26
|
+
npx -y @wordpress/create-block@latest --template ./create-plugin-html my-html-extension-name && cd "$_"
|
|
28
27
|
```
|
|
29
28
|
|
|
30
29
|
### Add Tests
|
package/index.js
CHANGED
|
@@ -3,27 +3,87 @@
|
|
|
3
3
|
*/
|
|
4
4
|
const {join} = require('path')
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Converts a string to kebab-case by replacing separators (hyphens, dots,
|
|
8
|
+
* underscores, spaces, and plus signs) with hyphens and lowercasing.
|
|
9
|
+
*
|
|
10
|
+
* @param {string} input - The string to convert.
|
|
11
|
+
* @returns {string} The kebab-cased string (e.g. "my-plugin-name").
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* kebabCase('My Plugin Name') // => 'my-plugin-name'
|
|
15
|
+
* kebabCase('my_plugin.name') // => 'my-plugin-name'
|
|
16
|
+
*/
|
|
7
17
|
function kebabCase(input) {
|
|
8
18
|
const regex = /[-._\s+]/gi
|
|
9
19
|
return input.replace(regex, '-').toLowerCase()
|
|
10
20
|
}
|
|
11
21
|
|
|
22
|
+
/**
|
|
23
|
+
* Converts a string to snake_case by replacing separators (hyphens, dots,
|
|
24
|
+
* underscores, spaces, and plus signs) with underscores and lowercasing.
|
|
25
|
+
*
|
|
26
|
+
* @param {string} input - The string to convert.
|
|
27
|
+
* @returns {string} The snake_cased string (e.g. "my_plugin_name").
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* snakeCase('My Plugin Name') // => 'my_plugin_name'
|
|
31
|
+
* snakeCase('my-plugin.name') // => 'my_plugin_name'
|
|
32
|
+
*/
|
|
33
|
+
function snakeCase(input) {
|
|
34
|
+
const regex = /[-._\s+]/gi
|
|
35
|
+
return input.replace(regex, '_').toLowerCase()
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Converts a string to CONSTANT_CASE by replacing separators (hyphens, dots,
|
|
40
|
+
* underscores, spaces, and plus signs) with underscores and uppercasing.
|
|
41
|
+
*
|
|
42
|
+
* @param {string} input - The string to convert.
|
|
43
|
+
* @returns {string} The constant-cased string (e.g. "MY_PLUGIN_NAME").
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* constantCase('my-plugin-name') // => 'MY_PLUGIN_NAME'
|
|
47
|
+
* constantCase('my plugin.name') // => 'MY_PLUGIN_NAME'
|
|
48
|
+
*/
|
|
12
49
|
function constantCase(input) {
|
|
13
50
|
const regex = /[-._\s+]/gi
|
|
14
51
|
return input.replace(regex, '_').toUpperCase()
|
|
15
52
|
}
|
|
16
53
|
|
|
54
|
+
/**
|
|
55
|
+
* Maps the literal string `"storepress"` to its branded casing `"StorePress"`,
|
|
56
|
+
* leaving all other inputs unchanged.
|
|
57
|
+
*
|
|
58
|
+
* @param {string} input - The string to check.
|
|
59
|
+
* @returns {string} `"StorePress"` if input is `"storepress"`, otherwise the original input.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* pascalStorePress('storepress') // => 'StorePress'
|
|
63
|
+
* pascalStorePress('myplugin') // => 'myplugin'
|
|
64
|
+
*/
|
|
17
65
|
function pascalStorePress(input) {
|
|
18
66
|
return 'storepress' === input ? 'StorePress' : input
|
|
19
67
|
}
|
|
20
68
|
|
|
69
|
+
/**
|
|
70
|
+
* Converts a string to PascalCase by extracting alphanumeric words and
|
|
71
|
+
* capitalizing the first letter of each.
|
|
72
|
+
*
|
|
73
|
+
* @param {string} input - The string to convert.
|
|
74
|
+
* @returns {string} The PascalCased string (e.g. "MyPluginName").
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* pascalCase('my-plugin-name') // => 'MyPluginName'
|
|
78
|
+
* pascalCase('my plugin name') // => 'MyPluginName'
|
|
79
|
+
*/
|
|
21
80
|
function pascalCase(input) {
|
|
22
81
|
return (input.match(/[a-zA-Z0-9]+/g) || []).map(w => `${w.charAt(0).toUpperCase()}${w.slice(1)}`).join('')
|
|
23
82
|
}
|
|
24
83
|
|
|
25
84
|
module.exports = {
|
|
26
85
|
defaultValues : {
|
|
86
|
+
wpScripts : false,
|
|
27
87
|
folderName : 'src',
|
|
28
88
|
namespace : 'storepress',
|
|
29
89
|
slug : 'plugin',
|
|
@@ -36,10 +96,10 @@ module.exports = {
|
|
|
36
96
|
attributes : {},
|
|
37
97
|
license : 'GPL-2.0-or-later',
|
|
38
98
|
customScripts : {
|
|
39
|
-
'postinstall' : 'git init -q && rimraf .husky && npx husky init && echo "npx lint-staged" > .husky/pre-commit',
|
|
99
|
+
'postinstall' : 'npm run packages-install:all && git init -q && rimraf .husky && npx husky init && echo "npx lint-staged" > .husky/pre-commit',
|
|
40
100
|
|
|
41
|
-
'prebuild' : 'rimraf build',
|
|
42
|
-
'build' : '
|
|
101
|
+
'prebuild' : 'rimraf build && npm run external:build',
|
|
102
|
+
'build' : 'wp-scripts build --webpack-copy-php --experimental-modules',
|
|
43
103
|
|
|
44
104
|
'check-engines' : 'wp-scripts check-engines',
|
|
45
105
|
'check-licenses' : 'wp-scripts check-licenses',
|
|
@@ -73,24 +133,29 @@ module.exports = {
|
|
|
73
133
|
'test:e2e' : 'wp-scripts test-e2e',
|
|
74
134
|
'test:unit' : 'wp-scripts test-unit-js',
|
|
75
135
|
|
|
76
|
-
|
|
136
|
+
"external:dev" : "wp-scripts start --no-watch --config tools/webpack.config.externals.js --experimental-modules --webpack-no-externals",
|
|
137
|
+
"external:build" : "wp-scripts build --config tools/webpack.config.externals.js --experimental-modules --webpack-no-externals",
|
|
138
|
+
|
|
139
|
+
'prestart' : 'rimraf build && npm run external:dev',
|
|
140
|
+
'start' : 'wp-scripts start --webpack-copy-php --experimental-modules',
|
|
77
141
|
},
|
|
78
142
|
npmDependencies : [
|
|
79
143
|
'@storepress/utils',
|
|
144
|
+
'@wordpress/element',
|
|
145
|
+
'@wordpress/interactivity',
|
|
80
146
|
],
|
|
81
147
|
npmDevDependencies : [
|
|
82
148
|
'@wordpress/scripts',
|
|
83
|
-
'@
|
|
84
|
-
'@
|
|
149
|
+
'@wordpress/dependency-extraction-webpack-plugin',
|
|
150
|
+
'@wordpress/eslint-plugin',
|
|
85
151
|
'@wordpress/base-styles',
|
|
86
152
|
'@wordpress/dependency-extraction-webpack-plugin',
|
|
87
|
-
'eslint-plugin-you-dont-need-lodash-underscore',
|
|
88
153
|
'husky',
|
|
89
154
|
'lint-staged',
|
|
90
|
-
"prettier
|
|
155
|
+
"prettier",
|
|
91
156
|
'fs-extra',
|
|
92
157
|
'webpack-remove-empty-scripts',
|
|
93
|
-
'eslint-plugin-prettier
|
|
158
|
+
'eslint-plugin-prettier',
|
|
94
159
|
'eslint-formatter-pretty',
|
|
95
160
|
'rimraf',
|
|
96
161
|
],
|
|
@@ -109,7 +174,7 @@ module.exports = {
|
|
|
109
174
|
'zip' : [
|
|
110
175
|
'build/**',
|
|
111
176
|
'index.html',
|
|
112
|
-
'
|
|
177
|
+
'index-module.html',
|
|
113
178
|
],
|
|
114
179
|
},
|
|
115
180
|
transformer : (view) => {
|
|
@@ -120,6 +185,8 @@ module.exports = {
|
|
|
120
185
|
const constantSlug = constantCase(view.slug) // TWO_WORDS
|
|
121
186
|
const kebabSlug = kebabCase(view.slug) // two-words
|
|
122
187
|
const pascaleSlug = pascalCase(pascalStorePress(view.slug)) // 'TwoWords'
|
|
188
|
+
const snakeNamespace = snakeCase(view.namespace)
|
|
189
|
+
const snakeSlug = snakeCase(view.slug)
|
|
123
190
|
return {
|
|
124
191
|
...view,
|
|
125
192
|
name : `@${kebabNamespace}/${kebabSlug}`,
|
|
@@ -127,10 +194,12 @@ module.exports = {
|
|
|
127
194
|
constantNamespace : constantNamespace,
|
|
128
195
|
kebabNamespace : kebabNamespace,
|
|
129
196
|
pascaleNamespace : pascaleNamespace,
|
|
197
|
+
snakeNamespace : snakeNamespace,
|
|
130
198
|
|
|
131
199
|
constantSlug : constantSlug,
|
|
132
200
|
kebabSlug : kebabSlug,
|
|
133
201
|
pascaleSlug : pascaleSlug,
|
|
202
|
+
snakeSlug : snakeSlug,
|
|
134
203
|
|
|
135
204
|
GITHUB_REPOSITORY_NAME : '${{ github.event.repository.name }}',
|
|
136
205
|
GITHUB_RELEASE_NAME : '${{ env.RELEASE_NAME }}',
|
package/package.json
CHANGED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
const wordpress = require('@wordpress/eslint-plugin');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Internal dependencies
|
|
8
|
+
*/
|
|
9
|
+
const { getWebPackAlias } = require('./tools/webpack-helpers');
|
|
10
|
+
const aliases = Object.keys(getWebPackAlias());
|
|
11
|
+
|
|
12
|
+
// All @wordpress/* packages that get externalized to wp.* globals at build time.
|
|
13
|
+
// These don't need to be in package.json — WordPress provides them at runtime.
|
|
14
|
+
// https://developer.wordpress.org/block-editor/reference-guides/packages/packages-eslint-plugin/
|
|
15
|
+
const wordPressPackages = [
|
|
16
|
+
'@wordpress/a11y',
|
|
17
|
+
'@wordpress/annotations',
|
|
18
|
+
'@wordpress/api-fetch',
|
|
19
|
+
'@wordpress/autop',
|
|
20
|
+
'@wordpress/blob',
|
|
21
|
+
'@wordpress/block-directory',
|
|
22
|
+
'@wordpress/block-editor',
|
|
23
|
+
'@wordpress/block-library',
|
|
24
|
+
'@wordpress/block-serialization-default-parser',
|
|
25
|
+
'@wordpress/blocks',
|
|
26
|
+
'@wordpress/commands',
|
|
27
|
+
'@wordpress/components',
|
|
28
|
+
'@wordpress/compose',
|
|
29
|
+
'@wordpress/core-commands',
|
|
30
|
+
'@wordpress/core-data',
|
|
31
|
+
'@wordpress/customize-widgets',
|
|
32
|
+
'@wordpress/data',
|
|
33
|
+
'@wordpress/data-controls',
|
|
34
|
+
'@wordpress/date',
|
|
35
|
+
'@wordpress/deprecated',
|
|
36
|
+
'@wordpress/dom',
|
|
37
|
+
'@wordpress/dom-ready',
|
|
38
|
+
'@wordpress/edit-post',
|
|
39
|
+
'@wordpress/edit-site',
|
|
40
|
+
'@wordpress/edit-widgets',
|
|
41
|
+
'@wordpress/editor',
|
|
42
|
+
'@wordpress/element',
|
|
43
|
+
'@wordpress/escape-html',
|
|
44
|
+
'@wordpress/format-library',
|
|
45
|
+
'@wordpress/hooks',
|
|
46
|
+
'@wordpress/html-entities',
|
|
47
|
+
'@wordpress/i18n',
|
|
48
|
+
'@wordpress/icons',
|
|
49
|
+
'@wordpress/interactivity',
|
|
50
|
+
'@wordpress/interactivity-router',
|
|
51
|
+
'@wordpress/interface',
|
|
52
|
+
'@wordpress/is-shallow-equal',
|
|
53
|
+
'@wordpress/keyboard-shortcuts',
|
|
54
|
+
'@wordpress/keycodes',
|
|
55
|
+
'@wordpress/list-reusable-blocks',
|
|
56
|
+
'@wordpress/media-utils',
|
|
57
|
+
'@wordpress/notices',
|
|
58
|
+
'@wordpress/nux',
|
|
59
|
+
'@wordpress/patterns',
|
|
60
|
+
'@wordpress/plugins',
|
|
61
|
+
'@wordpress/preferences',
|
|
62
|
+
'@wordpress/preferences-persistence',
|
|
63
|
+
'@wordpress/primitives',
|
|
64
|
+
'@wordpress/priority-queue',
|
|
65
|
+
'@wordpress/private-apis',
|
|
66
|
+
'@wordpress/redux-routine',
|
|
67
|
+
'@wordpress/reusable-blocks',
|
|
68
|
+
'@wordpress/rich-text',
|
|
69
|
+
'@wordpress/router',
|
|
70
|
+
'@wordpress/server-side-render',
|
|
71
|
+
'@wordpress/shortcode',
|
|
72
|
+
'@wordpress/style-engine',
|
|
73
|
+
'@wordpress/token-list',
|
|
74
|
+
'@wordpress/url',
|
|
75
|
+
'@wordpress/viewport',
|
|
76
|
+
'@wordpress/warning',
|
|
77
|
+
'@wordpress/widgets',
|
|
78
|
+
'@wordpress/wordcount',
|
|
79
|
+
'@storepress/html-plugin',
|
|
80
|
+
'adm-zip',
|
|
81
|
+
'fast-glob',
|
|
82
|
+
];
|
|
83
|
+
|
|
84
|
+
const restrictedImports = [
|
|
85
|
+
{
|
|
86
|
+
name: 'lodash',
|
|
87
|
+
message:
|
|
88
|
+
'This Lodash method is not recommended. Please use native functionality instead. If using `memoize`, please use `memize` instead.',
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
name: 'classnames',
|
|
92
|
+
message:
|
|
93
|
+
"Please use `clsx` instead. It's a lighter and faster drop-in replacement for `classnames`.",
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
name: 'redux',
|
|
97
|
+
importNames: ['combineReducers'],
|
|
98
|
+
message: 'Please use `combineReducers` from `@wordpress/data` instead.',
|
|
99
|
+
},
|
|
100
|
+
];
|
|
101
|
+
|
|
102
|
+
module.exports = [
|
|
103
|
+
{
|
|
104
|
+
ignores: ['build/', 'vendor/', 'node_modules/'],
|
|
105
|
+
},
|
|
106
|
+
...wordpress.configs.recommended,
|
|
107
|
+
{
|
|
108
|
+
languageOptions: {
|
|
109
|
+
globals: {
|
|
110
|
+
StorePress: 'writable',
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
settings: {
|
|
114
|
+
'import/core-modules': [...wordPressPackages, ...aliases],
|
|
115
|
+
'import/resolver': {
|
|
116
|
+
node: {
|
|
117
|
+
extensions: ['.js', '.jsx', '.ts', '.tsx'],
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
rules: {
|
|
122
|
+
'@wordpress/dependency-group': 'warn',
|
|
123
|
+
'no-unused-vars': 'warn',
|
|
124
|
+
'@wordpress/no-unsafe-wp-apis': 'warn',
|
|
125
|
+
'no-restricted-imports': [
|
|
126
|
+
'error',
|
|
127
|
+
{
|
|
128
|
+
paths: restrictedImports,
|
|
129
|
+
},
|
|
130
|
+
],
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
];
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
+
<title>Standalone WordPress Package Usages</title>
|
|
7
|
+
|
|
8
|
+
<script type="importmap">
|
|
9
|
+
{
|
|
10
|
+
"imports": {
|
|
11
|
+
"@storepress/utils": "./build/storepress-utils-module.js"
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
</script>
|
|
15
|
+
|
|
16
|
+
<link rel="modulepreload" href="./build/storepress-utils-module.js" fetchpriority="low"/>
|
|
17
|
+
</head>
|
|
18
|
+
|
|
19
|
+
<body>
|
|
20
|
+
|
|
21
|
+
<h2>StorePress Example as Module:</h2>
|
|
22
|
+
|
|
23
|
+
<div data-storepress-plugin="{'greet': 'Hello'}">Hello ( Check Browser Console )</div>
|
|
24
|
+
|
|
25
|
+
<p><a href="./index.html">Check using storepress plugin as script</a></p>
|
|
26
|
+
|
|
27
|
+
<script type="module" src="./build/module-example.js"></script>
|
|
28
|
+
|
|
29
|
+
</body>
|
|
30
|
+
</html>
|
|
@@ -3,35 +3,58 @@
|
|
|
3
3
|
<head>
|
|
4
4
|
<meta charset="UTF-8">
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
-
<title>
|
|
7
|
-
|
|
8
|
-
<
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
</script>
|
|
20
|
-
|
|
21
|
-
<link rel="modulepreload" href="./build/storepress-utils-module.js" />
|
|
22
|
-
<link rel="modulepreload" href="https://esm.sh/@huggingface/transformers" />
|
|
23
|
-
<link rel="modulepreload" href="https://esm.sh/@babycommando/entity-db" />
|
|
24
|
-
|
|
25
|
-
<script type="module" src="./custom-module.js"></script>
|
|
6
|
+
<title>Standalone WordPress Package Usages</title>
|
|
7
|
+
|
|
8
|
+
<script type="importmap">
|
|
9
|
+
{
|
|
10
|
+
"imports": {
|
|
11
|
+
"@wordpress/interactivity": "./build/externals/modules/wp-interactivity.js"
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
</script>
|
|
15
|
+
|
|
16
|
+
<link rel="modulepreload" href="./build/externals/modules/wp-interactivity.js" fetchpriority="low"/>
|
|
26
17
|
</head>
|
|
27
18
|
|
|
28
19
|
<body>
|
|
29
20
|
|
|
30
|
-
<
|
|
31
|
-
|
|
21
|
+
<h1>Example of WordPress Package Usage as Standalone</h1>
|
|
22
|
+
<div id="wrapper"></div>
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
<div
|
|
26
|
+
data-wp-interactive="{{slug}}"
|
|
27
|
+
data-wp-context='{ "isOpen": false }'
|
|
28
|
+
>
|
|
29
|
+
<h2>Interactive Counter: <span data-wp-text="state.count"></span></h2>
|
|
30
|
+
<button data-wp-on--click="actions.increment">+</button>
|
|
31
|
+
<button data-wp-on--click="actions.decrement">−</button>
|
|
32
|
+
|
|
33
|
+
<hr>
|
|
34
|
+
|
|
35
|
+
<button data-wp-on--click="actions.toggle">
|
|
36
|
+
<span data-wp-text="state.toggleText"></span>
|
|
37
|
+
</button>
|
|
38
|
+
<p data-wp-bind--hidden="!context.isOpen">
|
|
39
|
+
Hello from the Interactivity API! 🎉
|
|
40
|
+
</p>
|
|
32
41
|
</div>
|
|
33
42
|
|
|
43
|
+
|
|
44
|
+
<h2>StorePress Example:</h2>
|
|
45
|
+
|
|
46
|
+
<div data-storepress-plugin="{'greet': 'Hello'}">Hello ( Check Browser Console )</div>
|
|
47
|
+
|
|
48
|
+
<p><a href="./index-module.html">Check using storepress plugin as module</a></p>
|
|
49
|
+
|
|
50
|
+
<script src="./build/externals/scripts/react-jsx-runtime.js"></script>
|
|
51
|
+
<script src="./build/externals/scripts/wp-element.js"></script>
|
|
52
|
+
<script src="./build/react-example.js"></script>
|
|
53
|
+
|
|
34
54
|
<script src="./build/storepress-utils.js"></script>
|
|
35
|
-
<script src="./build/
|
|
55
|
+
<script src="./build/script-example.js"></script>
|
|
56
|
+
|
|
57
|
+
<script type="module" src="./build/interactive-example.js"></script>
|
|
58
|
+
|
|
36
59
|
</body>
|
|
37
|
-
</html>
|
|
60
|
+
</html>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { store, getContext } from '@wordpress/interactivity';
|
|
5
|
+
|
|
6
|
+
const { state } = store('{{slug}}', {
|
|
7
|
+
state: {
|
|
8
|
+
count: 0,
|
|
9
|
+
get toggleText() {
|
|
10
|
+
const ctx = getContext();
|
|
11
|
+
return ctx.isOpen ? 'Hide' : 'Show';
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
actions: {
|
|
15
|
+
increment() { state.count++; },
|
|
16
|
+
decrement() { state.count--; },
|
|
17
|
+
toggle() {
|
|
18
|
+
const ctx = getContext();
|
|
19
|
+
ctx.isOpen = !ctx.isOpen;
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { createRoot, useState, StrictMode } from '@wordpress/element';
|
|
5
|
+
|
|
6
|
+
const App = () => {
|
|
7
|
+
const [count, setCount] = useState(0);
|
|
8
|
+
const [isVisible, setIsVisible] = useState(false);
|
|
9
|
+
|
|
10
|
+
const toggleVisible = () => setIsVisible(!isVisible);
|
|
11
|
+
|
|
12
|
+
const toggleText = isVisible ? 'Hide' : 'Show';
|
|
13
|
+
|
|
14
|
+
const toggleStyle = {
|
|
15
|
+
display : isVisible ? 'block' : 'none'
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<div>
|
|
20
|
+
<h2>React Counter: {count}</h2>
|
|
21
|
+
|
|
22
|
+
<button onClick={() => setCount(count + 1)}>+</button>
|
|
23
|
+
|
|
24
|
+
<button onClick={() => setCount(count - 1)}>-</button>
|
|
25
|
+
|
|
26
|
+
<hr/>
|
|
27
|
+
|
|
28
|
+
<button onClick={toggleVisible}> {toggleText} </button>
|
|
29
|
+
|
|
30
|
+
<p style={toggleStyle}>
|
|
31
|
+
Hello from the React API! 🎉
|
|
32
|
+
</p>
|
|
33
|
+
</div>
|
|
34
|
+
);
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const container = document.getElementById('wrapper');
|
|
38
|
+
if (container) {
|
|
39
|
+
const root = createRoot(container);
|
|
40
|
+
root.render(<StrictMode><App/></StrictMode>);
|
|
41
|
+
}
|
|
@@ -10,7 +10,7 @@ export function Plugin (element, options) {
|
|
|
10
10
|
const PRIVATE = {}
|
|
11
11
|
|
|
12
12
|
// Collecting settings from html attribute
|
|
13
|
-
const ATTRIBUTE = 'plugin
|
|
13
|
+
const ATTRIBUTE = 'storepress-plugin' // html data-plugin-settings
|
|
14
14
|
|
|
15
15
|
const CLASSES = {
|
|
16
16
|
NEW: 'new-class',
|
|
@@ -86,4 +86,4 @@ export function Plugin (element, options) {
|
|
|
86
86
|
}
|
|
87
87
|
|
|
88
88
|
return init()
|
|
89
|
-
}
|
|
89
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { createStorePressPlugin } from '@storepress/utils';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Internal dependencies
|
|
8
|
+
*/
|
|
9
|
+
import { Plugin } from './Plugin';
|
|
10
|
+
|
|
11
|
+
const HtmlPlugin = createStorePressPlugin({
|
|
12
|
+
selector : '[data-storepress-plugin]',
|
|
13
|
+
options : {},
|
|
14
|
+
plugin : Plugin,
|
|
15
|
+
namespace : 'html',
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
HtmlPlugin.setup();
|
|
19
|
+
|
|
20
|
+
export default HtmlPlugin;
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
$default-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
|
|
6
6
|
|
|
7
|
-
:where([data-
|
|
7
|
+
:where([data-storepress-plugin]) {
|
|
8
8
|
font-family: $default-font;
|
|
9
9
|
|
|
10
10
|
@include plugin.init();
|
|
@@ -12,4 +12,4 @@ $default-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-San
|
|
|
12
12
|
& {
|
|
13
13
|
--custom-variable: 1px;
|
|
14
14
|
}
|
|
15
|
-
}
|
|
15
|
+
}
|