glass-easel-devtools-examples-miniprogram 0.9.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/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2024 wechat-miniprogram
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,23 @@
1
+ # glass-easel-miniprogram-template
2
+
3
+ The template mini-program code for the glass-easel project.
4
+
5
+ Refer to the [glass-easel](https://github.com/wechat-miniprogram/glass-easel) project for further details.
6
+
7
+ ## Build
8
+
9
+ `nodejs` toolchain should be globally installed.
10
+
11
+ Install dependencies:
12
+
13
+ ```sh
14
+ npm install
15
+ ```
16
+
17
+ Build:
18
+
19
+ ```sh
20
+ npm run build
21
+ ```
22
+
23
+ Then open `dist/index.html` in the browser.
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "glass-easel-devtools-examples-miniprogram",
3
+ "version": "0.9.0",
4
+ "main": "src/index.ts",
5
+ "dependencies": {
6
+ "glass-easel": "^0.9.0",
7
+ "glass-easel-miniprogram-adapter": "^0.9.0"
8
+ },
9
+ "devDependencies": {
10
+ "@typescript-eslint/eslint-plugin": "^6.6.0",
11
+ "@typescript-eslint/parser": "^6.6.0",
12
+ "css-loader": "^6.7.1",
13
+ "eslint": "^7.17.0",
14
+ "eslint-plugin-import": "^2.22.1",
15
+ "eslint-plugin-promise": "^4.2.1",
16
+ "glass-easel-miniprogram-webpack-plugin": "^0.9.0",
17
+ "less": "^4.1.3",
18
+ "less-loader": "^11.0.0",
19
+ "mini-css-extract-plugin": "^2.6.1",
20
+ "ts-loader": "^9.4.2",
21
+ "typescript": "^5.2.2",
22
+ "webpack": "^5.85.0",
23
+ "webpack-cli": "^5.0.1"
24
+ },
25
+ "scripts": {
26
+ "build": "webpack --config webpack.config.js",
27
+ "dev": "webpack --config webpack.dev.config.js --watch"
28
+ }
29
+ }
package/src/app.ts ADDED
@@ -0,0 +1,4 @@
1
+ // this file is always executed on startup
2
+
3
+ // eslint-disable-next-line no-console
4
+ console.info('App started')
package/src/app.wxss ADDED
@@ -0,0 +1 @@
1
+ /* this is the global stylesheet */
@@ -0,0 +1,3 @@
1
+ {
2
+ "component": true
3
+ }
@@ -0,0 +1,5 @@
1
+ Component({
2
+ properties: {
3
+ src: String,
4
+ },
5
+ })
@@ -0,0 +1 @@
1
+ <img src="{{src}}" />
@@ -0,0 +1,3 @@
1
+ :host {
2
+ display: block;
3
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "component": true
3
+ }
@@ -0,0 +1,19 @@
1
+ import { StyleSegmentIndex } from 'glass-easel'
2
+
3
+ Component({
4
+ properties: {
5
+ hidden: Boolean,
6
+ },
7
+ observers: {
8
+ hidden(hidden: boolean) {
9
+ // `this._$` is the underlying glass-easel element
10
+ // (this cannot be retrieved in MiniProgram environment)
11
+ const glassEaselElement = this._$
12
+ if (hidden) {
13
+ glassEaselElement.setNodeStyle('display: none', StyleSegmentIndex.TEMP_EXTRA)
14
+ } else {
15
+ glassEaselElement.setNodeStyle('', StyleSegmentIndex.TEMP_EXTRA)
16
+ }
17
+ },
18
+ },
19
+ })
@@ -0,0 +1 @@
1
+ <slot />
@@ -0,0 +1,3 @@
1
+ :host {
2
+ display: block;
3
+ }
package/src/index.html ADDED
@@ -0,0 +1,12 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width,initial-scale=1" />
6
+ <link rel="stylesheet" href="index.css" />
7
+ </head>
8
+ <body>
9
+ <!-- the entry component will be loaded here -->
10
+ </body>
11
+ <script src="index.js"></script>
12
+ </html>
@@ -0,0 +1,3 @@
1
+ {
2
+ "component": true
3
+ }
@@ -0,0 +1,16 @@
1
+ Component()
2
+ .options({
3
+ dynamicSlots: true,
4
+ })
5
+ .externalClasses(['hello-class', 'hover-class'])
6
+ .property('hello', String)
7
+ .data(() => ({
8
+ random: 0,
9
+ }))
10
+ .init(({ setData, method }) => {
11
+ const updateRandom = method(() => {
12
+ setData({ random: Math.random() })
13
+ })
14
+ return { updateRandom }
15
+ })
16
+ .register()
@@ -0,0 +1,7 @@
1
+ <div class="hello-class hover-class" custom-attr="custom-value">
2
+ This component has external classes.
3
+ <div catch:tap="updateRandom">
4
+ Tap here to update slot values.
5
+ <slot hello="{{ hello: 'component' }}" random="{{ random }}" />
6
+ </div>
7
+ </div>
File without changes
@@ -0,0 +1,7 @@
1
+ {
2
+ "usingComponents": {
3
+ "view": "/components/view/view",
4
+ "image": "/components/image/image",
5
+ "comp": "../comp/comp"
6
+ }
7
+ }
@@ -0,0 +1,54 @@
1
+ Component()
2
+ .data(() => ({
3
+ class: 'my-class-0',
4
+ paddingLeft: 0,
5
+ arrayData: ['a', 'b', 'c'],
6
+ objectData: { a: 0, b: 1 } as Record<string, number>,
7
+ childList: [1, 2, 3],
8
+ }))
9
+ .init(({ self, data, setData, listener }) => {
10
+ const modifyClass = listener(() => {
11
+ setData({ class: `my-class-${Math.floor(Math.random() * 10)}` })
12
+ })
13
+
14
+ const modifyStyle = listener(() => {
15
+ setData({ paddingLeft: Math.floor(Math.random() * 20) })
16
+ })
17
+
18
+ const randomArray = () =>
19
+ ['a', 'b', 'c', 'd', 'e', 'f', 'g'].slice(0, Math.floor(Math.random() * 7))
20
+ const modifyArrayData = listener(() => {
21
+ setData({
22
+ arrayData: randomArray(),
23
+ })
24
+ })
25
+
26
+ const randomObject = () => {
27
+ const ret = {}
28
+ randomArray().forEach((item, index) => {
29
+ Object.assign(ret, { item: index })
30
+ })
31
+ return ret
32
+ }
33
+ const modifyObjectData = listener(() => {
34
+ setData({
35
+ objectData: randomObject(),
36
+ })
37
+ })
38
+
39
+ let inc = data.childList.length + 1
40
+ const modifyChildList = listener(() => {
41
+ const list = data.childList.slice()
42
+ const i = Math.floor(Math.random() * (list.length * 2 + 1))
43
+ if (i < list.length) {
44
+ list.splice(i, 1)
45
+ } else {
46
+ list.splice(i - list.length, 0, inc)
47
+ inc += 1
48
+ }
49
+ self.setData({ childList: list })
50
+ })
51
+
52
+ return { modifyClass, modifyStyle, modifyArrayData, modifyObjectData, modifyChildList }
53
+ })
54
+ .register()
@@ -0,0 +1,27 @@
1
+ <view class="wrapper">
2
+ <view class="left">
3
+ <img class="logo" src="resources/logo_256.png" />
4
+ <view class="hello">
5
+ glass-easel-devtools
6
+ </view>
7
+ </view>
8
+
9
+ <view class="right">
10
+ <view hidden>This element is hidden.</view>
11
+
12
+ <view style="padding: 1px 2px 3px 4px">This element has paddings.</view>
13
+ <view style="border: 0 solid #808080; border-width: 1px 2px 3px 4px">This element has borders.</view>
14
+ <view style="margin: 1px 2px 3px 4px">This element has margins.</view>
15
+ <view class="my-class">This element has media query styles.</view>
16
+
17
+ <view class="{{ class }}" catch:tap="modifyClass">Tap here to change classes.</view>
18
+ <view style="padding-left: {{ paddingLeft }}px" catch:tap="modifyStyle">Tap here to change styles.</view>
19
+ <view data-num-data="{{ 1 }}" data:arrayData="{{ arrayData }}" catch:tap="modifyArrayData">Tap here to change dataset.</view>
20
+ <view mark:objectData="{{ objectData }}" catch:tap="modifyObjectData">Tap here to change marks.</view>
21
+ <view class="child-list" catch:tap="modifyChildList">Tap here to switch some child nodes. ({{ childList.length }} nodes)
22
+ <view wx:for="{{ childList }}" wx:key="*this">child: {{ item }}</view>
23
+ </view>
24
+
25
+ <comp hello-class="my-hello-class-impl" hover-class=" my-class {{ class }} " catch:tap="modifyClass"></comp>
26
+ </view>
27
+ </view>
@@ -0,0 +1,35 @@
1
+ .wrapper {
2
+ display: flex;
3
+ }
4
+
5
+ .left {
6
+ width: 300px;
7
+ flex: none;
8
+ }
9
+ .logo {
10
+ display: block;
11
+ width: 256px;
12
+ margin: 0 auto;
13
+ }
14
+ .hello {
15
+ margin: 20px;
16
+ text-align: center;
17
+ }
18
+
19
+ .right {
20
+ flex: auto;
21
+ }
22
+
23
+ .my-class {
24
+ border-bottom: 1px solid green;
25
+ }
26
+ @media (min-width: 600px) {
27
+ .my-class {
28
+ border-bottom: 1px solid blue;
29
+ }
30
+ }
31
+
32
+ .child-list {
33
+ border-left: 1px solid gray;
34
+ padding-left: 5px;
35
+ }
Binary file
package/tsconfig.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "compilerOptions": {
3
+ "strict": true,
4
+ "module": "es6",
5
+ "target": "es5",
6
+ "esModuleInterop": true,
7
+ "moduleResolution": "node",
8
+ "lib": ["ES6", "ES7", "DOM", "ESNext"]
9
+ },
10
+ "include": [
11
+ "src/**/*.ts",
12
+ "typings"
13
+ ]
14
+ }
@@ -0,0 +1,6 @@
1
+ import type { PageConstructor, ComponentConstructor } from 'glass-easel-miniprogram-adapter'
2
+
3
+ declare global {
4
+ const Page: PageConstructor
5
+ const Component: ComponentConstructor
6
+ }
@@ -0,0 +1,77 @@
1
+ /* eslint-disable import/no-extraneous-dependencies */
2
+ /* eslint-disable @typescript-eslint/no-var-requires */
3
+
4
+ const path = require('path')
5
+ const {
6
+ GlassEaselMiniprogramWebpackPlugin,
7
+ GlassEaselMiniprogramWxmlLoader,
8
+ GlassEaselMiniprogramWxssLoader,
9
+ } = require('glass-easel-miniprogram-webpack-plugin')
10
+ const MiniCssExtractPlugin = require('mini-css-extract-plugin')
11
+
12
+ module.exports = [
13
+ {
14
+ mode: 'production',
15
+ entry: './src/index.js', // this file is virtually generated by the plugin
16
+ output: {
17
+ filename: 'index.js',
18
+ path: path.join(__dirname, 'dist'),
19
+ module: false,
20
+ iife: true,
21
+ },
22
+ devtool: 'source-map',
23
+ resolve: {
24
+ extensions: ['.ts', '.js'],
25
+ alias: {
26
+ 'glass-easel': 'glass-easel',
27
+ },
28
+ },
29
+ module: {
30
+ rules: [
31
+ {
32
+ test: /\.ts$/,
33
+ loader: 'ts-loader',
34
+ exclude: /node_modules/,
35
+ },
36
+ {
37
+ // wxml should be explicit handled with a loader
38
+ test: /\.wxml$/,
39
+ use: GlassEaselMiniprogramWxmlLoader,
40
+ exclude: /node_modules/,
41
+ },
42
+ {
43
+ // wxss should be explicit handled like CSS
44
+ test: /\.wxss$/,
45
+ use: [
46
+ MiniCssExtractPlugin.loader,
47
+ 'css-loader',
48
+ GlassEaselMiniprogramWxssLoader,
49
+ // Add more loaders here if you work with less, sass, Stylus, etc.
50
+ // Currently `@import` does not work well without a preprocessor (such as `less`).
51
+ // This is a bug (#113) and will be fixed in future.
52
+ 'less-loader',
53
+ ],
54
+ exclude: /node_modules/,
55
+ },
56
+ ],
57
+ },
58
+ performance: {
59
+ hints: false,
60
+ maxEntrypointSize: 4 * 1024 * 1024,
61
+ maxAssetSize: 4 * 1024 * 1024,
62
+ },
63
+ plugins: [
64
+ new MiniCssExtractPlugin({
65
+ filename: 'index.css',
66
+ }),
67
+ new GlassEaselMiniprogramWebpackPlugin({
68
+ // the path of the mini-program code directory
69
+ path: path.join(__dirname, 'src'),
70
+ // the resouce files that should be copied to the dist directory
71
+ resourceFilePattern: /\.(jpg|jpeg|png|gif|html)$/,
72
+ // the default entry
73
+ defaultEntry: 'pages/index/index',
74
+ }),
75
+ ],
76
+ },
77
+ ]
@@ -0,0 +1,8 @@
1
+ /* eslint-disable @typescript-eslint/no-var-requires */
2
+
3
+ const config = require('./webpack.config')
4
+
5
+ config[0].mode = 'development'
6
+ config[0].resolve.alias['glass-easel'] = 'glass-easel/dist/glass_easel.dev.all.es.js'
7
+
8
+ module.exports = config