@next-libs/visual-builder 1.1.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.
Files changed (61) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/README.md +13 -0
  3. package/dist/cjs/index.js +45 -0
  4. package/dist/cjs/index.js.map +1 -0
  5. package/dist/cjs/interfaces/brick-visualization.js +22 -0
  6. package/dist/cjs/interfaces/brick-visualization.js.map +1 -0
  7. package/dist/cjs/interfaces/index.js +19 -0
  8. package/dist/cjs/interfaces/index.js.map +1 -0
  9. package/dist/cjs/visual-property-form/VisualPropertyForm.js +282 -0
  10. package/dist/cjs/visual-property-form/VisualPropertyForm.js.map +1 -0
  11. package/dist/cjs/visual-property-form/components/CodeEditor/CodeEditorFormItem.js +64 -0
  12. package/dist/cjs/visual-property-form/components/CodeEditor/CodeEditorFormItem.js.map +1 -0
  13. package/dist/cjs/visual-property-form/components/ColorEditor/ColorEditorItem.js +100 -0
  14. package/dist/cjs/visual-property-form/components/ColorEditor/ColorEditorItem.js.map +1 -0
  15. package/dist/cjs/visual-property-form/components/IconSelect/IconSelectFormItem.js +35 -0
  16. package/dist/cjs/visual-property-form/components/IconSelect/IconSelectFormItem.js.map +1 -0
  17. package/dist/cjs/visual-property-form/components/MenuEditor/MenuEditorItem.js +83 -0
  18. package/dist/cjs/visual-property-form/components/MenuEditor/MenuEditorItem.js.map +1 -0
  19. package/dist/cjs/visual-property-form/constant.js +54 -0
  20. package/dist/cjs/visual-property-form/constant.js.map +1 -0
  21. package/dist/cjs/visual-property-form/processor.js +204 -0
  22. package/dist/cjs/visual-property-form/processor.js.map +1 -0
  23. package/dist/esm/index.js +4 -0
  24. package/dist/esm/index.js.map +1 -0
  25. package/dist/esm/interfaces/brick-visualization.js +14 -0
  26. package/dist/esm/interfaces/brick-visualization.js.map +1 -0
  27. package/dist/esm/interfaces/index.js +2 -0
  28. package/dist/esm/interfaces/index.js.map +1 -0
  29. package/dist/esm/visual-property-form/VisualPropertyForm.js +253 -0
  30. package/dist/esm/visual-property-form/VisualPropertyForm.js.map +1 -0
  31. package/dist/esm/visual-property-form/VisualPropertyForm.module.css +33 -0
  32. package/dist/esm/visual-property-form/components/CodeEditor/CodeEditorFormItem.js +58 -0
  33. package/dist/esm/visual-property-form/components/CodeEditor/CodeEditorFormItem.js.map +1 -0
  34. package/dist/esm/visual-property-form/components/ColorEditor/ColorEditor.module.css +32 -0
  35. package/dist/esm/visual-property-form/components/ColorEditor/ColorEditorItem.js +81 -0
  36. package/dist/esm/visual-property-form/components/ColorEditor/ColorEditorItem.js.map +1 -0
  37. package/dist/esm/visual-property-form/components/IconSelect/IconSelectFormItem.js +23 -0
  38. package/dist/esm/visual-property-form/components/IconSelect/IconSelectFormItem.js.map +1 -0
  39. package/dist/esm/visual-property-form/components/MenuEditor/MenuEditorItem.js +77 -0
  40. package/dist/esm/visual-property-form/components/MenuEditor/MenuEditorItem.js.map +1 -0
  41. package/dist/esm/visual-property-form/constant.js +43 -0
  42. package/dist/esm/visual-property-form/constant.js.map +1 -0
  43. package/dist/esm/visual-property-form/images/empty-dark.svg +54 -0
  44. package/dist/esm/visual-property-form/processor.js +183 -0
  45. package/dist/esm/visual-property-form/processor.js.map +1 -0
  46. package/dist/types/index.d.ts +3 -0
  47. package/dist/types/interfaces/brick-visualization.d.ts +32 -0
  48. package/dist/types/interfaces/index.d.ts +1 -0
  49. package/dist/types/visual-property-form/VisualPropertyForm.d.ts +22 -0
  50. package/dist/types/visual-property-form/VisualPropertyForm.spec.d.ts +1 -0
  51. package/dist/types/visual-property-form/components/CodeEditor/CodeEditorFormItem.d.ts +7 -0
  52. package/dist/types/visual-property-form/components/CodeEditor/CodeEditorFormItem.spec.d.ts +1 -0
  53. package/dist/types/visual-property-form/components/ColorEditor/ColorEditorItem.d.ts +17 -0
  54. package/dist/types/visual-property-form/components/ColorEditor/ColorEditorItem.spec.d.ts +1 -0
  55. package/dist/types/visual-property-form/components/IconSelect/IconSelectFormItem.d.ts +3 -0
  56. package/dist/types/visual-property-form/components/IconSelect/IconSelectFormItem.spec.d.ts +1 -0
  57. package/dist/types/visual-property-form/components/MenuEditor/MenuEditorItem.d.ts +11 -0
  58. package/dist/types/visual-property-form/components/MenuEditor/MenuEditorItem.spec.d.ts +1 -0
  59. package/dist/types/visual-property-form/constant.d.ts +31 -0
  60. package/dist/types/visual-property-form/processor.d.ts +27 -0
  61. package/package.json +39 -0
@@ -0,0 +1,43 @@
1
+ export var groupI18nMap = {
2
+ basic: {
3
+ en: "Basic",
4
+ zh: "常用"
5
+ },
6
+ ui: {
7
+ en: "UI",
8
+ zh: "外观"
9
+ },
10
+ advanced: {
11
+ en: "Advanced",
12
+ zh: "高级"
13
+ },
14
+ basicFormItem: {
15
+ en: "Basic Form Item",
16
+ zh: "表单项常用"
17
+ },
18
+ advancedFormItem: {
19
+ en: "Advanced Form Item",
20
+ zh: "表单项高级"
21
+ },
22
+ other: {
23
+ en: "Other",
24
+ zh: "其他"
25
+ }
26
+ };
27
+ export var supportBasicType = ["boolean", "number", "string", "string[]", "MenuIcon", "Color"];
28
+ export var supportMenuType = ["Menu", "SidebarSubMenu"];
29
+ export var OTHER_FORM_ITEM_FIELD = "others";
30
+ export var commonProps = [{
31
+ name: "id",
32
+ type: "string",
33
+ description: "构件 ID",
34
+ group: "basic",
35
+ groupI18N: groupI18nMap
36
+ }, {
37
+ name: "style",
38
+ type: "Record<string, any>",
39
+ description: "构件样式",
40
+ group: "ui",
41
+ groupI18N: groupI18nMap
42
+ }];
43
+ //# sourceMappingURL=constant.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constant.js","names":["groupI18nMap","basic","en","zh","ui","advanced","basicFormItem","advancedFormItem","other","supportBasicType","supportMenuType","OTHER_FORM_ITEM_FIELD","commonProps","name","type","description","group","groupI18N"],"sources":["../../../src/visual-property-form/constant.ts"],"sourcesContent":["import { PropertyType } from \"../interfaces\";\n\nexport const groupI18nMap = {\n basic: {\n en: \"Basic\",\n zh: \"常用\",\n },\n ui: {\n en: \"UI\",\n zh: \"外观\",\n },\n advanced: {\n en: \"Advanced\",\n zh: \"高级\",\n },\n basicFormItem: {\n en: \"Basic Form Item\",\n zh: \"表单项常用\",\n },\n advancedFormItem: {\n en: \"Advanced Form Item\",\n zh: \"表单项高级\",\n },\n other: {\n en: \"Other\",\n zh: \"其他\",\n },\n};\n\nexport const supportBasicType = [\n \"boolean\",\n \"number\",\n \"string\",\n \"string[]\",\n \"MenuIcon\",\n \"Color\",\n];\n\nexport const supportMenuType = [\"Menu\", \"SidebarSubMenu\"];\n\nexport const OTHER_FORM_ITEM_FIELD = \"others\";\n\nexport const commonProps: PropertyType[] = [\n {\n name: \"id\",\n type: \"string\",\n description: \"构件 ID\",\n group: \"basic\",\n groupI18N: groupI18nMap,\n },\n {\n name: \"style\",\n type: \"Record<string, any>\",\n description: \"构件样式\",\n group: \"ui\",\n groupI18N: groupI18nMap,\n },\n];\n"],"mappings":"AAEA,OAAO,IAAMA,YAAY,GAAG;EAC1BC,KAAK,EAAE;IACLC,EAAE,EAAE,OADC;IAELC,EAAE,EAAE;EAFC,CADmB;EAK1BC,EAAE,EAAE;IACFF,EAAE,EAAE,IADF;IAEFC,EAAE,EAAE;EAFF,CALsB;EAS1BE,QAAQ,EAAE;IACRH,EAAE,EAAE,UADI;IAERC,EAAE,EAAE;EAFI,CATgB;EAa1BG,aAAa,EAAE;IACbJ,EAAE,EAAE,iBADS;IAEbC,EAAE,EAAE;EAFS,CAbW;EAiB1BI,gBAAgB,EAAE;IAChBL,EAAE,EAAE,oBADY;IAEhBC,EAAE,EAAE;EAFY,CAjBQ;EAqB1BK,KAAK,EAAE;IACLN,EAAE,EAAE,OADC;IAELC,EAAE,EAAE;EAFC;AArBmB,CAArB;AA2BP,OAAO,IAAMM,gBAAgB,GAAG,CAC9B,SAD8B,EAE9B,QAF8B,EAG9B,QAH8B,EAI9B,UAJ8B,EAK9B,UAL8B,EAM9B,OAN8B,CAAzB;AASP,OAAO,IAAMC,eAAe,GAAG,CAAC,MAAD,EAAS,gBAAT,CAAxB;AAEP,OAAO,IAAMC,qBAAqB,GAAG,QAA9B;AAEP,OAAO,IAAMC,WAA2B,GAAG,CACzC;EACEC,IAAI,EAAE,IADR;EAEEC,IAAI,EAAE,QAFR;EAGEC,WAAW,EAAE,OAHf;EAIEC,KAAK,EAAE,OAJT;EAKEC,SAAS,EAAEjB;AALb,CADyC,EAQzC;EACEa,IAAI,EAAE,OADR;EAEEC,IAAI,EAAE,qBAFR;EAGEC,WAAW,EAAE,MAHf;EAIEC,KAAK,EAAE,IAJT;EAKEC,SAAS,EAAEjB;AALb,CARyC,CAApC"}
@@ -0,0 +1,54 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <svg width="56px" height="53px" viewBox="0 0 56 53" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
3
+ <title>插图/空表格 白色背景备份</title>
4
+ <defs>
5
+ <linearGradient x1="7.2497624%" y1="5.98667004%" x2="83.0501817%" y2="88.9150948%" id="linearGradient-1">
6
+ <stop stop-color="#595959" offset="0%"></stop>
7
+ <stop stop-color="#484848" offset="100%"></stop>
8
+ </linearGradient>
9
+ <linearGradient x1="3.89238729%" y1="4.31113823%" x2="84.4129339%" y2="88.9150948%" id="linearGradient-2">
10
+ <stop stop-color="#646464" offset="0%"></stop>
11
+ <stop stop-color="#4F4F4F" offset="100%"></stop>
12
+ </linearGradient>
13
+ <path d="M23.6721311,23.6065574 L26.1639344,23.6065574 C28.3730734,23.6065574 30.1639344,25.3974184 30.1639344,27.6065574 L30.1639344,30.0983607 C30.1639344,32.3074997 28.3730734,34.0983607 26.1639344,34.0983607 L23.6721311,34.0983607 C21.4629921,34.0983607 19.6721311,32.3074997 19.6721311,30.0983607 L19.6721311,27.6065574 C19.6721311,25.3974184 21.4629921,23.6065574 23.6721311,23.6065574 Z" id="path-3"></path>
14
+ <filter x="-57.2%" y="-47.7%" width="233.4%" height="233.4%" filterUnits="objectBoundingBox" id="filter-4">
15
+ <feOffset dx="1" dy="2" in="SourceAlpha" result="shadowOffsetOuter1"></feOffset>
16
+ <feGaussianBlur stdDeviation="2" in="shadowOffsetOuter1" result="shadowBlurOuter1"></feGaussianBlur>
17
+ <feComposite in="shadowBlurOuter1" in2="SourceAlpha" operator="out" result="shadowBlurOuter1"></feComposite>
18
+ <feColorMatrix values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.22 0" type="matrix" in="shadowBlurOuter1"></feColorMatrix>
19
+ </filter>
20
+ <linearGradient x1="41.822656%" y1="24.7954546%" x2="8.8126561%" y2="86.4269134%" id="linearGradient-5">
21
+ <stop stop-color="#848484" offset="0%"></stop>
22
+ <stop stop-color="#686868" offset="100%"></stop>
23
+ </linearGradient>
24
+ <path d="M37.3114754,12.4590164 C39.5206144,12.4590164 41.3114754,14.2498774 41.3114754,16.4590164 L41.3114754,19.8778416 L33.8926502,12.4590164 L37.3114754,12.4590164 Z" id="path-6"></path>
25
+ <filter x="-94.4%" y="-121.3%" width="288.7%" height="288.7%" filterUnits="objectBoundingBox" id="filter-7">
26
+ <feOffset dx="0" dy="-2" in="SourceAlpha" result="shadowOffsetOuter1"></feOffset>
27
+ <feGaussianBlur stdDeviation="2" in="shadowOffsetOuter1" result="shadowBlurOuter1"></feGaussianBlur>
28
+ <feColorMatrix values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.25 0" type="matrix" in="shadowBlurOuter1"></feColorMatrix>
29
+ </filter>
30
+ </defs>
31
+ <g id="其他" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
32
+ <g id="空状态" transform="translate(-873.000000, -283.000000)">
33
+ <g id="编组-8" transform="translate(726.000000, 100.000000)">
34
+ <g id="插图/空表格--白色背景备份" transform="translate(147.000000, 183.000000)">
35
+ <path d="M39.6824378,33.9672131 L10.8093655,33.9672131 C10.0855554,33.9672131 9.38986655,34.247506 8.86822799,34.7492971 L3.67213115,39.7476907 L3.67213115,39.7476907 L3.67213115,46.7278689 C3.67213115,49.8206635 6.17933655,52.3278689 9.27213115,52.3278689 L41.2196721,52.3278689 C44.3124667,52.3278689 46.8196721,49.8206635 46.8196721,46.7278689 L46.8196721,39.7476907 L46.8196721,39.7476907 L41.6235753,34.7492971 C41.1019367,34.247506 40.4062478,33.9672131 39.6824378,33.9672131 Z" id="Fill-3" fill="#3E3E3E"></path>
36
+ <path d="M33.8926502,12.4590164 L41.3114754,19.8778416 L41.3114754,42.4459016 C41.3114754,43.9922989 40.0578727,45.2459016 38.5114754,45.2459016 L11.9803279,45.2459016 C10.4339306,45.2459016 9.18032787,43.9922989 9.18032787,42.4459016 L9.18032787,18.4590164 C9.18032787,15.1453079 11.8666194,12.4590164 15.1803279,12.4590164 L33.8926502,12.4590164 Z" id="形状结合" fill="url(#linearGradient-1)"></path>
37
+ <g id="矩形备份">
38
+ <use fill="black" fill-opacity="1" filter="url(#filter-4)" xlink:href="#path-3"></use>
39
+ <path stroke="#919191" stroke-width="1" d="M26.1639344,24.1065574 C27.1304327,24.1065574 28.0054327,24.4983082 28.6388082,25.1316836 C29.2721836,25.7650591 29.6639344,26.6400591 29.6639344,27.6065574 L29.6639344,27.6065574 L29.6639344,30.0983607 C29.6639344,31.064859 29.2721836,31.939859 28.6388082,32.5732344 C28.0054327,33.2066098 27.1304327,33.5983607 26.1639344,33.5983607 L26.1639344,33.5983607 L23.6721311,33.5983607 C22.7056328,33.5983607 21.8306328,33.2066098 21.1972574,32.5732344 C20.563882,31.939859 20.1721311,31.064859 20.1721311,30.0983607 L20.1721311,30.0983607 L20.1721311,27.6065574 C20.1721311,26.6400591 20.563882,25.7650591 21.1972574,25.1316836 C21.8306328,24.4983082 22.7056328,24.1065574 23.6721311,24.1065574 L23.6721311,24.1065574 Z" stroke-linejoin="square" fill="url(#linearGradient-2)" fill-rule="evenodd"></path>
40
+ </g>
41
+ <g id="形状结合" transform="translate(37.602063, 16.168429) scale(-1, -1) translate(-37.602063, -16.168429) ">
42
+ <use fill="black" fill-opacity="1" filter="url(#filter-7)" xlink:href="#path-6"></use>
43
+ <use fill="url(#linearGradient-5)" fill-rule="evenodd" xlink:href="#path-6"></use>
44
+ </g>
45
+ <path d="M54.1639344,27.5409836 C54.4174422,27.5409836 54.6229508,27.7464922 54.6229508,28 L54.6228689,28.9179836 L55.5409836,28.9180328 C55.7944914,28.9180328 56,29.1235414 56,29.3770492 C56,29.6305569 55.7944914,29.8360656 55.5409836,29.8360656 L54.6228689,29.8359836 L54.6229508,30.7540984 C54.6229508,31.0076061 54.4174422,31.2131148 54.1639344,31.2131148 C53.9104267,31.2131148 53.704918,31.0076061 53.704918,30.7540984 L53.7048689,29.8359836 L52.7868852,29.8360656 C52.5333775,29.8360656 52.3278689,29.6305569 52.3278689,29.3770492 C52.3278689,29.1235414 52.5333775,28.9180328 52.7868852,28.9180328 L53.7048689,28.9179836 L53.704918,28 C53.704918,27.7464922 53.9104267,27.5409836 54.1639344,27.5409836 Z" id="形状结合" fill="#646465" opacity="0.299999982"></path>
46
+ <path d="M1.37704918,20.1967213 C1.56718,20.1967213 1.72131148,20.3508528 1.72131148,20.5409836 L1.721,21.1147213 L2.29508197,21.1147541 C2.54858972,21.1147541 2.75409836,21.3202627 2.75409836,21.5737705 C2.75409836,21.8272782 2.54858972,22.0327869 2.29508197,22.0327869 L1.721,22.0327213 L1.72131148,22.6065574 C1.72131148,22.7966882 1.56718,22.9508197 1.37704918,22.9508197 C1.18691836,22.9508197 1.03278689,22.7966882 1.03278689,22.6065574 L1.032,22.0327213 L0.459016393,22.0327869 C0.205508639,22.0327869 3.1045746e-17,21.8272782 0,21.5737705 C-3.1045746e-17,21.3202627 0.205508639,21.1147541 0.459016393,21.1147541 L1.032,21.1147213 L1.03278689,20.5409836 C1.03278689,20.3508528 1.18691836,20.1967213 1.37704918,20.1967213 Z" id="形状结合备份-2" fill="#646465" opacity="0.299999982"></path>
47
+ <path d="M24.7868852,43.5295076 L24.8011005,43.5307601 C31.8876782,43.6725873 34.6183834,39.6961587 37.5855745,39.48387 L37.7753351,39.4755076 L46.8196721,39.4755076 L46.8196721,49.5278689 C46.8196721,51.0169922 45.6572093,52.2346078 44.1902403,52.3227588 L44.0196721,52.3278689 L24.7868852,52.3275076 L24.7868852,52.3272615 L6.47213115,52.3277253 L6.30156296,52.3226152 C4.83459401,52.2344642 3.67213115,51.0168486 3.67213115,49.5277253 L3.67213115,49.5277253 L3.67213115,39.4754333 L11.7984354,39.4754333 L11.941603,39.4712638 C14.4272721,39.4747517 17.1558091,43.3688567 24.77267,43.5306166 L24.77267,43.5306166 L24.7868852,43.5292615 L24.7868852,43.5295076 Z" id="形状结合" fill="#616161"></path>
48
+ <path d="M13.7704918,2.20053283 C13.7704918,2.20053283 16.0775627,1.64513672 16.7320305,0 C17.67481,1.34913293 18.1609037,1.93253682 19.2786885,2.18900021 C17.7566906,2.64243336 17.0955917,3.151699 16.5749006,4.59016393 C15.9772302,2.89541866 15.4331859,2.67611591 13.7704918,2.20053283" id="Fill-1" fill="#646465" opacity="0.5"></path>
49
+ <path d="M41.3114754,6.63941814 C41.3114754,6.63941814 47.4636646,5.19538826 49.2089119,0.918032787 C51.7229907,4.4257784 53.0192405,5.94262851 56,6.60943334 C51.9413388,7.78835951 50.1784084,9.11245019 48.7898988,12.852459 C47.1961112,8.44612131 45.7453263,7.87593416 41.3114754,6.63941814" id="Fill-1备份" fill="#646465" opacity="0.697637649"></path>
50
+ </g>
51
+ </g>
52
+ </g>
53
+ </g>
54
+ </svg>
@@ -0,0 +1,183 @@
1
+ import _objectSpread from "@babel/runtime/helpers/objectSpread2";
2
+ import { i18nText } from "@next-core/brick-kit";
3
+ import { ItemModeType } from "../interfaces";
4
+ import { safeDump, JSON_SCHEMA, safeLoad } from "js-yaml";
5
+ import { omit, isEmpty, groupBy } from "lodash";
6
+ import { supportBasicType, supportMenuType, OTHER_FORM_ITEM_FIELD, commonProps, groupI18nMap } from "./constant";
7
+ export function isAdvanceMode(value) {
8
+ if (typeof value === "string" && (value.startsWith("<%") || value.includes("${"))) {
9
+ return true;
10
+ }
11
+
12
+ return false;
13
+ }
14
+ export function mergeProperties() {
15
+ var propertyList = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
16
+ var brickProperties = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
17
+ return propertyList === null || propertyList === void 0 ? void 0 : propertyList.map(item => _objectSpread(_objectSpread({}, item), {}, {
18
+ value: brickProperties === null || brickProperties === void 0 ? void 0 : brickProperties[item.name],
19
+ mode: isAdvanceMode(brickProperties === null || brickProperties === void 0 ? void 0 : brickProperties[item.name]) ? ItemModeType.Advanced : ItemModeType.Normal
20
+ }));
21
+ }
22
+ export function yamlStringify(value) {
23
+ var indent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 2;
24
+ return safeDump(value, {
25
+ indent,
26
+ schema: JSON_SCHEMA,
27
+ skipInvalid: true,
28
+ noRefs: true,
29
+ noCompatMode: true
30
+ });
31
+ }
32
+ export function yaml(value) {
33
+ return safeLoad(value, {
34
+ schema: JSON_SCHEMA,
35
+ json: true
36
+ });
37
+ }
38
+ export function matchNoramlMenuValue(value) {
39
+ if (typeof value === "string") {
40
+ var _value$match, _value$match$;
41
+
42
+ var reg = /<% APP\.getMenu\((.*)\) %>/;
43
+ return ((_value$match = value.match(reg)) === null || _value$match === void 0 ? void 0 : (_value$match$ = _value$match[1]) === null || _value$match$ === void 0 ? void 0 : _value$match$.replace(/'|"/g, "")) || value;
44
+ }
45
+
46
+ return value;
47
+ }
48
+
49
+ function calcMenuValue(value) {
50
+ if (typeof value === "string") {
51
+ if (value.startsWith("<%")) {
52
+ return value;
53
+ }
54
+
55
+ return "<% APP.getMenu('".concat(value, "') %>");
56
+ }
57
+
58
+ return value;
59
+ }
60
+
61
+ export function calculateValue() {
62
+ var propertyList = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
63
+ var brickProperties = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
64
+ var typeList = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
65
+ var othersValue = {};
66
+
67
+ var _loop = function (key, value) {
68
+ var find = propertyList.find(item => item.name === key);
69
+
70
+ if (!find) {
71
+ othersValue[key] = value;
72
+ }
73
+ };
74
+
75
+ for (var [key, value] of Object.entries(brickProperties)) {
76
+ _loop(key, value);
77
+ }
78
+
79
+ var processValue = propertyList.reduce((obj, item) => {
80
+ var v = brickProperties[item.name];
81
+ obj[item.name] = v;
82
+
83
+ if (v !== undefined) {
84
+ if (!supportBasicType.concat(supportMenuType).includes(item.type)) {
85
+ obj[item.name] = yamlStringify(v);
86
+ }
87
+
88
+ if (supportMenuType.includes(item.type)) {
89
+ var selected = typeList.find(typeItem => typeItem.name === item.name);
90
+
91
+ if ((selected === null || selected === void 0 ? void 0 : selected.mode) === ItemModeType.Advanced) {
92
+ obj[item.name] = v;
93
+ } else {
94
+ obj[item.name] = matchNoramlMenuValue(v);
95
+ }
96
+ }
97
+ }
98
+
99
+ return obj;
100
+ }, {});
101
+ return _objectSpread(_objectSpread({}, processValue), {}, {
102
+ [OTHER_FORM_ITEM_FIELD]: isEmpty(othersValue) ? "" : yamlStringify(othersValue)
103
+ });
104
+ }
105
+ /**
106
+ * @description 判断是否用使用 yaml 把用户输入解析成 JSON 的模式,当前只有以下情况下会进行解析,其他情况不对数据进行处理
107
+ * 1. 当前属性的类型不是内置支持的类型
108
+ * 2. 当前属性虽然是支持的类型,但是当前切换到高级模式编辑
109
+ * 3. 不是构件本身申明的属性,为 html 共有的通用属性,目前统一放在 others 的编辑器中
110
+ * @param field 字段值
111
+ * @param typeList 属性列表包含每个属性的类型和当前编辑模式
112
+ * @return boolean
113
+ */
114
+
115
+ export function isUseYamlParse(field, typeList) {
116
+ if (typeof field.value !== "string") return false;
117
+ if (field.key === OTHER_FORM_ITEM_FIELD) return true;
118
+ var find = typeList === null || typeList === void 0 ? void 0 : typeList.find(item => item.name === field.key);
119
+
120
+ if (find) {
121
+ if (supportMenuType.includes(find.type) && find.mode !== ItemModeType.Advanced) return false;
122
+ var isBasicType = supportBasicType.includes(find.type);
123
+ if (isBasicType && find.mode === ItemModeType.Advanced) return true;
124
+ if (!isBasicType) return true;
125
+ }
126
+
127
+ return false;
128
+ }
129
+ export function isUseMenuParse(field, typeList) {
130
+ var item = typeList.find(item => item.name === field.key);
131
+
132
+ if (supportMenuType.includes(item === null || item === void 0 ? void 0 : item.type)) {
133
+ return true;
134
+ }
135
+
136
+ return false;
137
+ }
138
+ export function processFormValue() {
139
+ var values = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
140
+ var typeList = arguments.length > 1 ? arguments[1] : undefined;
141
+ var formData = {};
142
+
143
+ for (var [key, value] of Object.entries(values)) {
144
+ if (isUseYamlParse({
145
+ key,
146
+ value
147
+ }, typeList)) {
148
+ formData[key] = yaml(value);
149
+ } else if (isUseMenuParse({
150
+ key,
151
+ value
152
+ }, typeList)) {
153
+ formData[key] = calcMenuValue(value);
154
+ } else {
155
+ formData[key] = value;
156
+ }
157
+ }
158
+
159
+ return _objectSpread(_objectSpread({}, omit(formData, OTHER_FORM_ITEM_FIELD)), isEmpty(formData[OTHER_FORM_ITEM_FIELD]) ? {} : formData[OTHER_FORM_ITEM_FIELD]);
160
+ }
161
+ export function groupByType() {
162
+ var typeList = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
163
+ var normals = typeList.filter(item => item.group !== "other");
164
+ var others = typeList.filter(item => item.group === "other");
165
+ return Object.entries(groupBy(normals.concat(others), item => {
166
+ var group = item.group || "basic";
167
+
168
+ var groupI18N = _objectSpread(_objectSpread({}, groupI18nMap), item.groupI18N);
169
+
170
+ var i18nData = groupI18N && groupI18N[group];
171
+
172
+ if (i18nData) {
173
+ return i18nText(i18nData);
174
+ }
175
+
176
+ return group;
177
+ }));
178
+ }
179
+ export function extractCommonProps(typeList) {
180
+ if (isEmpty(typeList)) return [];
181
+ return commonProps.concat(typeList);
182
+ }
183
+ //# sourceMappingURL=processor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"processor.js","names":["i18nText","ItemModeType","safeDump","JSON_SCHEMA","safeLoad","omit","isEmpty","groupBy","supportBasicType","supportMenuType","OTHER_FORM_ITEM_FIELD","commonProps","groupI18nMap","isAdvanceMode","value","startsWith","includes","mergeProperties","propertyList","brickProperties","map","item","name","mode","Advanced","Normal","yamlStringify","indent","schema","skipInvalid","noRefs","noCompatMode","yaml","json","matchNoramlMenuValue","reg","match","replace","calcMenuValue","calculateValue","typeList","othersValue","key","find","Object","entries","processValue","reduce","obj","v","undefined","concat","type","selected","typeItem","isUseYamlParse","field","isBasicType","isUseMenuParse","processFormValue","values","formData","groupByType","normals","filter","group","others","groupI18N","i18nData","extractCommonProps"],"sources":["../../../src/visual-property-form/processor.ts"],"sourcesContent":["import { i18nText } from \"@next-core/brick-kit\";\nimport {\n PropertyType,\n UnionPropertyType,\n BrickProperties,\n ItemModeType,\n} from \"../interfaces\";\nimport { safeDump, JSON_SCHEMA, safeLoad } from \"js-yaml\";\nimport { omit, isEmpty, groupBy } from \"lodash\";\nimport {\n supportBasicType,\n supportMenuType,\n OTHER_FORM_ITEM_FIELD,\n commonProps,\n groupI18nMap,\n} from \"./constant\";\n\nexport function isAdvanceMode(value: unknown): boolean {\n if (\n typeof value === \"string\" &&\n (value.startsWith(\"<%\") || value.includes(\"${\"))\n ) {\n return true;\n }\n\n return false;\n}\n\nexport function mergeProperties(\n propertyList: PropertyType[] = [],\n brickProperties: BrickProperties = {}\n): UnionPropertyType[] {\n return propertyList?.map((item) => ({\n ...item,\n value: brickProperties?.[item.name],\n mode: isAdvanceMode(brickProperties?.[item.name])\n ? ItemModeType.Advanced\n : ItemModeType.Normal,\n }));\n}\n\nexport function yamlStringify(value: unknown, indent = 2): string {\n return safeDump(value, {\n indent,\n schema: JSON_SCHEMA,\n skipInvalid: true,\n noRefs: true,\n noCompatMode: true,\n });\n}\n\nexport function yaml(value: string): any {\n return safeLoad(value, { schema: JSON_SCHEMA, json: true });\n}\n\nexport function matchNoramlMenuValue(value: unknown): unknown {\n if (typeof value === \"string\") {\n const reg = /<% APP\\.getMenu\\((.*)\\) %>/;\n return value.match(reg)?.[1]?.replace(/'|\"/g, \"\") || value;\n }\n return value;\n}\n\nfunction calcMenuValue(value: string): string {\n if (typeof value === \"string\") {\n if (value.startsWith(\"<%\")) {\n return value;\n }\n return `<% APP.getMenu('${value}') %>`;\n }\n return value;\n}\n\nexport function calculateValue(\n propertyList: PropertyType[] = [],\n brickProperties: BrickProperties = {},\n typeList: UnionPropertyType[] = []\n): Record<string, any> {\n const othersValue: Record<string, any> = {};\n for (const [key, value] of Object.entries(brickProperties)) {\n const find = propertyList.find((item) => item.name === key);\n if (!find) {\n othersValue[key] = value;\n }\n }\n\n const processValue = propertyList.reduce((obj: any, item) => {\n const v = brickProperties[item.name];\n obj[item.name] = v;\n if (v !== undefined) {\n if (\n !supportBasicType.concat(supportMenuType).includes(item.type as string)\n ) {\n obj[item.name] = yamlStringify(v);\n }\n\n if (supportMenuType.includes(item.type as string)) {\n const selected = typeList.find(\n (typeItem) => typeItem.name === item.name\n );\n if (selected?.mode === ItemModeType.Advanced) {\n obj[item.name] = v;\n } else {\n obj[item.name] = matchNoramlMenuValue(v);\n }\n }\n }\n return obj;\n }, {});\n\n return {\n ...processValue,\n [OTHER_FORM_ITEM_FIELD]: isEmpty(othersValue)\n ? \"\"\n : yamlStringify(othersValue),\n };\n}\n\n/**\n * @description 判断是否用使用 yaml 把用户输入解析成 JSON 的模式,当前只有以下情况下会进行解析,其他情况不对数据进行处理\n * 1. 当前属性的类型不是内置支持的类型\n * 2. 当前属性虽然是支持的类型,但是当前切换到高级模式编辑\n * 3. 不是构件本身申明的属性,为 html 共有的通用属性,目前统一放在 others 的编辑器中\n * @param field 字段值\n * @param typeList 属性列表包含每个属性的类型和当前编辑模式\n * @return boolean\n */\n\nexport function isUseYamlParse(\n field: { key: string; value: any },\n typeList: UnionPropertyType[]\n): boolean {\n if (typeof field.value !== \"string\") return false;\n\n if (field.key === OTHER_FORM_ITEM_FIELD) return true;\n\n const find = typeList?.find((item) => item.name === field.key);\n\n if (find) {\n if (\n supportMenuType.includes(find.type as string) &&\n find.mode !== ItemModeType.Advanced\n )\n return false;\n\n const isBasicType = supportBasicType.includes(find.type as string);\n\n if (isBasicType && find.mode === ItemModeType.Advanced) return true;\n\n if (!isBasicType) return true;\n }\n\n return false;\n}\n\nexport function isUseMenuParse(\n field: { key: string; value: any },\n typeList: UnionPropertyType[]\n): boolean {\n const item = typeList.find((item) => item.name === field.key);\n if (supportMenuType.includes(item?.type as string)) {\n return true;\n }\n return false;\n}\n\nexport function processFormValue(\n values = {},\n typeList: UnionPropertyType[]\n): Record<string, any> {\n const formData: Record<string, any> = {};\n for (const [key, value] of Object.entries(values)) {\n if (isUseYamlParse({ key, value }, typeList)) {\n formData[key] = yaml(value as any);\n } else if (isUseMenuParse({ key, value }, typeList)) {\n formData[key] = calcMenuValue(value as string);\n } else {\n formData[key] = value;\n }\n }\n\n return {\n ...omit(formData, OTHER_FORM_ITEM_FIELD),\n ...(isEmpty(formData[OTHER_FORM_ITEM_FIELD])\n ? {}\n : formData[OTHER_FORM_ITEM_FIELD]),\n };\n}\n\nexport function groupByType(\n typeList: UnionPropertyType[] = []\n): Array<[string, UnionPropertyType[]]> {\n const normals = typeList.filter((item) => item.group !== \"other\");\n const others = typeList.filter((item) => item.group === \"other\");\n\n return Object.entries(\n groupBy(normals.concat(others), (item) => {\n const group = item.group || \"basic\";\n const groupI18N: Record<string, any> = {\n ...groupI18nMap,\n ...item.groupI18N,\n };\n const i18nData = groupI18N && groupI18N[group];\n if (i18nData) {\n return i18nText(i18nData);\n }\n\n return group;\n })\n );\n}\n\nexport function extractCommonProps(typeList: PropertyType[]): PropertyType[] {\n if (isEmpty(typeList)) return [];\n\n return commonProps.concat(typeList);\n}\n"],"mappings":";AAAA,SAASA,QAAT,QAAyB,sBAAzB;AACA,SAIEC,YAJF,QAKO,eAL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D;AAED,OAAO,SAASI,kBAAT,CAA4B7B,QAA5B,EAAsE;EAC3E,IAAIlC,OAAO,CAACkC,QAAD,CAAX,EAAuB,OAAO,EAAP;EAEvB,OAAO7B,WAAW,CAACwC,MAAZ,CAAmBX,QAAnB,CAAP;AACD"}
@@ -0,0 +1,3 @@
1
+ export * from "./visual-property-form/VisualPropertyForm";
2
+ export * from "./interfaces";
3
+ export * from "./visual-property-form/processor";
@@ -0,0 +1,32 @@
1
+ import { FormInstance } from "antd/lib/form";
2
+ export declare type FormItemType = boolean | string | string[] | number | Record<string, any>;
3
+ export declare enum Required {
4
+ True = "true",
5
+ False = "false"
6
+ }
7
+ export declare enum ItemModeType {
8
+ Normal = "normal",
9
+ Advanced = "advanced"
10
+ }
11
+ export interface PropertyType {
12
+ type: FormItemType;
13
+ name: string;
14
+ required?: Required;
15
+ description?: string;
16
+ default?: string;
17
+ group?: string;
18
+ groupI18N?: Record<string, {
19
+ [language: string]: string;
20
+ }>;
21
+ }
22
+ export interface UnionPropertyType extends PropertyType {
23
+ mode?: ItemModeType;
24
+ value?: any;
25
+ jsonSchema?: Record<string, any>;
26
+ schemaRef?: string;
27
+ }
28
+ export declare type BrickProperties = Record<string, any>;
29
+ export interface visualFormUtils extends Partial<FormInstance> {
30
+ resetPropertyFields: (typeList: PropertyType[], properties: BrickProperties) => void;
31
+ getCurTypeList: () => UnionPropertyType[];
32
+ }
@@ -0,0 +1 @@
1
+ export * from "./brick-visualization";
@@ -0,0 +1,22 @@
1
+ import React from "react";
2
+ import { EmptyProps } from "antd/lib/empty";
3
+ import { MenuIcon } from "@next-core/brick-types";
4
+ import { FormProps } from "antd/lib/form";
5
+ import { PropertyType, BrickProperties, visualFormUtils } from "../interfaces";
6
+ export interface VisualPropertyFormProps {
7
+ projectId?: string;
8
+ propertyTypeList: PropertyType[];
9
+ labelIcon: {
10
+ normal?: MenuIcon;
11
+ advanced?: MenuIcon;
12
+ };
13
+ brickProperties: BrickProperties;
14
+ onValuesChange?: FormProps["onValuesChange"];
15
+ brickInfo?: {
16
+ type: "brick" | "provider" | "template";
17
+ };
18
+ emptyConfig?: EmptyProps;
19
+ menuSettingClick?: () => void;
20
+ }
21
+ export declare function LegacyVisualPropertyForm(props: VisualPropertyFormProps, ref: React.Ref<visualFormUtils>): React.ReactElement;
22
+ export declare const VisualPropertyForm: React.ForwardRefExoticComponent<VisualPropertyFormProps & React.RefAttributes<visualFormUtils>>;
@@ -0,0 +1,7 @@
1
+ import React from "react";
2
+ import { FormItemWrapperProps } from "@next-libs/forms";
3
+ import { CodeEditorProps } from "@next-libs/code-editor-components";
4
+ interface CodeEditorItemProps extends CodeEditorProps, FormItemWrapperProps {
5
+ }
6
+ export declare function CodeEditorFormItem(props: CodeEditorItemProps): React.ReactElement;
7
+ export {};
@@ -0,0 +1,17 @@
1
+ import { Colors } from "@next-libs/basic-components";
2
+ import React from "react";
3
+ export interface ColorEditorItemProps {
4
+ name?: string;
5
+ label?: string | React.ReactElement;
6
+ required?: boolean;
7
+ value?: any;
8
+ onChange?: (value: string) => void;
9
+ }
10
+ export declare function getPresetColors(colorMap: Record<Colors, {
11
+ color: string;
12
+ background: string;
13
+ borderColor: string;
14
+ }>): string[];
15
+ export declare function LegacyColorPick(props: ColorEditorItemProps, ref: React.Ref<any>): JSX.Element;
16
+ export declare const ColorPick: React.ForwardRefExoticComponent<ColorEditorItemProps & React.RefAttributes<any>>;
17
+ export declare function ColorEditorItem(props: ColorEditorItemProps): JSX.Element;
@@ -0,0 +1,3 @@
1
+ import React from "react";
2
+ import { IconSelectProps } from "@next-libs/forms";
3
+ export declare function IconSelectFormItem(props: IconSelectProps): React.ReactElement;
@@ -0,0 +1,11 @@
1
+ import React from "react";
2
+ interface MenuEditorItemProps {
3
+ name?: string;
4
+ label?: string | React.ReactElement;
5
+ value?: string;
6
+ required?: boolean;
7
+ projectId?: string;
8
+ menuSettingClick?: () => void;
9
+ }
10
+ export declare function MenuEditorItem(props: MenuEditorItemProps): React.ReactElement;
11
+ export {};
@@ -0,0 +1,31 @@
1
+ import { PropertyType } from "../interfaces";
2
+ export declare const groupI18nMap: {
3
+ basic: {
4
+ en: string;
5
+ zh: string;
6
+ };
7
+ ui: {
8
+ en: string;
9
+ zh: string;
10
+ };
11
+ advanced: {
12
+ en: string;
13
+ zh: string;
14
+ };
15
+ basicFormItem: {
16
+ en: string;
17
+ zh: string;
18
+ };
19
+ advancedFormItem: {
20
+ en: string;
21
+ zh: string;
22
+ };
23
+ other: {
24
+ en: string;
25
+ zh: string;
26
+ };
27
+ };
28
+ export declare const supportBasicType: string[];
29
+ export declare const supportMenuType: string[];
30
+ export declare const OTHER_FORM_ITEM_FIELD = "others";
31
+ export declare const commonProps: PropertyType[];
@@ -0,0 +1,27 @@
1
+ import { PropertyType, UnionPropertyType, BrickProperties } from "../interfaces";
2
+ export declare function isAdvanceMode(value: unknown): boolean;
3
+ export declare function mergeProperties(propertyList?: PropertyType[], brickProperties?: BrickProperties): UnionPropertyType[];
4
+ export declare function yamlStringify(value: unknown, indent?: number): string;
5
+ export declare function yaml(value: string): any;
6
+ export declare function matchNoramlMenuValue(value: unknown): unknown;
7
+ export declare function calculateValue(propertyList?: PropertyType[], brickProperties?: BrickProperties, typeList?: UnionPropertyType[]): Record<string, any>;
8
+ /**
9
+ * @description 判断是否用使用 yaml 把用户输入解析成 JSON 的模式,当前只有以下情况下会进行解析,其他情况不对数据进行处理
10
+ * 1. 当前属性的类型不是内置支持的类型
11
+ * 2. 当前属性虽然是支持的类型,但是当前切换到高级模式编辑
12
+ * 3. 不是构件本身申明的属性,为 html 共有的通用属性,目前统一放在 others 的编辑器中
13
+ * @param field 字段值
14
+ * @param typeList 属性列表包含每个属性的类型和当前编辑模式
15
+ * @return boolean
16
+ */
17
+ export declare function isUseYamlParse(field: {
18
+ key: string;
19
+ value: any;
20
+ }, typeList: UnionPropertyType[]): boolean;
21
+ export declare function isUseMenuParse(field: {
22
+ key: string;
23
+ value: any;
24
+ }, typeList: UnionPropertyType[]): boolean;
25
+ export declare function processFormValue(values: {}, typeList: UnionPropertyType[]): Record<string, any>;
26
+ export declare function groupByType(typeList?: UnionPropertyType[]): Array<[string, UnionPropertyType[]]>;
27
+ export declare function extractCommonProps(typeList: PropertyType[]): PropertyType[];
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@next-libs/visual-builder",
3
+ "version": "1.1.0",
4
+ "description": "> TODO: description",
5
+ "homepage": "https://github.com/easyops-cn/next-libs/tree/master/libs/visual-builder",
6
+ "license": "GPL-3.0",
7
+ "main": "dist/cjs/index.js",
8
+ "module": "dist/esm/index.js",
9
+ "typings": "dist/types/index.d.ts",
10
+ "files": [
11
+ "dist"
12
+ ],
13
+ "scripts": {
14
+ "clean": "rimraf dist",
15
+ "prestart": "npm run clean",
16
+ "start": "concurrently -k -n types,main \"npm run start:types\" \"npm run start:main\"",
17
+ "start:main": "cross-env NODE_ENV=development build-next-libs --watch",
18
+ "start:types": "tsc --watch --emitDeclarationOnly --declaration --declarationDir dist/types",
19
+ "prebuild": "npm run clean",
20
+ "build": "npm run build:types && npm run build:main",
21
+ "build:main": "cross-env NODE_ENV=production build-next-libs",
22
+ "build:types": "tsc --emitDeclarationOnly --declaration --declarationDir dist/types",
23
+ "postbuild": "node scripts/post-build.js",
24
+ "test": "cross-env NODE_ENV='test' jest",
25
+ "test:ci": "cross-env NODE_ENV='test' CI=true jest"
26
+ },
27
+ "sideEffects": false,
28
+ "peerDependencies": {
29
+ "@next-dll/ace": "*"
30
+ },
31
+ "dependencies": {
32
+ "@next-libs/basic-components": "^3.5.2",
33
+ "@next-libs/code-editor-components": "^4.1.3",
34
+ "@next-libs/forms": "^3.2.28",
35
+ "@types/react-color": "^3.0.6",
36
+ "react-color": "^2.19.3"
37
+ },
38
+ "gitHead": "3f61763b06ed8242738dab8b92b039c3877c7056"
39
+ }