neo.mjs 4.0.39 → 4.0.40

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.
@@ -0,0 +1,85 @@
1
+ import autoprefixer from 'autoprefixer';
2
+ import chalk from 'chalk';
3
+ import fs from 'fs-extra';
4
+ import path from 'path';
5
+ import postcss from 'postcss';
6
+ import sass from 'sass';
7
+
8
+ const cwd = process.cwd(),
9
+ requireJson = path => JSON.parse(fs.readFileSync((path))),
10
+ packageJson = requireJson(path.resolve(cwd, 'package.json')),
11
+ neoPath = packageJson.name === 'neo.mjs' ? './' : './node_modules/neo.mjs/',
12
+ mixinPath = path.resolve(neoPath, 'resources/scss/mixins/_all.scss'),
13
+ scssPath = path.resolve(neoPath, 'resources/scss');
14
+
15
+ fs.watch(scssPath, {
16
+ recursive: true
17
+ }, (eventType, filename) => {
18
+ if (filename.endsWith('.scss')) {
19
+ switch (eventType) {
20
+ case 'change': {
21
+ buildFile(filename);
22
+ }
23
+ }
24
+ }
25
+ });
26
+
27
+ function buildFile(filename) {
28
+ console.log('start processing', filename);
29
+
30
+ let filePath = path.join(scssPath, filename),
31
+ destPath = path.join(neoPath, 'dist/development/css', filename.replace('.scss', '.css')),
32
+ startDate = new Date(),
33
+ data, map;
34
+
35
+ data = [
36
+ `@use "sass:map";`,
37
+ `@use "sass:math";`,
38
+ `$neoMap: ();`,
39
+ `$useCssVars: true;`,
40
+ `@import "${mixinPath}";`
41
+ ].join('');
42
+
43
+ fs.readFile(filePath).then(content => {
44
+ let result = sass.renderSync({
45
+ data : data + content.toString(),
46
+ outFile : destPath,
47
+ sourceMap : true,
48
+ sourceMapEmbed: false
49
+ });
50
+
51
+ map = result.map?.toString();
52
+
53
+ if (map) {
54
+ // https://github.com/neomjs/neo/issues/1970
55
+ map = JSON.parse(map);
56
+
57
+ let len = filename.split('/').length,
58
+ src = `/scss/${filename}`,
59
+ i = 0;
60
+
61
+ for (; i < len; i++) {
62
+ src = '../' + src;
63
+ }
64
+
65
+ map.sources = [src];
66
+ }
67
+
68
+ postcss([autoprefixer]).process(result.css, {
69
+ from: filePath,
70
+ to : destPath,
71
+ map : {
72
+ prev: map && JSON.stringify(map)
73
+ }
74
+ }).then(result => {
75
+ fs.writeFileSync(destPath, result.css, () => true);
76
+
77
+ if (result.map) {
78
+ fs.writeFileSync(result.opts.to + '.map', result.map.toString());
79
+ }
80
+
81
+ const processTime = (Math.round((new Date - startDate) * 100) / 100000).toFixed(2);
82
+ console.log('Updated file:', (chalk.blue(`${processTime}s`)), destPath);
83
+ });
84
+ });
85
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "neo.mjs",
3
- "version": "4.0.39",
3
+ "version": "4.0.40",
4
4
  "description": "The webworkers driven UI framework",
5
5
  "type": "module",
6
6
  "repository": {
@@ -16,7 +16,8 @@
16
16
  "create-app": "node ./buildScripts/createApp.mjs",
17
17
  "generate-docs-json": "node ./buildScripts/docs/jsdocx.mjs",
18
18
  "server-start": "webpack serve -c ./buildScripts/webpack/webpack.server.config.mjs --open",
19
- "test": "echo \"Error: no test specified\" && exit 1"
19
+ "test": "echo \"Error: no test specified\" && exit 1",
20
+ "watch-themes": "node ./buildScripts/watchThemes.mjs"
20
21
  },
21
22
  "keywords": [
22
23
  "javascript",
@@ -41,7 +42,7 @@
41
42
  "chalk": "^5.0.1",
42
43
  "clean-webpack-plugin": "^4.0.0",
43
44
  "commander": "^9.3.0",
44
- "cssnano": "^5.1.10",
45
+ "cssnano": "^5.1.11",
45
46
  "envinfo": "^7.8.1",
46
47
  "fs-extra": "^10.1.0",
47
48
  "highlightjs-line-numbers.js": "^2.8.0",
@@ -49,10 +50,10 @@
49
50
  "neo-jsdoc": "^1.0.1",
50
51
  "neo-jsdoc-x": "^1.0.4",
51
52
  "postcss": "^8.4.14",
52
- "sass": "^1.52.0",
53
- "webpack": "^5.72.1",
53
+ "sass": "^1.52.2",
54
+ "webpack": "^5.73.0",
54
55
  "webpack-cli": "^4.9.2",
55
- "webpack-dev-server": "4.9.0",
56
+ "webpack-dev-server": "4.9.2",
56
57
  "webpack-hook-plugin": "^1.0.7",
57
58
  "webpack-node-externals": "^3.0.0"
58
59
  },
@@ -91,4 +91,4 @@
91
91
  margin: 0 0 6px 0;
92
92
  }
93
93
  }
94
- }
94
+ }
@@ -0,0 +1,70 @@
1
+ /**
2
+ * CAROUSEL TRANSFORM
3
+ */
4
+ .neo-carousel {
5
+ /**
6
+ * VARS
7
+ */
8
+ --neo-carousel-translate-x: 0;
9
+ --neo-carousel-translate-y: 0;
10
+ --neo-carousel-transition-timing: cubic-bezier(.4,0,.2,1);
11
+ --neo-carousel-duration: .7s;
12
+
13
+ .neo-carousel-inner {
14
+ position: relative;
15
+ overflow: hidden;
16
+
17
+ .neo-carousel-item {
18
+ transition-timing-function: var(--neo-carousel-transition-timing);
19
+ transition-duration: var(--neo-carousel-duration);
20
+ transition-property: all;
21
+ z-index: 10;
22
+ inset: 0;
23
+ position: absolute;
24
+ transform: translate(var(--neo-carousel-translate-x), var(--neo-carousel-translate-y));
25
+ }
26
+ }
27
+ }
28
+
29
+ .neo-carousel--translate-x-full{
30
+ --neo-carousel-translate-x: -100%;
31
+ transform: translate(var(--neo-carousel-translate-x),var(--neo-carousel-translate-y));
32
+ }
33
+ .neo-carousel-translate-x-0{
34
+ --neo-carousel-translate-x: 0;
35
+ transform: translate(var(--neo-carousel-translate-x),var(--neo-carousel-translate-y));
36
+ }
37
+ .neo-carousel-translate-x-full{
38
+ --neo-carousel-translate-x: 100%;
39
+ transform: translate(var(--neo-carousel-translate-x),var(--neo-carousel-translate-y));
40
+ }
41
+
42
+ /**
43
+ * BASE STYLING
44
+ */
45
+ .neo-carousel {
46
+ padding: 15px;
47
+ height: 14rem;
48
+ background: var(--container-background-color);
49
+
50
+ .neo-carousel-btn-bar {
51
+ text-align: end;
52
+
53
+ .neo-carousel-btn {
54
+ padding: 15px;
55
+ font-size: 18px;
56
+ }
57
+ }
58
+ .neo-carousel-inner {
59
+ border-radius: 5px;
60
+ height: 9rem;
61
+ overflow: hidden;
62
+ background-color: var(--button-active-color);
63
+ color: var(--button-background-color);
64
+
65
+ .neo-carousel-item {
66
+ height: 9rem;
67
+ padding: 15px;
68
+ }
69
+ }
70
+ }
@@ -147,6 +147,12 @@ class Base extends CoreBase {
147
147
  * @member {Number|String|null} height_=null
148
148
  */
149
149
  height_: null,
150
+ /**
151
+ * Used for hide and show and defines if the component
152
+ * should use css visibility:'hidden' or vdom:removeDom
153
+ * @member {'visible', 'remove'} hiddenType='visible'
154
+ */
155
+ hiddenType: 'visible',
150
156
  /**
151
157
  * The top level innerHTML of the component
152
158
  * @member {String|null} html_=null
@@ -402,6 +408,17 @@ class Base extends CoreBase {
402
408
  }
403
409
  }
404
410
 
411
+ /**
412
+ * Add a new cls to the vdomRoot
413
+ * @param {String} value
414
+ */
415
+ addCls(value) {
416
+ let cls = this.cls;
417
+
418
+ NeoArray.add(cls, value);
419
+ this.cls = cls;
420
+ }
421
+
405
422
  /**
406
423
  * Either a string like 'color: red; background-color: blue;'
407
424
  * or an object containing style attributes
@@ -1061,6 +1078,36 @@ class Base extends CoreBase {
1061
1078
  return this.vnode;
1062
1079
  }
1063
1080
 
1081
+ /**
1082
+ * Hide the component.
1083
+ * hiddenType: 'visible' uses css visibility.
1084
+ * hiddenType: 'remove' uses vdom removeDom.
1085
+ * If hiddenType 'remove' you can pass a timeout for custom css class hiding.
1086
+ * @param {Number} timeout
1087
+ */
1088
+ hide(timeout) {
1089
+ let me = this,
1090
+ doRemove = me.hiddenType !== 'visible';
1091
+
1092
+ if (doRemove) {
1093
+ let removeFn = function() {
1094
+ let vdom = me.vdom;
1095
+ vdom.removeDom = true;
1096
+ me.vdom = vdom;
1097
+ }
1098
+
1099
+ if (timeout) {
1100
+ setTimeout(removeFn, timeout);
1101
+ } else {
1102
+ removeFn();
1103
+ }
1104
+ } else {
1105
+ let style = me.style;
1106
+ style.visibility = 'hidden';
1107
+ me.style = style;
1108
+ }
1109
+ }
1110
+
1064
1111
  /**
1065
1112
  *
1066
1113
  */
@@ -1282,6 +1329,17 @@ class Base extends CoreBase {
1282
1329
  });
1283
1330
  }
1284
1331
 
1332
+ /**
1333
+ * Remove a cls from the vdomRoot
1334
+ * @param {String} value
1335
+ */
1336
+ removeCls(value) {
1337
+ let cls = this.cls;
1338
+
1339
+ NeoArray.remove(cls, value);
1340
+ this.cls = cls;
1341
+ }
1342
+
1285
1343
  /**
1286
1344
  * @param {Array|Object} value
1287
1345
  */
@@ -1404,6 +1462,26 @@ class Base extends CoreBase {
1404
1462
  return this.set(values, true);
1405
1463
  }
1406
1464
 
1465
+ /**
1466
+ * Show the component.
1467
+ * hiddenType: 'visible' uses css visibility.
1468
+ * hiddenType: 'remove' uses vdom removeDom.
1469
+ */
1470
+ show() {
1471
+ let me = this,
1472
+ doAdd = me.hiddenType !== 'visible';
1473
+
1474
+ if (doAdd) {
1475
+ let vdom = me.vdom;
1476
+ vdom.removeDom = false;
1477
+ me.vdom = vdom;
1478
+ } else {
1479
+ let style = me.style;
1480
+ style.visibility = 'visible';
1481
+ me.style = style;
1482
+ }
1483
+ }
1484
+
1407
1485
  /**
1408
1486
  * Placeholder method for util.VDom.syncVdomIds to allow overriding (disabling) it
1409
1487
  * @param {Neo.vdom.VNode} [vnode=this.vnode]
@@ -1473,7 +1551,17 @@ class Base extends CoreBase {
1473
1551
  let end = performance.now();
1474
1552
  console.log('syncVnodeTree', me.id, end - start);
1475
1553
  }
1554
+ }
1476
1555
 
1556
+ /**
1557
+ * Toggle a cls inside the vdomRoot of the component
1558
+ * @param {String} value
1559
+ */
1560
+ toggleCls(value) {
1561
+ let cls = this.cls;
1562
+
1563
+ NeoArray.toggle(cls, value);
1564
+ this.cls = cls;
1477
1565
  }
1478
1566
 
1479
1567
  /**
@@ -0,0 +1,266 @@
1
+ import ClassSystemUtil from '../util/ClassSystem.mjs';
2
+ import Component from './Base.mjs';
3
+ import Store from '../data/Store.mjs';
4
+
5
+ /**
6
+ * @class Neo.component.Carousel
7
+ * @extends Neo.component.Base
8
+ */
9
+ class Carousel extends Component {
10
+ /**
11
+ * Defines the currently visible item in the middle
12
+ * This gets updated everytime a button is clicked to reflect the current order
13
+ * @member {Number} itemIndex=1
14
+ */
15
+ itemIndex = 1
16
+ /**
17
+ * Defines the order of the item in the carousel
18
+ * This gets updated everytime a button is clicked to reflect the current order
19
+ * @member {String[]} positionArray
20
+ */
21
+ positionArray = ['neo-carousel--translate-x-full', 'neo-carousel-translate-x-0', 'neo-carousel-translate-x-full']
22
+
23
+ static getConfig() {return {
24
+ /**
25
+ * @member {String} className='Neo.component.Carousel'
26
+ * @protected
27
+ */
28
+ className: 'Neo.component.Carousel',
29
+ /**
30
+ * @member {String} ntype='carousel'
31
+ * @protected
32
+ */
33
+ ntype: 'carousel',
34
+ /**
35
+ * @member {String[]} cls=['neo-carousel']
36
+ */
37
+ cls : ['neo-carousel'],
38
+ /**
39
+ * Custom cls added to each item
40
+ * This is only a single string
41
+ *
42
+ * @member {String|null} itemCls=null
43
+ */
44
+ itemCls: null,
45
+ /**
46
+ * Template for each item
47
+ * The format is the same as for literals,
48
+ * but it is a string instead of surrounding "`"
49
+ * @member {String|null} tpl=null
50
+ * @example
51
+ * record = {foo: ... , bar: ...}
52
+ * "[{cls: 'css-foo-class', html: '${foo}'}, {html: '${baa}'}]"
53
+ */
54
+ itemTpl_: null,
55
+ /**
56
+ * Store to be used.
57
+ *
58
+ * @member {Neo.data.Store|null} store=null
59
+ */
60
+ store_: null,
61
+ /**
62
+ * @member {Object} _vdom
63
+ */
64
+ _vdom:
65
+ {cn: [
66
+ {cls: ['neo-carousel'], cn: [
67
+ {cls: ['neo-carousel-btn-bar'], cn: [
68
+ {tag: 'a', 'data-carouselaction': 'back', cls: ['neo-carousel-btn', 'fa', 'fa-chevron-left']},
69
+ {tag: 'a', 'data-carouselaction': 'forward', cls: ['neo-carousel-btn', 'fa', 'fa-chevron-right']}
70
+ ]},
71
+ {cls: ['neo-carousel-inner'], cn: []}
72
+ ]}
73
+ ]}
74
+ }}
75
+
76
+ /**
77
+ * @param {Object} config
78
+ */
79
+ construct(config) {
80
+ super.construct(config);
81
+
82
+ let me = this,
83
+ domListeners = me.domListeners;
84
+
85
+ domListeners.push({
86
+ click: {
87
+ fn : me.onCarouselBtnClick,
88
+ delegate: '.neo-carousel-btn',
89
+ scope : me
90
+ }
91
+ });
92
+
93
+ me.domListeners = domListeners;
94
+ }
95
+
96
+ /**
97
+ * Triggered after the store config got changed
98
+ * @param {Neo.data.Store|Object|null} value
99
+ * @param {Neo.data.Store|null} oldValue
100
+ * @protected
101
+ */
102
+ afterSetStore(value, oldValue) {
103
+ let me = this;
104
+
105
+ value?.on({
106
+ load : 'onStoreLoad',
107
+ scope: me
108
+ });
109
+
110
+ value?.getCount() > 0 && me.onStoreLoad();
111
+ }
112
+
113
+ /**
114
+ * Ensure the itemTpl is setup correctly to match a valid JSON
115
+ * @param {String} value
116
+ * @returns {String}
117
+ * @protected
118
+ */
119
+ beforeSetItemTpl(value) {
120
+ let itemTpl = value.replaceAll('\'', '"');
121
+
122
+ itemTpl = itemTpl.replace(/(\w+:)|(\w+ :)/g, function(matchedStr) {
123
+ return `"${matchedStr.substring(0, matchedStr.length - 1)}":`;
124
+ });
125
+
126
+ return itemTpl;
127
+ }
128
+
129
+ /**
130
+ * Triggered before the store config gets changed.
131
+ * @param {Neo.data.Store|Object|null} value
132
+ * @param {Neo.data.Store|null} oldValue
133
+ * @returns {Neo.data.Store}
134
+ * @protected
135
+ */
136
+ beforeSetStore(value, oldValue) {
137
+ oldValue?.destroy();
138
+ return ClassSystemUtil.beforeSetInstance(value, Store);
139
+ }
140
+
141
+ /**
142
+ * Create the initial three items and add them to the vdom
143
+ */
144
+ createBaseItems() {
145
+ let me = this,
146
+ vdom = me._vdom,
147
+ itemRoot = me.#getItemRoot(),
148
+ items = [],
149
+ i = 0;
150
+
151
+ for (i; i < 3; i++) {
152
+ items.push(me.createItem(i, i));
153
+ }
154
+
155
+ itemRoot.cn = items;
156
+ me.vdom = vdom;
157
+ }
158
+
159
+ /**
160
+ * Everytime we rotate we create items
161
+ * @param {Number} recordIndex - index inside store
162
+ * @param {Number} positionIndex - based on positionArray
163
+ * @returns {Object}
164
+ */
165
+ createItem(recordIndex, positionIndex) {
166
+ let me = this,
167
+ itemCls = me.itemCls,
168
+ positionArray = me.positionArray,
169
+ store = me.store,
170
+ data = store.getAt(recordIndex),
171
+ itemTpl = me.#formatTpl(me.itemTpl, data),
172
+
173
+ newItem = {
174
+ cls: [positionArray[positionIndex], 'neo-carousel-item'],
175
+ cn : itemTpl,
176
+ recordIndex
177
+ };
178
+
179
+ itemCls && newItem.cls.push(itemCls);
180
+
181
+ return newItem;
182
+ }
183
+
184
+ /**
185
+ * Rotate the three items and fill in a new record
186
+ * @param {Object} event
187
+ * @param {Object} event.target - clicked button
188
+ */
189
+ onCarouselBtnClick(event) {
190
+ let me = this,
191
+ action = event.target.data.carouselaction,
192
+ store = me.store,
193
+ countItems = store.getCount(),
194
+ vdom = me.vdom,
195
+ index = me.itemIndex,
196
+ positionArray = me.positionArray,
197
+ root = me.#getItemRoot(),
198
+ newRecordIndex, positionCls, recordIndex, vdomCls;
199
+
200
+ if (action === 'forward') {
201
+ vdomCls = 'neo-carousel-translate-x-full';
202
+ index = index + 2
203
+ newRecordIndex = index % countItems;
204
+
205
+ me.itemIndex = newRecordIndex - 1;
206
+ positionArray = me.#arrayRotate(positionArray, -1);
207
+ } else {
208
+ vdomCls = 'neo-carousel--translate-x-full';
209
+ index = index - 2;
210
+ newRecordIndex = index < 0 ? (countItems + index) : index;
211
+
212
+ me.itemIndex = newRecordIndex + 1;
213
+ positionArray = me.#arrayRotate(positionArray, 1);
214
+ }
215
+
216
+ me.positionArray = positionArray;
217
+
218
+ root.cn = root.cn.map(function(cn, mappingIndex) {
219
+ positionCls = positionArray[mappingIndex];
220
+ recordIndex = cn.recordIndex;
221
+
222
+ cn.cls.shift();
223
+ cn.cls.unshift(positionCls);
224
+
225
+ // Update new Record
226
+ if (positionCls === vdomCls) {
227
+ recordIndex = newRecordIndex;
228
+ cn = me.createItem(recordIndex, mappingIndex);
229
+ }
230
+
231
+ return cn;
232
+ })
233
+
234
+ me.vdom = vdom;
235
+ }
236
+
237
+ /**
238
+ * As soon as the store is loaded we want to
239
+ * - create the three items
240
+ * - fill the first three records
241
+ */
242
+ onStoreLoad() {
243
+ this.createBaseItems();
244
+ }
245
+
246
+ /**
247
+ * HELPERS
248
+ */
249
+ #getItemRoot() {
250
+ return this.vdom.cn[0].cn[1];
251
+ }
252
+
253
+ #arrayRotate(arr, n) {
254
+ return n ? [...arr.slice(n, arr.length), ...arr.slice(0, n)] : arr;
255
+ }
256
+
257
+ #formatTpl(tpl, record) {
258
+ let resultStr = tpl.replace(/\$\{[^\}]+\}/g, (m) => record[m.slice(2, -1).trim()]);
259
+
260
+ return JSON.parse(resultStr);
261
+ }
262
+ }
263
+
264
+ Neo.applyClassConfig(Carousel);
265
+
266
+ export default Carousel;