@flowgram.ai/form-materials 0.2.17 → 0.2.18

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/dist/esm/index.js CHANGED
@@ -416,7 +416,10 @@ var JsonSchemaUtils;
416
416
  properties: Object.entries(jsonSchema.properties || {}).sort((a, b) => (get(a?.[1], "extra.index") || 0) - (get(b?.[1], "extra.index") || 0)).map(([key, _property]) => ({
417
417
  key,
418
418
  type: schemaToAST(_property),
419
- meta: { description: _property.description }
419
+ meta: {
420
+ title: _property.title,
421
+ description: _property.description
422
+ }
420
423
  }))
421
424
  });
422
425
  case "array":
@@ -472,7 +475,16 @@ var JsonSchemaUtils;
472
475
  return {
473
476
  type: "object",
474
477
  properties: drilldown ? Object.fromEntries(
475
- typeAST.properties.map((property) => [property.key, astToSchema(property.type)])
478
+ typeAST.properties.map((property) => {
479
+ const schema = astToSchema(property.type);
480
+ if (property.meta?.title && schema) {
481
+ schema.title = property.meta.title;
482
+ }
483
+ if (property.meta?.description && schema) {
484
+ schema.description = property.meta.description;
485
+ }
486
+ return [property.key, schema];
487
+ })
476
488
  ) : {}
477
489
  };
478
490
  }
@@ -569,10 +581,20 @@ function useVariableTree(params) {
569
581
  // src/components/variable-selector/styles.tsx
570
582
  import styled from "styled-components";
571
583
  import { Tag, TreeSelect } from "@douyinfe/semi-ui";
572
- var UIRootTitle = styled.span`
584
+ var UIRootTitle = styled.div`
573
585
  margin-right: 4px;
586
+ min-width: 20px;
587
+ overflow: hidden;
588
+ text-overflow: ellipsis;
589
+ white-space: nowrap;
574
590
  color: var(--semi-color-text-2);
575
591
  `;
592
+ var UIVarName = styled.div`
593
+ overflow: hidden;
594
+ text-overflow: ellipsis;
595
+ white-space: nowrap;
596
+ min-width: 50%;
597
+ `;
576
598
  var UITag = styled(Tag)`
577
599
  width: 100%;
578
600
  display: flex;
@@ -673,7 +695,7 @@ var VariableSelector = ({
673
695
  onClose: () => onChange(void 0)
674
696
  },
675
697
  /* @__PURE__ */ React3.createElement(UIRootTitle, null, _option.rootMeta?.title ? `${_option.rootMeta?.title} -` : null),
676
- _option.label
698
+ /* @__PURE__ */ React3.createElement(UIVarName, null, _option.label)
677
699
  );
678
700
  },
679
701
  showClear: false,
@@ -1123,14 +1145,14 @@ function ConstantInput(props) {
1123
1145
  () => [...defaultStrategies, ...extraStrategies || []],
1124
1146
  [extraStrategies]
1125
1147
  );
1126
- const Renderer = useMemo4(() => {
1148
+ const Renderer2 = useMemo4(() => {
1127
1149
  const strategy = strategies.find((_strategy) => _strategy.hit(schema));
1128
1150
  return strategy?.Renderer;
1129
1151
  }, [strategies, schema]);
1130
- if (!Renderer) {
1152
+ if (!Renderer2) {
1131
1153
  return /* @__PURE__ */ React6.createElement(Input, { size: "small", disabled: true, placeholder: "Unsupported type" });
1132
1154
  }
1133
- return /* @__PURE__ */ React6.createElement(Renderer, { value, onChange, readonly, ...rest });
1155
+ return /* @__PURE__ */ React6.createElement(Renderer2, { value, onChange, readonly, ...rest });
1134
1156
  }
1135
1157
 
1136
1158
  // src/components/json-schema-editor/default-value.tsx
@@ -1438,6 +1460,8 @@ var UIContainer2 = styled3.div`
1438
1460
  `;
1439
1461
  var UIMain = styled3.div`
1440
1462
  flex-grow: 1;
1463
+ overflow: hidden;
1464
+ min-width: 0;
1441
1465
 
1442
1466
  & .semi-tree-select,
1443
1467
  & .semi-input-number,
@@ -1467,6 +1491,7 @@ function DynamicValueInput({
1467
1491
  return /* @__PURE__ */ React11.createElement(
1468
1492
  VariableSelector,
1469
1493
  {
1494
+ style: { width: "100%" },
1470
1495
  value: value?.content,
1471
1496
  onChange: (_v) => onChange(_v ? { type: "ref", content: _v } : void 0),
1472
1497
  includeSchema,
@@ -1917,6 +1942,228 @@ function BatchOutputs(props) {
1917
1942
  )))), /* @__PURE__ */ React14.createElement(Button4, { disabled: readonly, icon: /* @__PURE__ */ React14.createElement(IconPlus2, null), size: "small", onClick: add }, "Add"));
1918
1943
  }
1919
1944
 
1945
+ // src/components/prompt-editor/index.tsx
1946
+ import React15 from "react";
1947
+ import { Renderer, EditorProvider } from "@coze-editor/editor/react";
1948
+ import preset from "@coze-editor/editor/preset-prompt";
1949
+
1950
+ // src/components/prompt-editor/styles.tsx
1951
+ import styled6, { css as css2 } from "styled-components";
1952
+ var UIContainer4 = styled6.div`
1953
+ background-color: var(--semi-color-fill-0);
1954
+ padding-left: 10px;
1955
+ padding-right: 6px;
1956
+
1957
+ ${({ $hasError }) => $hasError && css2`
1958
+ border: 1px solid var(--semi-color-danger-6);
1959
+ `}
1960
+ `;
1961
+
1962
+ // src/components/prompt-editor/extensions/markdown.tsx
1963
+ import { useLayoutEffect } from "react";
1964
+ import { useInjector } from "@coze-editor/editor/react";
1965
+ import { astDecorator } from "@coze-editor/editor";
1966
+ import { EditorView } from "@codemirror/view";
1967
+ function MarkdownHighlight() {
1968
+ const injector = useInjector();
1969
+ useLayoutEffect(
1970
+ () => injector.inject([
1971
+ astDecorator.whole.of((cursor) => {
1972
+ if (cursor.name.startsWith("ATXHeading")) {
1973
+ return {
1974
+ type: "className",
1975
+ className: "heading"
1976
+ };
1977
+ }
1978
+ if (cursor.name === "Emphasis") {
1979
+ return {
1980
+ type: "className",
1981
+ className: "emphasis"
1982
+ };
1983
+ }
1984
+ if (cursor.name === "StrongEmphasis") {
1985
+ return {
1986
+ type: "className",
1987
+ className: "strong-emphasis"
1988
+ };
1989
+ }
1990
+ if (cursor.name === "ListMark" || cursor.name === "QuoteMark") {
1991
+ return {
1992
+ type: "className",
1993
+ className: "mark"
1994
+ };
1995
+ }
1996
+ }),
1997
+ EditorView.theme({
1998
+ ".heading": {
1999
+ color: "#00818C",
2000
+ fontWeight: "bold"
2001
+ },
2002
+ ".emphasis": {
2003
+ fontStyle: "italic"
2004
+ },
2005
+ ".strong-emphasis": {
2006
+ fontWeight: "bold"
2007
+ },
2008
+ ".mark": {
2009
+ color: "#4E40E5"
2010
+ }
2011
+ })
2012
+ ]),
2013
+ [injector]
2014
+ );
2015
+ return null;
2016
+ }
2017
+ var markdown_default = MarkdownHighlight;
2018
+
2019
+ // src/components/prompt-editor/extensions/language-support.tsx
2020
+ import { useLayoutEffect as useLayoutEffect2 } from "react";
2021
+ import { useInjector as useInjector2 } from "@coze-editor/editor/react";
2022
+ import { languageSupport } from "@coze-editor/editor/preset-prompt";
2023
+ function LanguageSupport() {
2024
+ const injector = useInjector2();
2025
+ useLayoutEffect2(() => injector.inject([languageSupport]), [injector]);
2026
+ return null;
2027
+ }
2028
+ var language_support_default = LanguageSupport;
2029
+
2030
+ // src/components/prompt-editor/extensions/jinja.tsx
2031
+ import { useLayoutEffect as useLayoutEffect3 } from "react";
2032
+ import { useInjector as useInjector3 } from "@coze-editor/editor/react";
2033
+ import { astDecorator as astDecorator2 } from "@coze-editor/editor";
2034
+ import { EditorView as EditorView2 } from "@codemirror/view";
2035
+ function JinjaHighlight() {
2036
+ const injector = useInjector3();
2037
+ useLayoutEffect3(
2038
+ () => injector.inject([
2039
+ astDecorator2.whole.of((cursor) => {
2040
+ if (cursor.name === "JinjaStatementStart" || cursor.name === "JinjaStatementEnd") {
2041
+ return {
2042
+ type: "className",
2043
+ className: "jinja-statement-bracket"
2044
+ };
2045
+ }
2046
+ if (cursor.name === "JinjaComment") {
2047
+ return {
2048
+ type: "className",
2049
+ className: "jinja-comment"
2050
+ };
2051
+ }
2052
+ if (cursor.name === "JinjaExpression") {
2053
+ return {
2054
+ type: "className",
2055
+ className: "jinja-expression"
2056
+ };
2057
+ }
2058
+ }),
2059
+ EditorView2.theme({
2060
+ ".jinja-statement-bracket": {
2061
+ color: "#D1009D"
2062
+ },
2063
+ ".jinja-comment": {
2064
+ color: "#0607094D"
2065
+ },
2066
+ ".jinja-expression": {
2067
+ color: "#4E40E5"
2068
+ }
2069
+ })
2070
+ ]),
2071
+ [injector]
2072
+ );
2073
+ return null;
2074
+ }
2075
+ var jinja_default = JinjaHighlight;
2076
+
2077
+ // src/components/prompt-editor/index.tsx
2078
+ function PromptEditor(props) {
2079
+ const { value, onChange, readonly, style, hasError, children } = props || {};
2080
+ return /* @__PURE__ */ React15.createElement(UIContainer4, { $hasError: hasError, style }, /* @__PURE__ */ React15.createElement(EditorProvider, null, /* @__PURE__ */ React15.createElement(
2081
+ Renderer,
2082
+ {
2083
+ plugins: preset,
2084
+ defaultValue: String(value?.content),
2085
+ options: {
2086
+ readOnly: readonly,
2087
+ editable: !readonly
2088
+ },
2089
+ onChange: (e) => {
2090
+ onChange({ type: "template", content: e.value });
2091
+ }
2092
+ }
2093
+ ), /* @__PURE__ */ React15.createElement(markdown_default, null), /* @__PURE__ */ React15.createElement(language_support_default, null), /* @__PURE__ */ React15.createElement(jinja_default, null), children));
2094
+ }
2095
+
2096
+ // src/components/prompt-editor-with-variables/index.tsx
2097
+ import React17 from "react";
2098
+
2099
+ // src/components/prompt-editor-with-variables/extensions/variable.tsx
2100
+ import React16, { useEffect as useEffect4, useState as useState6 } from "react";
2101
+ import { Popover, Tree } from "@douyinfe/semi-ui";
2102
+ import {
2103
+ Mention,
2104
+ getCurrentMentionReplaceRange,
2105
+ useEditor,
2106
+ PositionMirror
2107
+ } from "@coze-editor/editor/react";
2108
+ function Variable() {
2109
+ const [posKey, setPosKey] = useState6("");
2110
+ const [visible, setVisible] = useState6(false);
2111
+ const [position, setPosition] = useState6(-1);
2112
+ const editor = useEditor();
2113
+ function insert(variablePath) {
2114
+ const range = getCurrentMentionReplaceRange(editor.$view.state);
2115
+ if (!range) {
2116
+ return;
2117
+ }
2118
+ editor.replaceText({
2119
+ ...range,
2120
+ text: "{{" + variablePath + "}}"
2121
+ });
2122
+ setVisible(false);
2123
+ }
2124
+ function handleOpenChange(e) {
2125
+ setPosition(e.state.selection.main.head);
2126
+ setVisible(e.value);
2127
+ }
2128
+ useEffect4(() => {
2129
+ if (!editor) {
2130
+ return;
2131
+ }
2132
+ }, [editor, visible]);
2133
+ const treeData = useVariableTree({});
2134
+ return /* @__PURE__ */ React16.createElement(React16.Fragment, null, /* @__PURE__ */ React16.createElement(Mention, { triggerCharacters: ["{", "{}"], onOpenChange: handleOpenChange }), /* @__PURE__ */ React16.createElement(
2135
+ Popover,
2136
+ {
2137
+ visible,
2138
+ trigger: "custom",
2139
+ position: "topLeft",
2140
+ rePosKey: posKey,
2141
+ content: /* @__PURE__ */ React16.createElement("div", { style: { width: 300 } }, /* @__PURE__ */ React16.createElement(
2142
+ Tree,
2143
+ {
2144
+ treeData,
2145
+ onSelect: (v) => {
2146
+ insert(v);
2147
+ }
2148
+ }
2149
+ ))
2150
+ },
2151
+ /* @__PURE__ */ React16.createElement(
2152
+ PositionMirror,
2153
+ {
2154
+ position,
2155
+ onChange: () => setPosKey(String(Math.random()))
2156
+ }
2157
+ )
2158
+ ));
2159
+ }
2160
+ var variable_default = Variable;
2161
+
2162
+ // src/components/prompt-editor-with-variables/index.tsx
2163
+ function PromptEditorWithVariables(props) {
2164
+ return /* @__PURE__ */ React17.createElement(PromptEditor, { ...props }, /* @__PURE__ */ React17.createElement(variable_default, null));
2165
+ }
2166
+
1920
2167
  // src/effects/provide-batch-input/index.ts
1921
2168
  import {
1922
2169
  ASTFactory as ASTFactory2,
@@ -2165,6 +2412,8 @@ export {
2165
2412
  DynamicValueInput,
2166
2413
  JsonSchemaEditor,
2167
2414
  JsonSchemaUtils,
2415
+ PromptEditor,
2416
+ PromptEditorWithVariables,
2168
2417
  TypeSelector,
2169
2418
  VariableSelector,
2170
2419
  VariableTypeIcons,