@storepress/create-plugin-html 0.0.1 → 0.0.3

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.
@@ -10,24 +10,10 @@ export function Plugin (element, options) {
10
10
  const PRIVATE = {}
11
11
 
12
12
  // Collecting settings from html attribute
13
- const ATTRIBUTE = 'plugin-settings' //
13
+ const ATTRIBUTE = 'plugin-settings' // html data-plugin-settings
14
14
 
15
- const CLASSES = {}
16
-
17
- // Do what you need and return expose fn.
18
- const init = () => {
19
- this.$element = element
20
- this.settings = {
21
- ...DEFAULTS, ...options, ...getOptionsFromAttribute(this.$element, ATTRIBUTE), ...PRIVATE,
22
- }
23
-
24
- initial()
25
-
26
- addClasses()
27
-
28
- addEvents()
29
-
30
- return expose()
15
+ const CLASSES = {
16
+ NEW: 'new-class',
31
17
  }
32
18
 
33
19
  const noop = () => () => {}
@@ -41,27 +27,31 @@ export function Plugin (element, options) {
41
27
  }
42
28
 
43
29
  const initial = () => {
44
- console.log(this.settings)
30
+ console.log(this.settings)
45
31
  triggerEvent(this.$element, 'afterInit', {})
46
32
  }
47
33
 
48
- const cssVariableIsTrue = (string) => {
49
- return string === 'true' || string === '1' || string === 'yes'
50
- }
51
34
  const addClasses = () => {
52
-
35
+ this.$element.classList.add(CLASSES.NEW)
53
36
  }
54
37
 
55
- const removeClasses = () => {
38
+ const addEvents = () => {
56
39
 
57
- }
40
+ this.$element.addEventListener('click', (e) => {
58
41
 
59
- const addEvents = () => {
42
+ console.log(e.target.getAttribute('class'))
43
+
44
+ }, { signal: this.signal, passive: true })
60
45
 
61
46
  }
62
47
 
63
48
  const removeEvents = () => {
64
49
 
50
+ this.controller.abort('Reset')
51
+ }
52
+
53
+ const removeClasses = () => {
54
+ this.$element.classList.remove(CLASSES.NEW)
65
55
  }
66
56
 
67
57
  const reset = () => {
@@ -69,10 +59,29 @@ export function Plugin (element, options) {
69
59
  removeEvents()
70
60
  }
71
61
 
72
- // Expose to public.
62
+ // Expose reset to public.
73
63
  const expose = () => ({
74
- removeEvents, reset,
64
+ reset,
75
65
  })
76
66
 
67
+ // Do what you need and return expose fn.
68
+ const init = () => {
69
+ this.$element = element
70
+ this.settings = {
71
+ ...DEFAULTS, ...options, ...getOptionsFromAttribute(this.$element, ATTRIBUTE), ...PRIVATE,
72
+ }
73
+
74
+ this.controller = new AbortController()
75
+ this.signal = this.controller.signal
76
+
77
+ initial()
78
+
79
+ addClasses()
80
+
81
+ addEvents()
82
+
83
+ return expose()
84
+ }
85
+
77
86
  return init()
78
87
  }
@@ -1,64 +1,89 @@
1
1
  /**
2
2
  * External dependencies
3
3
  */
4
- import { createPluginInstance, triggerEvent } from '@storepress/utils'
4
+ import { createPluginInstance, triggerEvent, getPluginInstance } from '@storepress/utils'
5
5
 
6
6
  /**
7
7
  * Internal dependencies
8
8
  */
9
- import { Plugin } from './Plugin'
9
+ import { Plugin as Instance } from './Plugin'
10
10
 
11
- export default function StorePressPlugin () {
12
- const StorePressPlugin = {
13
- getInstance (element) {
14
- return createPluginInstance(element, false, Plugin)
11
+ export default function {{pascaleSlug}}Plugin () {
12
+ const Plugin = {
13
+ createInstance (element, options) {
14
+ return createPluginInstance(element, options, Instance)
15
15
  },
16
16
 
17
- initWith ($selector = '[data-plugin-settings]') {
18
- for (const { element, unregister } of this.getInstance($selector)) {
19
- element.addEventListener('destroy', unregister)
20
- }
17
+ getInstance (element) {
18
+ return getPluginInstance(element)
21
19
  },
22
20
 
23
- init () {
24
- for (const { element, unregister } of this.getInstance('[data-plugin-settings]')) {
25
- element.addEventListener('destroy', unregister)
21
+ init ($selector, options) {
22
+ for (const { element, reset } of this.createInstance($selector, options)) {
23
+ element.addEventListener('destroy', reset)
26
24
  }
27
25
  },
28
26
 
29
- destroy () {
30
- for (const { destroy } of this.getInstance('[data-plugin-settings]')) {
27
+ destroy ($selector) {
28
+ for (const { destroy } of this.getInstance($selector)) {
31
29
  destroy()
32
30
  }
33
31
  },
34
32
 
35
- destroyWith ($selector = '[data-plugin-settings]') {
36
- for (const { destroy } of this.getInstance($selector)) {
37
- destroy()
38
- }
33
+ reload ($selector, options) {
34
+ this.destroy($selector)
35
+ this.init($selector, options)
39
36
  },
40
37
  }
41
38
 
42
- document.addEventListener('storepress_plugin_init', () => {
43
- StorePressPlugin.init()
44
- })
39
+ document.addEventListener('storepress_plugin_init', (event) => {
45
40
 
46
- document.addEventListener('storepress_plugin_destroy', () => {
47
- StorePressPlugin.destroy()
48
- })
41
+ const defaultSettings = {}
42
+ const settings = { ...defaultSettings, ...event.detail?.settings }
43
+ const element = event.detail?.element
49
44
 
50
- document.addEventListener('storepress_plugin_init_with', (event) => {
51
- const selector = event.detail?.element
52
- StorePressPlugin.initWith(selector)
53
- })
45
+ if (Array.isArray(element)) {
46
+ for (const el of element) {
47
+ Plugin.init(el, settings)
48
+ }
49
+ } else {
50
+ Plugin.init(element, settings)
51
+ }
52
+ }, { passive: true })
54
53
 
55
- document.addEventListener('storepress_plugin_destroy_with', (event) => {
56
- const selector = event.detail?.element
57
- StorePressPlugin.destroyWith(selector)
58
- })
54
+ document.addEventListener('storepress_plugin_destroy', (event) => {
55
+
56
+ const element = event.detail?.element
57
+
58
+ if (Array.isArray(element)) {
59
+ for (const el of element) {
60
+ Plugin.destroy(el)
61
+ }
62
+ } else {
63
+ Plugin.destroy(element)
64
+ }
65
+
66
+ }, { passive: true })
67
+
68
+ document.addEventListener('storepress_plugin_reload', (event) => {
69
+ const defaultSettings = {}
70
+ const settings = { ...defaultSettings, ...event.detail?.settings }
71
+ const element = event.detail?.element
72
+
73
+ if (Array.isArray(element)) {
74
+ for (const el of element) {
75
+ Plugin.reload(el, settings)
76
+ }
77
+ } else {
78
+ Plugin.reload(element, settings)
79
+ }
80
+ }, { passive: true })
59
81
  }
60
82
 
61
83
  document.addEventListener('DOMContentLoaded', () => {
62
- StorePressPlugin()
63
- triggerEvent(document, 'storepress_plugin_init')
84
+ {{pascaleSlug}}Plugin()
85
+ triggerEvent(document, 'storepress_plugin_init', {
86
+ element: ['[data-plugin-settings]'],
87
+ settings: {},
88
+ })
64
89
  })
package/index.js CHANGED
@@ -27,7 +27,7 @@ module.exports = {
27
27
  folderName: 'src',
28
28
  namespace: 'storepress',
29
29
  slug: 'plugin',
30
- version: '0.1.0',
30
+ version: '0.0.1',
31
31
  title: 'StorePress Plugin',
32
32
  description: 'A StorePress Plugin',
33
33
  author: 'EmranAhmed',
@@ -84,6 +84,7 @@ module.exports = {
84
84
  'eslint-plugin-you-dont-need-lodash-underscore',
85
85
  'husky',
86
86
  'lint-staged',
87
+ "prettier@npm:wp-prettier@latest",
87
88
  'fs-extra',
88
89
  'webpack-remove-empty-scripts',
89
90
  'eslint-plugin-prettier',
@@ -96,20 +97,6 @@ module.exports = {
96
97
  'sideEffects': [
97
98
  'src/**',
98
99
  ],
99
- 'lint-staged': {
100
- './src/**/*.scss': [
101
- 'npm run lint:css',
102
- ],
103
- './src/**/*.{js,ts,tsx}': [
104
- 'npm run lint:js',
105
- ],
106
- './*.md': [
107
- 'npm run lint:md:docs',
108
- ],
109
- './package.json': [
110
- 'npm run lint:pkg-json',
111
- ],
112
- },
113
100
  'main': 'build/index.js',
114
101
  'module': 'src/index.js',
115
102
  'files': [
@@ -127,6 +114,7 @@ module.exports = {
127
114
  const kebabNamespace = kebabCase(view.namespace)
128
115
  const constantSlug = constantCase(view.slug) // TWO_WORDS
129
116
  const kebabSlug = kebabCase(view.slug) // two-words
117
+ const pascaleSlug = pascalCase(pascalStorePress(view.slug)) // 'TwoWords'
130
118
  return {
131
119
  ...view,
132
120
  todayDate: todayDate,
@@ -136,6 +124,12 @@ module.exports = {
136
124
 
137
125
  constantSlug: constantSlug,
138
126
  kebabSlug: kebabSlug,
127
+ pascaleSlug: pascaleSlug,
128
+ GITHUB_REPOSITORY_NAME: '${{ github.event.repository.name }}',
129
+ GITHUB_RELEASE_NAME: '${{ env.RELEASE_NAME }}',
130
+ GITHUB_RELEASE_TAG: '${{ env.RELEASE_TAG }}',
131
+ GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}',
132
+ GITHUB_PAGE_URL: '${{ steps.deployment.outputs.page_url }}',
139
133
  }
140
134
  },
141
135
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storepress/create-plugin-html",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "A template to be used with `@wordpress/create-block` to create a StorePress HTML based JS Extension.",
5
5
  "author": "StorePress",
6
6
  "main": "index.js",
@@ -26,27 +26,27 @@ jobs:
26
26
  deploy:
27
27
  environment:
28
28
  name: github-pages
29
- url: ${{ steps.deployment.outputs.page_url }}
29
+ url: {{ GITHUB_PAGE_URL }}
30
30
  runs-on: ubuntu-latest
31
31
  steps:
32
- - name: Checkout
32
+ - name: "Checkout"
33
33
  uses: actions/checkout@v4
34
- # Set up Node
35
- - name: Setup Node
34
+
35
+ - name: "Setup Node"
36
36
  uses: actions/setup-node@v4
37
37
  with:
38
- node-version: 18
39
- - name: Install and Build
38
+ node-version: '20.x'
39
+
40
+ - name: "Install and Build"
40
41
  run: |
41
42
  npm install
42
43
  npm run build
43
- #- name: Setup Pages
44
- # uses: actions/configure-pages@v5
45
- - name: Upload artifact
44
+ rm -rf node_modules
45
+
46
+ - name: "Upload Page Contents"
46
47
  uses: actions/upload-pages-artifact@v3
47
48
  with:
48
- # Upload entire repository
49
49
  path: '.'
50
- - name: Deploy to GitHub Pages
50
+ - name: "Deploy to GitHub Pages"
51
51
  id: deployment
52
52
  uses: actions/deploy-pages@v4
@@ -10,23 +10,22 @@ on:
10
10
  permissions: write-all
11
11
 
12
12
  env:
13
- REPOSITORY_NAME: ${{ github.event.repository.name }}
13
+ REPOSITORY_NAME: {{ GITHUB_REPOSITORY_NAME }}
14
14
 
15
15
  name: Release
16
16
 
17
17
  jobs:
18
18
 
19
-
20
19
  # Build distribution release.
21
20
  #
22
21
  # Performs the following steps:
23
- # - Checks out the repository.
24
- # - Set up PHP.
25
- # - Install PHP Dependencies.
26
- # - Setup and Install Node.js.
27
- # - Make Zip.
28
- # - Upload Release.
29
-
22
+ # - Checks out the repository
23
+ # - Setup and Install Node.js
24
+ # - NPM Install
25
+ # - Make Zip
26
+ # - Get Release Version
27
+ # - Get Release Filename
28
+ # - Make Release
30
29
 
31
30
  build:
32
31
  name: Release
@@ -39,24 +38,26 @@ jobs:
39
38
  uses: actions/setup-node@v4
40
39
  with:
41
40
  node-version: '20.x'
42
- - run: npm clean-install
41
+
42
+ - name: "NPM Install"
43
+ run: npm install
43
44
 
44
45
  - name: "Make Zip"
45
46
  run: npm run plugin-zip --if-present
46
47
 
47
- - name: "Get release version."
48
+ - name: "Get Release Version"
48
49
  run: |
49
50
  echo "RELEASE_TAG=$(node -p -e "require('./package.json').version")" >> $GITHUB_ENV
50
51
 
51
- - name: "Get release file base name."
52
+ - name: "Get Release Filename"
52
53
  run: |
53
54
  echo "RELEASE_NAME=$(node -p -e "require('./package.json').name")" >> $GITHUB_ENV
54
55
 
55
- - name: "Upload Release"
56
+ - name: "Make Release"
56
57
  uses: softprops/action-gh-release@v2
57
58
  with:
58
- files: ./${{ env.RELEASE_NAME }}.zip
59
+ files: ./{{ GITHUB_RELEASE_NAME }}.zip
59
60
  make_latest: true
60
- name: Release - v${{ env.RELEASE_TAG }}
61
+ name: Release - v{{ GITHUB_RELEASE_TAG }}
61
62
  env:
62
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
63
+ GITHUB_TOKEN: {{ GITHUB_TOKEN }}
@@ -1 +1 @@
1
-
1
+ package-lock=false
@@ -0,0 +1,6 @@
1
+ module.exports = {
2
+ './package.json': ['npm run lint:pkg-json'],
3
+ './*.md': ['npm run lint:md:docs'],
4
+ './src/**/*.scss': ['npm run lint:css'],
5
+ './src/**/*.{js,ts,tsx}': ['npm run lint:js'],
6
+ };