@storepress/create-plugin-html 0.0.5 → 0.1.0
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 -7
- package/index.js +136 -125
- package/package.json +1 -1
- package/plugin-templates/.eslintrc.js.mustache +1 -0
- package/plugin-templates/.github/workflows/release.yaml.mustache +9 -0
- package/plugin-templates/.gitignore.mustache +1 -1
- package/plugin-templates/README.md.mustache +4 -1
- package/plugin-templates/changelog.txt.mustache +12 -0
- package/plugin-templates/index-module.html.mustache +30 -0
- package/plugin-templates/index.html.mustache +47 -7
- package/plugin-templates/src/interactive/index.js.mustache +19 -0
- package/plugin-templates/src/react/index.js.mustache +38 -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 +60 -0
- package/plugin-templates/tools/packages-install.js.mustache +98 -0
- package/plugin-templates/tools/packages-update.js.mustache +90 -0
- package/plugin-templates/tools/webpack-helpers.js.mustache +61 -39
- package/plugin-templates/tools/webpack.config.externals.js.mustache +131 -0
- package/plugin-templates/webpack.config.js.mustache +99 -83
- package/block-templates/index.js.mustache +0 -20
- 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,17 +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 @wordpress/create-block@latest --template @storepress/create-plugin-html my-extension-name
|
|
10
|
+
npx -y @wordpress/create-block@latest --template @storepress/create-plugin-html --no-wp-scripts 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
|
-
|
|
17
|
-
npm
|
|
18
|
-
|
|
19
|
-
npm run build # Build the javascript
|
|
20
|
-
npx @wp-now/wp-now start # Start Wordpress environment
|
|
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
|
|
21
19
|
```
|
|
22
20
|
|
|
23
21
|
## Development
|
|
@@ -25,7 +23,7 @@ npx @wp-now/wp-now start # Start Wordpress environment
|
|
|
25
23
|
For development on this tool itself, you can also install from a local directory.
|
|
26
24
|
|
|
27
25
|
```bash
|
|
28
|
-
npx @wordpress/create-block@latest --template ./path/to/storepress/create-plugin-html my-extension-name
|
|
26
|
+
npx -y @wordpress/create-block@latest --template ./path/to/storepress/create-plugin-html --no-wp-scripts my-html-extension-name && cd "$_"
|
|
29
27
|
```
|
|
30
28
|
|
|
31
29
|
### Add Tests
|
package/index.js
CHANGED
|
@@ -1,141 +1,152 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
const {
|
|
4
|
+
const {join} = require('path')
|
|
5
5
|
|
|
6
6
|
// two-words
|
|
7
|
-
function kebabCase
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
function kebabCase(input) {
|
|
8
|
+
const regex = /[-._\s+]/gi
|
|
9
|
+
return input.replace(regex, '-').toLowerCase()
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
function constantCase
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
function constantCase(input) {
|
|
13
|
+
const regex = /[-._\s+]/gi
|
|
14
|
+
return input.replace(regex, '_').toUpperCase()
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
function pascalStorePress
|
|
18
|
-
|
|
17
|
+
function pascalStorePress(input) {
|
|
18
|
+
return 'storepress' === input ? 'StorePress' : input
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
function pascalCase
|
|
22
|
-
|
|
21
|
+
function pascalCase(input) {
|
|
22
|
+
return (input.match(/[a-zA-Z0-9]+/g) || []).map(w => `${w.charAt(0).toUpperCase()}${w.slice(1)}`).join('')
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
module.exports = {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
26
|
+
defaultValues : {
|
|
27
|
+
folderName : 'src',
|
|
28
|
+
namespace : 'storepress',
|
|
29
|
+
slug : 'plugin',
|
|
30
|
+
version : '0.0.1',
|
|
31
|
+
title : 'StorePress Plugin',
|
|
32
|
+
description : 'A StorePress Plugin',
|
|
33
|
+
author : 'EmranAhmed',
|
|
34
|
+
dashicon : 'pets',
|
|
35
|
+
category : 'storepress',
|
|
36
|
+
attributes : {},
|
|
37
|
+
license : 'GPL-2.0-or-later',
|
|
38
|
+
customScripts : {
|
|
39
|
+
'postinstall' : 'git init -q && rimraf .husky && npx husky init && echo "npx lint-staged" > .husky/pre-commit',
|
|
40
|
+
|
|
41
|
+
'prebuild' : 'rimraf build && npm run external:build',
|
|
42
|
+
'build' : 'wp-scripts build --webpack-copy-php --experimental-modules',
|
|
43
|
+
|
|
44
|
+
'check-engines' : 'wp-scripts check-engines',
|
|
45
|
+
'check-licenses' : 'wp-scripts check-licenses',
|
|
46
|
+
|
|
47
|
+
'format' : 'wp-scripts format ./src',
|
|
48
|
+
'format:all' : 'npm run format:php && npm run format:css && npm run format:js',
|
|
49
|
+
'format:js' : 'wp-scripts format \'./src/**/*.js\'',
|
|
50
|
+
'format:css' : 'wp-scripts format \'./src/**/*.scss\'',
|
|
51
|
+
|
|
52
|
+
'lint:css' : 'wp-scripts lint-style \'./src/**/*.scss\'',
|
|
53
|
+
'lint:css:report' : 'npm run lint:css -- --output-file scss-report.txt',
|
|
54
|
+
'lint:css:fix' : 'npm run lint:css -- --fix',
|
|
55
|
+
|
|
56
|
+
'lint:js' : 'wp-scripts lint-js --format=pretty \'./src/**/*.js\'',
|
|
57
|
+
'lint:js:report' : 'npm run lint:js -- --format html --output-file lint-report.html',
|
|
58
|
+
'lint:js:fix' : 'npm run lint:js -- --fix',
|
|
59
|
+
|
|
60
|
+
'lint:md:docs' : 'wp-scripts lint-md-docs',
|
|
61
|
+
'lint:pkg-json' : 'wp-scripts lint-pkg-json',
|
|
62
|
+
|
|
63
|
+
"packages-install:all" : "node ./tools/packages-install.js",
|
|
64
|
+
"packages-update:storepress" : "node ./tools/packages-update.js",
|
|
65
|
+
|
|
66
|
+
"packages-update" : "wp-scripts packages-update && npm run packages-update:storepress && npm run packages-install:all",
|
|
67
|
+
|
|
68
|
+
'prepackage' : 'rimraf ${npm_package_name}.zip && npm run build',
|
|
69
|
+
'package' : 'node ./tools/package.js',
|
|
70
|
+
|
|
71
|
+
'plugin-zip' : 'npm run package -- --zip',
|
|
72
|
+
|
|
73
|
+
'test:e2e' : 'wp-scripts test-e2e',
|
|
74
|
+
'test:unit' : 'wp-scripts test-unit-js',
|
|
75
|
+
|
|
76
|
+
"external:dev": "wp-scripts start --no-watch --config tools/webpack.config.externals.js --experimental-modules --webpack-no-externals",
|
|
77
|
+
"external:build": "wp-scripts build --config tools/webpack.config.externals.js --experimental-modules --webpack-no-externals",
|
|
78
|
+
|
|
79
|
+
'prestart' : 'rimraf build && npm run external:dev',
|
|
80
|
+
'start' : 'wp-scripts start --webpack-copy-php --experimental-modules',
|
|
81
|
+
},
|
|
82
|
+
npmDependencies : [
|
|
83
|
+
'@storepress/utils',
|
|
84
|
+
'@wordpress/element',
|
|
85
|
+
'@wordpress/interactivity',
|
|
86
|
+
],
|
|
87
|
+
npmDevDependencies : [
|
|
88
|
+
'@wordpress/scripts',
|
|
89
|
+
'@woocommerce/dependency-extraction-webpack-plugin',
|
|
90
|
+
'@woocommerce/eslint-plugin',
|
|
91
|
+
'@wordpress/base-styles',
|
|
92
|
+
'@wordpress/dependency-extraction-webpack-plugin',
|
|
93
|
+
'eslint-plugin-you-dont-need-lodash-underscore',
|
|
94
|
+
'husky',
|
|
95
|
+
'lint-staged',
|
|
96
|
+
"prettier@npm:wp-prettier",
|
|
97
|
+
'fs-extra',
|
|
98
|
+
'webpack-remove-empty-scripts',
|
|
99
|
+
'eslint-plugin-prettier@5.2.1',
|
|
100
|
+
'eslint-formatter-pretty',
|
|
101
|
+
'rimraf',
|
|
102
|
+
],
|
|
103
|
+
customPackageJSON : {
|
|
104
|
+
'publishConfig' : {
|
|
105
|
+
'access' : 'public',
|
|
106
|
+
},
|
|
107
|
+
'sideEffects' : [
|
|
108
|
+
'src/**',
|
|
109
|
+
],
|
|
110
|
+
'main' : 'build/index.js',
|
|
111
|
+
'module' : 'src/index.js',
|
|
112
|
+
'files' : [
|
|
113
|
+
'src/**',
|
|
114
|
+
],
|
|
115
|
+
'zip' : [
|
|
116
|
+
'build/**',
|
|
117
|
+
'index.html',
|
|
118
|
+
'index-module.html',
|
|
119
|
+
],
|
|
120
|
+
},
|
|
121
|
+
transformer : (view) => {
|
|
122
|
+
const todayDate = new Date().toJSON().slice(0, 10)
|
|
123
|
+
const pascaleNamespace = pascalCase(pascalStorePress(view.namespace))
|
|
124
|
+
const constantNamespace = constantCase(view.namespace)
|
|
125
|
+
const kebabNamespace = kebabCase(view.namespace)
|
|
126
|
+
const constantSlug = constantCase(view.slug) // TWO_WORDS
|
|
127
|
+
const kebabSlug = kebabCase(view.slug) // two-words
|
|
128
|
+
const pascaleSlug = pascalCase(pascalStorePress(view.slug)) // 'TwoWords'
|
|
129
|
+
return {
|
|
130
|
+
...view,
|
|
131
|
+
name : `@${kebabNamespace}/${kebabSlug}`,
|
|
132
|
+
todayDate : todayDate,
|
|
133
|
+
constantNamespace : constantNamespace,
|
|
134
|
+
kebabNamespace : kebabNamespace,
|
|
135
|
+
pascaleNamespace : pascaleNamespace,
|
|
136
|
+
|
|
137
|
+
constantSlug : constantSlug,
|
|
138
|
+
kebabSlug : kebabSlug,
|
|
139
|
+
pascaleSlug : pascaleSlug,
|
|
140
|
+
|
|
141
|
+
GITHUB_REPOSITORY_NAME : '${{ github.event.repository.name }}',
|
|
142
|
+
GITHUB_RELEASE_NAME : '${{ env.RELEASE_NAME }}',
|
|
143
|
+
GITHUB_RELEASE_TAG : '${{ env.RELEASE_TAG }}',
|
|
144
|
+
GITHUB_TOKEN : '${{ secrets.GITHUB_TOKEN }}',
|
|
145
|
+
GITHUB_PAGE_URL : '${{ steps.deployment.outputs.page_url }}',
|
|
146
|
+
GITHUB_CHANGELOG_CONTENT : "${{ steps.changelog.outputs.changelog }}",
|
|
147
|
+
}
|
|
148
|
+
},
|
|
74
149
|
},
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
],
|
|
78
|
-
npmDevDependencies: [
|
|
79
|
-
'@wordpress/scripts',
|
|
80
|
-
'@woocommerce/dependency-extraction-webpack-plugin',
|
|
81
|
-
'@woocommerce/eslint-plugin',
|
|
82
|
-
'@wordpress/base-styles',
|
|
83
|
-
'@wordpress/dependency-extraction-webpack-plugin',
|
|
84
|
-
'eslint-plugin-you-dont-need-lodash-underscore',
|
|
85
|
-
'husky',
|
|
86
|
-
'lint-staged',
|
|
87
|
-
"prettier@npm:wp-prettier",
|
|
88
|
-
'fs-extra',
|
|
89
|
-
'webpack-remove-empty-scripts',
|
|
90
|
-
'eslint-plugin-prettier@5.2.1',
|
|
91
|
-
'eslint-formatter-pretty',
|
|
92
|
-
'rimraf',
|
|
93
|
-
],
|
|
94
|
-
customPackageJSON: {
|
|
95
|
-
'publishConfig': {
|
|
96
|
-
'access': 'public',
|
|
97
|
-
},
|
|
98
|
-
'sideEffects': [
|
|
99
|
-
'src/**',
|
|
100
|
-
],
|
|
101
|
-
'main': 'build/index.js',
|
|
102
|
-
'module': 'src/index.js',
|
|
103
|
-
'files': [
|
|
104
|
-
'src/**',
|
|
105
|
-
],
|
|
106
|
-
'zip': [
|
|
107
|
-
'build/**',
|
|
108
|
-
'index.html',
|
|
109
|
-
'global-style.css',
|
|
110
|
-
],
|
|
111
|
-
},
|
|
112
|
-
transformer: (view) => {
|
|
113
|
-
const todayDate = new Date().toJSON().slice(0, 10)
|
|
114
|
-
const pascaleNamespace = pascalCase(pascalStorePress(view.namespace))
|
|
115
|
-
const constantNamespace = constantCase(view.namespace)
|
|
116
|
-
const kebabNamespace = kebabCase(view.namespace)
|
|
117
|
-
const constantSlug = constantCase(view.slug) // TWO_WORDS
|
|
118
|
-
const kebabSlug = kebabCase(view.slug) // two-words
|
|
119
|
-
const pascaleSlug = pascalCase(pascalStorePress(view.slug)) // 'TwoWords'
|
|
120
|
-
return {
|
|
121
|
-
...view,
|
|
122
|
-
name: `@${kebabNamespace}/${kebabSlug}`,
|
|
123
|
-
todayDate: todayDate,
|
|
124
|
-
constantNamespace: constantNamespace,
|
|
125
|
-
kebabNamespace: kebabNamespace,
|
|
126
|
-
pascaleNamespace: pascaleNamespace,
|
|
127
|
-
|
|
128
|
-
constantSlug: constantSlug,
|
|
129
|
-
kebabSlug: kebabSlug,
|
|
130
|
-
pascaleSlug: pascaleSlug,
|
|
131
|
-
GITHUB_REPOSITORY_NAME: '${{ github.event.repository.name }}',
|
|
132
|
-
GITHUB_RELEASE_NAME: '${{ env.RELEASE_NAME }}',
|
|
133
|
-
GITHUB_RELEASE_TAG: '${{ env.RELEASE_TAG }}',
|
|
134
|
-
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}',
|
|
135
|
-
GITHUB_PAGE_URL: '${{ steps.deployment.outputs.page_url }}',
|
|
136
|
-
}
|
|
137
|
-
},
|
|
138
|
-
},
|
|
139
|
-
pluginTemplatesPath: join(__dirname, 'plugin-templates'),
|
|
140
|
-
blockTemplatesPath: join(__dirname, 'block-templates'),
|
|
150
|
+
pluginTemplatesPath : join(__dirname, 'plugin-templates'),
|
|
151
|
+
blockTemplatesPath : join(__dirname, 'block-templates'),
|
|
141
152
|
}
|
package/package.json
CHANGED
|
@@ -161,6 +161,7 @@ module.exports = {
|
|
|
161
161
|
'lodash',
|
|
162
162
|
'jquery',
|
|
163
163
|
'@storepress/utils',
|
|
164
|
+
'@storepress/html-plugin', // See: getWebPackAlias() from tools/webpack-helpers.js
|
|
164
165
|
'@utils', // See: getWebPackAlias() from tools/webpack-helpers.js
|
|
165
166
|
],
|
|
166
167
|
'import/resolver': {
|
|
@@ -25,6 +25,7 @@ jobs:
|
|
|
25
25
|
# - Make Zip
|
|
26
26
|
# - Get Release Version
|
|
27
27
|
# - Get Release Filename
|
|
28
|
+
# - Get Changelog
|
|
28
29
|
# - Make Release
|
|
29
30
|
|
|
30
31
|
build:
|
|
@@ -53,11 +54,19 @@ jobs:
|
|
|
53
54
|
run: |
|
|
54
55
|
echo "RELEASE_NAME=$(node -p -e "require('./package.json').name")" >> $GITHUB_ENV
|
|
55
56
|
|
|
57
|
+
- name: "Get Changelog"
|
|
58
|
+
id: changelog
|
|
59
|
+
run: |
|
|
60
|
+
echo "changelog<<EOF" >> $GITHUB_OUTPUT
|
|
61
|
+
node ./tools/changelog.js >> $GITHUB_OUTPUT
|
|
62
|
+
echo "EOF" >> $GITHUB_OUTPUT
|
|
63
|
+
|
|
56
64
|
- name: "Make Release"
|
|
57
65
|
uses: softprops/action-gh-release@v2
|
|
58
66
|
with:
|
|
59
67
|
files: ./{{ GITHUB_RELEASE_NAME }}.zip
|
|
60
68
|
make_latest: true
|
|
61
69
|
name: Release - v{{ GITHUB_RELEASE_TAG }}
|
|
70
|
+
body: {{ GITHUB_CHANGELOG_CONTENT }}
|
|
62
71
|
env:
|
|
63
72
|
GITHUB_TOKEN: {{ GITHUB_TOKEN }}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
*** {{title}} ***
|
|
2
|
+
|
|
3
|
+
2023-09-30 - version 1.0.0
|
|
4
|
+
* Added - add msg
|
|
5
|
+
* Update - update msg
|
|
6
|
+
* Fixed - fix msg
|
|
7
|
+
* Tweak - what we tweak
|
|
8
|
+
* Enhancement - add action / add filter
|
|
9
|
+
* Performance - if any performance added
|
|
10
|
+
|
|
11
|
+
2023-09-18 - version 1.0.0
|
|
12
|
+
* Initial release
|
|
@@ -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,18 +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
|
-
<
|
|
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"/>
|
|
9
17
|
</head>
|
|
10
18
|
|
|
11
19
|
<body>
|
|
12
20
|
|
|
13
|
-
<
|
|
14
|
-
|
|
21
|
+
<h1>Example of WordPress Package Usage as Standalone</h1>
|
|
22
|
+
<div id="wrapper"></div>
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
<div
|
|
26
|
+
data-wp-interactive="my-app"
|
|
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>
|
|
15
41
|
</div>
|
|
16
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
|
+
|
|
17
54
|
<script src="./build/storepress-utils.js"></script>
|
|
18
|
-
<script src="./build/
|
|
55
|
+
<script src="./build/script-example.js"></script>
|
|
56
|
+
|
|
57
|
+
<script type="module" src="./build/interactive-example.js"></script>
|
|
58
|
+
|
|
19
59
|
</body>
|
|
20
|
-
</html>
|
|
60
|
+
</html>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { store, getContext } from '@wordpress/interactivity';
|
|
2
|
+
|
|
3
|
+
const { state } = store('my-app', {
|
|
4
|
+
state: {
|
|
5
|
+
count: 0,
|
|
6
|
+
get toggleText() {
|
|
7
|
+
const ctx = getContext();
|
|
8
|
+
return ctx.isOpen ? 'Hide' : 'Show';
|
|
9
|
+
},
|
|
10
|
+
},
|
|
11
|
+
actions: {
|
|
12
|
+
increment() { state.count++; },
|
|
13
|
+
decrement() { state.count--; },
|
|
14
|
+
toggle() {
|
|
15
|
+
const ctx = getContext();
|
|
16
|
+
ctx.isOpen = !ctx.isOpen;
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { createRoot, useState, StrictMode } from '@wordpress/element';
|
|
2
|
+
|
|
3
|
+
const App = () => {
|
|
4
|
+
const [count, setCount] = useState(0);
|
|
5
|
+
const [isVisible, setIsVisible] = useState(false);
|
|
6
|
+
|
|
7
|
+
const toggleVisible = () => setIsVisible(!isVisible);
|
|
8
|
+
|
|
9
|
+
const toggleText = isVisible ? 'Hide' : 'Show';
|
|
10
|
+
|
|
11
|
+
const toggleStyle = {
|
|
12
|
+
display : isVisible ? 'block' : 'none'
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return (
|
|
16
|
+
<div>
|
|
17
|
+
<h2>React Counter: {count}</h2>
|
|
18
|
+
|
|
19
|
+
<button onClick={() => setCount(count + 1)}>+</button>
|
|
20
|
+
|
|
21
|
+
<button onClick={() => setCount(count - 1)}>-</button>
|
|
22
|
+
|
|
23
|
+
<hr/>
|
|
24
|
+
|
|
25
|
+
<button onClick={toggleVisible}> {toggleText} </button>
|
|
26
|
+
|
|
27
|
+
<p style={toggleStyle}>
|
|
28
|
+
Hello from the React API! 🎉
|
|
29
|
+
</p>
|
|
30
|
+
</div>
|
|
31
|
+
);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const container = document.getElementById('wrapper');
|
|
35
|
+
if (container) {
|
|
36
|
+
const root = createRoot(container);
|
|
37
|
+
root.render(<StrictMode><App/></StrictMode>);
|
|
38
|
+
}
|
|
@@ -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
|
+
}
|