Skip to content

Commit

Permalink
feat(uicontrol): add Menu
Browse files Browse the repository at this point in the history
(chore: update package.json->meta3d:publish_dev_auto script)
  • Loading branch information
yyc-git committed Nov 24, 2023
1 parent 7214e5f commit b05617f
Show file tree
Hide file tree
Showing 128 changed files with 743 additions and 143 deletions.
2 changes: 1 addition & 1 deletion contributes/meta3d-action-publish/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"scripts": {
"watch": "tsc -w -noEmit",
"webpack": "webpack --config webpack.config.js",
"meta3d:publish_dev_auto": "yarn version --new-version patch && gulp publish_local_env",
"meta3d:publish_dev_auto": "yarn version --patch --no-git-tag-version && yarn meta3d:publish_dev",
"meta3d:publish_dev": "cross-env NODE_ENV=development npm run webpack && gulp publish_local_env",
"meta3d:publish_pro": "cross-env NODE_ENV=production npm run webpack && gulp publish_production_env"
},
Expand Down
2 changes: 1 addition & 1 deletion contributes/meta3d-action-run/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"scripts": {
"watch": "tsc -w -noEmit",
"webpack": "webpack --config webpack.config.js",
"meta3d:publish_dev_auto": "yarn version --new-version patch && gulp publish_local_env",
"meta3d:publish_dev_auto": "yarn version --patch --no-git-tag-version && yarn meta3d:publish_dev",
"meta3d:publish_dev": "cross-env NODE_ENV=development npm run webpack && gulp publish_local_env",
"meta3d:publish_pro": "cross-env NODE_ENV=production npm run webpack && gulp publish_production_env"
},
Expand Down
2 changes: 1 addition & 1 deletion contributes/meta3d-action-stop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"scripts": {
"watch": "tsc -w -noEmit",
"webpack": "webpack --config webpack.config.js",
"meta3d:publish_dev_auto": "yarn version --new-version patch && gulp publish_local_env",
"meta3d:publish_dev_auto": "yarn version --patch --no-git-tag-version && yarn meta3d:publish_dev",
"meta3d:publish_dev": "cross-env NODE_ENV=development npm run webpack && gulp publish_local_env",
"meta3d:publish_pro": "cross-env NODE_ENV=production npm run webpack && gulp publish_production_env"
},
Expand Down
2 changes: 1 addition & 1 deletion contributes/meta3d-input-runstopbutton/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"scripts": {
"watch": "tsc -w -noEmit",
"webpack": "webpack --config webpack.config.js",
"meta3d:publish_dev_auto": "yarn version --new-version patch && gulp publish_local_env",
"meta3d:publish_dev_auto": "yarn version --patch --no-git-tag-version && yarn meta3d:publish_dev",
"meta3d:publish_dev": "cross-env NODE_ENV=development npm run webpack && gulp publish_local_env",
"meta3d:publish_pro": "cross-env NODE_ENV=production npm run webpack && gulp publish_production_env"
},
Expand Down
2 changes: 1 addition & 1 deletion contributes/meta3d-ui-control-button/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"scripts": {
"watch": "tsc -w -noEmit",
"webpack": "webpack --config webpack.config.js",
"meta3d:publish_dev_auto": "yarn version --new-version patch && gulp publish_local_env",
"meta3d:publish_dev_auto": "yarn version --patch --no-git-tag-version && yarn meta3d:publish_dev",
"meta3d:publish_dev": "cross-env NODE_ENV=development npm run webpack && gulp publish_local_env",
"meta3d:publish_pro": "cross-env NODE_ENV=production npm run webpack && gulp publish_production_env"
},
Expand Down
2 changes: 1 addition & 1 deletion contributes/meta3d-ui-control-game-view/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"scripts": {
"watch": "tsc -w -noEmit",
"webpack": "webpack --config webpack.config.js",
"meta3d:publish_dev_auto": "yarn version --new-version patch && gulp publish_local_env",
"meta3d:publish_dev_auto": "yarn version --patch --no-git-tag-version && yarn meta3d:publish_dev",
"meta3d:publish_dev": "cross-env NODE_ENV=development npm run webpack && gulp publish_local_env",
"meta3d:publish_pro": "cross-env NODE_ENV=production npm run webpack && gulp publish_production_env"
},
Expand Down
19 changes: 19 additions & 0 deletions contributes/meta3d-ui-control-menu/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.DS_Store
.merlin
.idea/
.vscode/
jest_0/
reference/
node_modules/
mine/

coverage

dist/

npm-debug

.bsb.lock

yarn.lock

25 changes: 25 additions & 0 deletions contributes/meta3d-ui-control-menu/gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
var gulp = require("gulp");
var path = require("path");
var publish = require("meta3d-tool-publish")

gulp.task("publish_local_env", function (done) {
publish.publishContribute(
"local",
path.join(__dirname, "package.json"),
path.join(__dirname, "dist/static/js", "main.js")
).then(() => {
done()
})
});

gulp.task("publish_production_env", function (done) {
publish.publishContribute(
"production",
path.join(__dirname, "package.json"),
path.join(__dirname, "dist/static/js", "main.js")
).then(() => {
done()
})
});


2 changes: 1 addition & 1 deletion contributes/meta3d-ui-control-menu/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"scripts": {
"watch": "tsc -w -noEmit",
"webpack": "webpack --config webpack.config.js",
"meta3d:publish_dev_auto": "yarn version --new-version patch && npm run meta3d:publish_dev",
"meta3d:publish_dev_auto": "yarn version --patch --no-git-tag-version && yarn meta3d:publish_dev",
"meta3d:publish_dev": "cross-env NODE_ENV=development npm run webpack && gulp publish_local_env",
"meta3d:publish_pro": "cross-env NODE_ENV=production npm run webpack && gulp publish_production_env"
},
Expand Down
73 changes: 73 additions & 0 deletions contributes/meta3d-ui-control-menu/src/Main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { getContribute as getContributeMeta3D, state as meta3dState } from "meta3d-type"
import { inputFunc, specificData, outputData, uiControlName, menuLabel, actionName, state } from "meta3d-ui-control-menu-protocol"
import { service, uiControlContribute } from "meta3d-editor-whole-protocol/src/service/ServiceType"
import type { Map } from "immutable"

export let getContribute: getContributeMeta3D<uiControlContribute<inputFunc, specificData, outputData>> = (api) => {
return {
uiControlName: uiControlName,
func: (meta3dState,
_,
{
rect,
label,
items
}
) => {
let { menu } = api.nullable.getExn(api.getPackageService<service>(meta3dState, "meta3d-editor-whole-protocol")).ui(meta3dState)

// let items: Array<[menuLabel, Record<menuLabel, string>]> = [
// [
// "编辑",
// {
// "导出事件": exportEventActionName,
// "导出单一事件": exportSingleEventActionName,
// "导入事件": importEventActionName
// }
// ],
// [
// "发布",
// {
// "本地包": publishActionName
// }
// ],
// [
// "帮助",
// {
// "关于Meta3D": jumpToLinkActionName
// }
// ],
// ]

console.log(
rect,
label,
items

)

let data = menu(meta3dState, items.map(([label, secondLevelData]) => [
label,
api.immutable.createMapOfData(meta3dState, secondLevelData).keySeq().toArray()
]), "Menu Window", rect)
meta3dState = data[0]
let selectItemLabel = data[1]

if (api.nullable.isNullable(selectItemLabel)) {
return Promise.resolve([meta3dState, null])
}

selectItemLabel = api.nullable.getExn(selectItemLabel)

let actionNameMap: Map<menuLabel, actionName> = items.map(([_, secondLevelData]) => api.immutable.createMapOfData(meta3dState, secondLevelData)
).reduce((result, map) => {
return result.concat(map)
}, api.immutable.createMap(meta3dState))

let { trigger } = api.nullable.getExn(api.getPackageService<service>(meta3dState, "meta3d-editor-whole-protocol")).event(meta3dState)

return trigger(meta3dState, "meta3d-event-protocol", api.nullable.getExn(actionNameMap.get(selectItemLabel)), null).then(meta3dState => [meta3dState, null])
},
init: (meta3dState) => Promise.resolve(meta3dState)
}
}
24 changes: 24 additions & 0 deletions contributes/meta3d-ui-control-menu/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"compilerOptions": {
"target": "ES6",
"module": "ES6",
"moduleResolution": "node",
"sourceMap": true,
"resolveJsonModule": true,
"esModuleInterop": true,
"jsx": "react",
// "noEmit": true,
// "noUnusedLocals": true,
// "noUnusedParameters": true,
"noImplicitReturns": true,
"lib": [
"DOM",
"ESNext",
],
"types": [],
"strict": true
},
"include": [
"./src"
]
}
64 changes: 64 additions & 0 deletions contributes/meta3d-ui-control-menu/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
const path = require('path');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');

module.exports = {
entry: "./src/Main.ts",
mode: process.env.NODE_ENV.trim() == 'production' ? 'production' : 'development',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'static/js/[name].js',
library: {
name: 'Contribute',
type: 'window',
},
},

// Enable sourcemaps for debugging webpack's output.
// devtool: "source-map",

resolve: {
extensions: ['.ts', '.tsx', '.js', '.jsx', '.scss'],
modules: ['node_modules']
},

module: {
rules: [
// All files with a '.ts' or '.tsx' extension will be handled by 'awesome-typescript-loader'.
{
test: /\.tsx?$/,
exclude: /node_modules/,
use: "ts-loader"
},
// All output '.js' files will have any sourcemaps re-processed by 'source-map-loader'.
{
enforce: 'pre',
test: /\.js$/,
loader: "source-map-loader"
},
]
},
plugins: [
/**
* All files inside webpack's output.path directory will be removed once, but the
* directory itself will not be. If using webpack 4+'s default configuration,
* everything under <PROJECT_DIR>/dist/ will be removed.
* Use cleanOnceBeforeBuildPatterns to override this behavior.
*
* During rebuilds, all webpack assets that are not used anymore
* will be removed automatically.
*
* See `Options and Defaults` for information
*/
new CleanWebpackPlugin(),
// new HtmlWebpackPlugin({
// template: './user.html',
// filename: 'user.html',
// }),
],
// When importing a module whose path matches one of the following, just
// assume a corresponding global variable exists and use that instead.
// This is important because it allows us to avoid bundling all of our
// dependencies, which allows browsers to cache those libraries between builds.
externals: {
}
};
2 changes: 1 addition & 1 deletion contributes/meta3d-ui-control-scene-view/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"scripts": {
"watch": "tsc -w -noEmit",
"webpack": "webpack --config webpack.config.js",
"meta3d:publish_dev_auto": "yarn version --new-version patch && gulp publish_local_env",
"meta3d:publish_dev_auto": "yarn version --patch --no-git-tag-version && yarn meta3d:publish_dev",
"meta3d:publish_dev": "cross-env NODE_ENV=development npm run webpack && gulp publish_local_env",
"meta3d:publish_pro": "cross-env NODE_ENV=production npm run webpack && gulp publish_production_env"
},
Expand Down
6 changes: 3 additions & 3 deletions contributes/meta3d-ui-control-switch-button/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"scripts": {
"watch": "tsc -w -noEmit",
"webpack": "webpack --config webpack.config.js",
"meta3d:publish_dev_auto": "yarn version --new-version patch && gulp publish_local_env",
"meta3d:publish_dev": "cross-env NODE_ENV=development npm run webpack && gulp publish_local_env",
"meta3d:publish_dev_auto": "yarn version --patch --no-git-tag-version && yarn meta3d:publish_dev",
"meta3d:publish_dev": "cross-env NODE_ENV=development npm run webpack && gulp publish_local_env",
"meta3d:publish_pro": "cross-env NODE_ENV=production npm run webpack && gulp publish_production_env"
},
"keywords": [],
Expand All @@ -32,4 +32,4 @@
"webpack": "^5.62.1",
"webpack-cli": "^4.9.1"
}
}
}
2 changes: 1 addition & 1 deletion contributes/meta3d-ui-control-window/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"scripts": {
"watch": "tsc -w -noEmit",
"webpack": "webpack --config webpack.config.js",
"meta3d:publish_dev_auto": "yarn version --new-version patch && gulp publish_local_env",
"meta3d:publish_dev_auto": "yarn version --patch --no-git-tag-version && yarn meta3d:publish_dev",
"meta3d:publish_dev": "cross-env NODE_ENV=development npm run webpack && gulp publish_local_env",
"meta3d:publish_pro": "cross-env NODE_ENV=production npm run webpack && gulp publish_production_env"
},
Expand Down
6 changes: 6 additions & 0 deletions defaults/meta3d-type/src/Index.res
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,17 @@ type nullableAPI = {

type list

type arrayData

type map

type dictData

type immutableAPI = {
createList: (. state) => list,
createListOfData: (. state, arrayData) => list,
createMap: (. state) => map,
createMapOfData: (. state, dictData) => map,
}

type actionName = string
Expand Down
7 changes: 6 additions & 1 deletion defaults/meta3d-type/src/Index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ export type nullableAPI = {
};

// tslint:disable-next-line:interface-over-type-literal
export type immutableAPI = { createList: <T>(state: state) => List<T>; createMap: <K, V>(state: state) => Map<K, V> };
export type immutableAPI = {
createList: <T>(state: state) => List<T>;
createListOfData: <T>(state: state, data: Array<T>) => List<T>;
createMap: <K, V>(state: state) => Map<K, V>
createMapOfData: <K extends string, V>(state: state, data: Record<K, V>) => Map<K, V>
};

// tslint:disable-next-line:interface-over-type-literal
export type actionAPI = { getActionState: <actionState> (state: state, actionName: string) => actionState; setActionState: <actionState> (state: state, actionName: string, actionState: actionState) => state };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type versionRange = string

type generateUIControlCommonDataStr = string => string

type uiControlSpecicFieldType = [#string | #imageBase64]
type uiControlSpecicFieldType = [#string | #imageBase64 | #menuItems]

type uiControlSpecicFieldValue

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export type versionRange = string
export type generateUIControlCommonDataStr = (rect: string) => string


type uiControlSpecicFieldType = "string" | "imageBase64"
type uiControlSpecicFieldType = "string" | "imageBase64" | "menuItems"

type uiControlSpecicFieldValue = any

Expand Down
10 changes: 10 additions & 0 deletions defaults/meta3d/lib/es6_global/src/ExtensionManager.bs.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,21 @@ function _buildImmutableAPI(nullableAPI, getPackageService) {
let { createList } = nullableAPI.getExn(getPackageService(state, "meta3d-editor-whole-protocol")).core(state).immutable(state)

return createList()
}),
createListOfData: (function (state, data){
let { createListOfData } = nullableAPI.getExn(getPackageService(state, "meta3d-editor-whole-protocol")).core(state).immutable(state)

return createListOfData(data)
}),
createMap: (function (state){
let { createMap } = nullableAPI.getExn(getPackageService(state, "meta3d-editor-whole-protocol")).core(state).immutable(state)

return createMap()
}),
createMapOfData: (function (state, data){
let { createMapOfData } = nullableAPI.getExn(getPackageService(state, "meta3d-editor-whole-protocol")).core(state).immutable(state)

return createMapOfData(data)
})
};
}
Expand Down
Loading

0 comments on commit b05617f

Please sign in to comment.