Skip to content

Commit

Permalink
chore: update project structure
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinchappell committed Oct 20, 2024
1 parent d432e8b commit a897736
Show file tree
Hide file tree
Showing 133 changed files with 1,271 additions and 225 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Nodejs v20
uses: actions/setup-node@v4
- uses: actions/setup-node@v4
with:
node-version: 20
node-version: 23
- name: Install dependencies
env:
CI: true
Expand Down
13 changes: 4 additions & 9 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@ on:
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node: [12]
steps:
- uses: actions/checkout@v2
- name: Set up Nodejs ${{ matrix.node }}
uses: actions/setup-node@v1
- uses: actions/setup-node@v4
with:
node-version: 23
- name: Install dependencies
env:
CI: true
Expand All @@ -30,12 +28,9 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npx semantic-release
- name: Build the new version for the demo
if: success()
run: npm run build
- name: Deploy - https://draggable.github.io/formeo/
if: success()
env:
GH_PAT: ${{ secrets.GH_TOKEN }}
BUILD_DIR: demo/
BUILD_DIR: dist/demo/
uses: maxheld83/ghpages@v0.2.1
5 changes: 2 additions & 3 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Nodejs v20
uses: actions/setup-node@v4
- uses: actions/setup-node@v4
with:
node-version: 20
node-version: 23
- name: Install dependencies
env:
CI: true
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@
"analyze": "webpack --mode production -p --progress --config tools/webpack.config --analyze",
"build": "npm-run-all -p build:icons build:formeo build:demo",
"build:formeo": "vite build --mode lib",
"build:formeo:watch": "npm run build:formeo -- --watch",
"build:demo": "vite build --mode demo",
"build:demo:watch": "vite build --mode demo --watch",
"build:icons": "node ./tools/generate-sprite",
"lint": "eslint ./src --ext .js || true",
"test": "node --experimental-test-snapshots --require ./tools/test-setup.cjs --test --no-warnings src/**/*.test.js",
Expand Down
6 changes: 3 additions & 3 deletions src/demo/index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html>
<html lang="en" xml:lang="en">

<head>
<meta charset="utf-8" />
Expand All @@ -24,7 +24,7 @@ <h2>Action Tester</h2>
-->
</div>
</div>
<nav>
<nav aria-label="Footer navigation">
<ul>
<li>
<label for="locale">Language</label>
Expand Down Expand Up @@ -52,7 +52,7 @@ <h2>Action Tester</h2>
</div>
</div>
<footer id="demo-footer">
<nav>
<nav aria-label="Footer navigation">
<ul>
<li>
<a href="https://github.com/Draggable/formeo" target="_blank" title="View project on GitHub">
Expand Down
5 changes: 3 additions & 2 deletions src/demo/js/demo.js → src/demo/js/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import './scripts'
import './scripts.js'
import '../sass/demo.scss'
import { editorOptions, renderOptions } from './options/index.js'
import { editorButtons } from './actionButtons.js'
import { editorEvents } from './events.js'
import { FormeoEditor, FormeoRenderer } from '../../js/index.js'

import { FormeoEditor, FormeoRenderer } from 'formeo'

const editor = new FormeoEditor(editorOptions)
const renderer = new FormeoRenderer(renderOptions)
Expand Down
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
104 changes: 104 additions & 0 deletions src/lib/js/common/helpers.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
'use strict'
import { unique } from './utils/index.mjs'
import { get } from './utils/object.mjs'
import { slugify } from './utils/string.mjs'

/**
* Tests if is whole number. returns false if n is Float
* @param {String|Number} n
*/
export const isInt = n => Number.isInteger(Number(n))

/**
* Finds the index of an element in its parent
* @param {NodeElement} node
* @param {NodeElement} parent
*/
export const indexOfNode = (node, parent) => {
const parentElement = parent || node.parentElement
const nodeList = Array.prototype.slice.call(parentElement.childNodes)
return nodeList.indexOf(node)
}

/**
* Orders an array of objects by specific attributes
* @param {Array} elements Array of element objects
* @param {Array} order array of keys to order objects by
* @param {String} path string path to property to order by
* @return {Array} Ordered Array of Element Objects
*/
export const orderObjectsBy = (elements, order, path) => {
// OR operator for path
const splitPath = path.split('||')
const newOrder = unique(order)
.map(key =>
elements.find(elem => {
const newPath = splitPath.find(p => !!get(elem, p))
return newPath && get(elem, newPath) === key
}),
)
.filter(Boolean)
const orderedElements = newOrder.concat(elements)

return unique(orderedElements)
}

/**
* @param {Array|NodeList} arr to be iterated
* @param {Function} cb
* @param {Context}
*/
export const forEach = (arr, cb, scope) => {
for (let i = 0; i < arr.length; i++) {
cb.call(scope, arr[i], i)
}
}

/**
* @param {Array|NodeList} arr to be iterated
* @param {Function} cb
* @return {Array} newArray
*/
export const map = (arr, cb) => {
const newArray = []
forEach(arr, (elem, i) => newArray.push(cb(elem, i)))

return newArray
}

export const safeAttrName = name => {
const safeAttr = {
className: 'class',
}

return safeAttr[name] || slugify(name)
}

export const capitalize = str => str.replace(/\b\w/g, m => m.toUpperCase())

// Expensive recursive object copy
export const copyObj = obj => window.JSON.parse(window.JSON.stringify(obj))

// subtract the contents of 1 array from another
export const subtract = (arr, from) => from.filter(a => !~arr.indexOf(a))

export const isIE = () => window.navigator.userAgent.indexOf('MSIE ') !== -1

export const helpers = {
capitalize,
safeAttrName,
forEach,
copyObj,

// basic map that can be used on nodeList
map,
subtract,
indexOfNode,
isInt,
get,

orderObjectsBy,
isIE,
}

export default helpers
File renamed without changes.
2 changes: 1 addition & 1 deletion src/js/common/loaders.js → src/lib/js/common/loaders.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,6 @@ export const ajax = (file, callback, onError = noop) => {
return new Promise((resolve, reject) => {
return fetch(file)
.then(data => resolve(callback ? callback(data) : data))
.catch(err => reject(onError(err)))
.catch(err => reject(new Error(onError(err))))
})
}
Loading

0 comments on commit a897736

Please sign in to comment.