@player-ui/storybook 0.9.0-next.0 → 0.9.0-next.2

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/index.js CHANGED
@@ -18,8 +18,9 @@ var managerApi = require('@storybook/manager-api');
18
18
  var types = require('@storybook/types');
19
19
  var dequal = require('dequal');
20
20
  var Editor = require('@monaco-editor/react');
21
+ var storybookDarkMode = require('storybook-dark-mode');
21
22
  var table = require('@devtools-ds/table');
22
- var clsx = require('clsx');
23
+ var ts = require('typescript');
23
24
 
24
25
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
25
26
 
@@ -44,6 +45,7 @@ function _interopNamespace(e) {
44
45
  var React5__namespace = /*#__PURE__*/_interopNamespace(React5);
45
46
  var PlayerDSL__namespace = /*#__PURE__*/_interopNamespace(PlayerDSL);
46
47
  var Editor__default = /*#__PURE__*/_interopDefault(Editor);
48
+ var ts__default = /*#__PURE__*/_interopDefault(ts);
47
49
 
48
50
  // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/tools/storybook/src/decorator/index.tsx
49
51
  var initializedPromise;
@@ -226,10 +228,10 @@ var StorybookPlayerPlugin = class {
226
228
  }
227
229
  };
228
230
  var PlayerFlowSummary = (props) => {
229
- var _a, _b, _c;
231
+ var _a2, _b, _c;
230
232
  React5.useEffect(() => {
231
- var _a2;
232
- const model = new react.LocalModel((_a2 = props.completedState) == null ? void 0 : _a2.data);
233
+ var _a3;
234
+ const model = new react.LocalModel((_a3 = props.completedState) == null ? void 0 : _a3.data);
233
235
  const parser = new react.BindingParser({
234
236
  get: (binding) => model.get(binding)
235
237
  });
@@ -242,7 +244,7 @@ var PlayerFlowSummary = (props) => {
242
244
  delete window.__PLAYER_COMPLETED_DATA__;
243
245
  };
244
246
  }, [props.completedState, props.beacons]);
245
- return /* @__PURE__ */ React5__namespace.default.createElement("div", null, /* @__PURE__ */ React5__namespace.default.createElement("h1", null, "Flow Completed ", props.error ? "with Error" : ""), ((_a = props.completedState) == null ? void 0 : _a.endState.outcome) && /* @__PURE__ */ React5__namespace.default.createElement("pre", null, "Outcome: ", /* @__PURE__ */ React5__namespace.default.createElement("span", null, (_b = props.completedState) == null ? void 0 : _b.endState.outcome)), props.error && /* @__PURE__ */ React5__namespace.default.createElement("pre", { colorScheme: "red" }, "Error Message: ", /* @__PURE__ */ React5__namespace.default.createElement("span", null, (_c = props.error) == null ? void 0 : _c.message)), /* @__PURE__ */ React5__namespace.default.createElement("button", { onClick: props.reset }, "Reset"));
247
+ return /* @__PURE__ */ React5__namespace.default.createElement("div", null, /* @__PURE__ */ React5__namespace.default.createElement("h1", null, "Flow Completed ", props.error ? "with Error" : ""), ((_a2 = props.completedState) == null ? void 0 : _a2.endState.outcome) && /* @__PURE__ */ React5__namespace.default.createElement("pre", null, "Outcome: ", /* @__PURE__ */ React5__namespace.default.createElement("span", null, (_b = props.completedState) == null ? void 0 : _b.endState.outcome)), props.error && /* @__PURE__ */ React5__namespace.default.createElement("pre", { colorScheme: "red" }, "Error Message: ", /* @__PURE__ */ React5__namespace.default.createElement("span", null, (_c = props.error) == null ? void 0 : _c.message)), /* @__PURE__ */ React5__namespace.default.createElement("button", { onClick: props.reset }, "Reset"));
246
248
  };
247
249
  var useFlowSetListener = (chan) => {
248
250
  const dispatch = reactRedux.useDispatch();
@@ -455,8 +457,8 @@ var setCompiledEditorResult = toolkit.createAction("setCompiledEditorResult");
455
457
  var setEditorContentType = toolkit.createAction("setEditorContentType");
456
458
  var setJSONEditorValue = toolkit.createAction("setJSONEditorValue");
457
459
  var updateAndCompileDSLFlow = toolkit.createAsyncThunk("editor/dsl/compile", async (context, thunkAPI) => {
458
- var _a;
459
- const content = (_a = thunkAPI.getState().editor.dsl) == null ? void 0 : _a.value;
460
+ var _a2;
461
+ const content = (_a2 = thunkAPI.getState().editor.dsl) == null ? void 0 : _a2.value;
460
462
  if (!content) {
461
463
  throw new Error("No content to compile");
462
464
  }
@@ -524,8 +526,8 @@ var flowEditorReducer = toolkit.createReducer(
524
526
  };
525
527
  });
526
528
  builder.addCase(setCompilationErrors, (state, action) => {
527
- var _a;
528
- if (((_a = state.dsl) == null ? void 0 : _a.state) === "loaded") {
529
+ var _a2;
530
+ if (((_a2 = state.dsl) == null ? void 0 : _a2.state) === "loaded") {
529
531
  state.dsl.compilationErrors = action.payload;
530
532
  }
531
533
  });
@@ -540,8 +542,8 @@ var flowEditorReducer = toolkit.createReducer(
540
542
  state.dsl = { state: "error" };
541
543
  });
542
544
  builder.addCase(setCompiledEditorResult, (state, action) => {
543
- var _a;
544
- if (((_a = state.dsl) == null ? void 0 : _a.state) === "loaded") {
545
+ var _a2;
546
+ if (((_a2 = state.dsl) == null ? void 0 : _a2.state) === "loaded") {
545
547
  state.dsl.needsCompile = false;
546
548
  state.dsl.compilationErrors = action.payload.errors;
547
549
  }
@@ -565,11 +567,13 @@ var eventsReducer = toolkit.createReducer([], (builder) => {
565
567
  });
566
568
  });
567
569
  var STATE_SYNC_CHANNEL_NAME = (() => {
568
- if (window == null ? void 0 : window.sessionStorage.getItem("player:channel")) {
570
+ if (typeof window !== "undefined" && window.sessionStorage.getItem("player:channel")) {
569
571
  return window == null ? void 0 : window.sessionStorage.getItem("player:channel");
570
572
  }
571
573
  const channel = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
572
- window == null ? void 0 : window.sessionStorage.setItem("player:channel", channel);
574
+ if (typeof window !== "undefined") {
575
+ window == null ? void 0 : window.sessionStorage.setItem("player:channel", channel);
576
+ }
573
577
  return channel;
574
578
  })();
575
579
  var store = toolkit.configureStore({
@@ -668,7 +672,7 @@ var useInitialJsonEditorValue = (initialValue) => {
668
672
 
669
673
  // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/tools/storybook/src/decorator/index.tsx
670
674
  var PlayerRenderContextWrapper = (props) => {
671
- var _a;
675
+ var _a2;
672
676
  const { playerParams } = props;
673
677
  const platform = reactRedux.useSelector(
674
678
  (s) => s.platform.platform ?? "web"
@@ -678,7 +682,7 @@ var PlayerRenderContextWrapper = (props) => {
678
682
  {
679
683
  value: {
680
684
  platform,
681
- token: platform === "web" ? void 0 : (_a = playerParams == null ? void 0 : playerParams.appetizeTokens) == null ? void 0 : _a[platform],
685
+ token: platform === "web" ? void 0 : (_a2 = playerParams == null ? void 0 : playerParams.appetizeTokens) == null ? void 0 : _a2[platform],
682
686
  baseUrl: playerParams.appetizeBaseUrl,
683
687
  appetizeVersions: playerParams.appetizeVersions
684
688
  }
@@ -703,29 +707,40 @@ var preview = {
703
707
  };
704
708
 
705
709
  // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/tools/storybook/src/addons/constants.ts
706
- var ADDON_ID = "web-player/addon";
710
+ var ADDON_ID = "@player-ui/storybook";
707
711
  var FLOW_PANEL_ID = `${ADDON_ID}/flow-editor-panel`;
708
712
  var EVENT_PANEL_ID = `${ADDON_ID}/events-panel`;
709
-
710
- // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/tools/storybook/src/addons/useDarkMode.ts
711
- function useDarkMode() {
712
- if (typeof window === "undefined") {
713
- return false;
714
- }
715
- return matchMedia("(prefers-color-scheme: dark)").matches;
713
+ var DOCS_PANEL_ID = `${ADDON_ID}/asset-docs-panel`;
714
+ var FLOW_REFRESH_TOOL_ID = `${ADDON_ID}/flow-refresh-tool`;
715
+ var _a;
716
+ var prefersDark = (_a = window.matchMedia) == null ? void 0 : _a.call(window, "(prefers-color-scheme: dark)");
717
+ function useDarkMode(api) {
718
+ const [isDark, setIsDark] = React5.useState(prefersDark);
719
+ React5.useEffect(function() {
720
+ var chan = api.getChannel();
721
+ chan.on(storybookDarkMode.DARK_MODE_EVENT_NAME, setIsDark);
722
+ return function() {
723
+ return chan.off(storybookDarkMode.DARK_MODE_EVENT_NAME, setIsDark);
724
+ };
725
+ }, []);
726
+ return isDark;
716
727
  }
717
728
 
718
729
  // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/tools/storybook/src/addons/editor/index.tsx
719
730
  if (typeof window !== "undefined") {
720
731
  Editor.loader.init().then((m) => {
721
732
  m.languages.typescript.javascriptDefaults.setEagerModelSync(true);
733
+ m.languages.typescript.typescriptDefaults.setDiagnosticsOptions({
734
+ noSemanticValidation: true,
735
+ noSyntaxValidation: true
736
+ });
722
737
  m.languages.typescript.typescriptDefaults.setCompilerOptions({
723
738
  jsx: m.languages.typescript.JsxEmit.React
724
739
  });
725
740
  });
726
741
  }
727
- var JSONEditorPanel = () => {
728
- const darkMode = useDarkMode();
742
+ var JSONEditorPanel = (props) => {
743
+ const darkMode = useDarkMode(props.api);
729
744
  const jsonEditorValue = useJSONEditorValue();
730
745
  const jsonValueAsString = (jsonEditorValue == null ? void 0 : jsonEditorValue.state) === "loaded" ? JSON.stringify(jsonEditorValue.value, null, 2) : "";
731
746
  const dispatch = reactRedux.useDispatch();
@@ -763,7 +778,7 @@ var JSONEditorPanel = () => {
763
778
  var CompileErrors = ({
764
779
  errors
765
780
  }) => {
766
- var _a, _b;
781
+ var _a2, _b;
767
782
  if ((errors.compileErrors === void 0 || errors.compileErrors.length === 0) && (errors.transpileErrors === void 0 || errors.transpileErrors.length === 0)) {
768
783
  return null;
769
784
  }
@@ -782,12 +797,12 @@ var CompileErrors = ({
782
797
  }
783
798
  },
784
799
  /* @__PURE__ */ React5__namespace.default.createElement("h3", null, "Errors"),
785
- (_a = errors.compileErrors) == null ? void 0 : _a.map((e) => /* @__PURE__ */ React5__namespace.default.createElement("pre", { key: e.message }, e.message)),
800
+ (_a2 = errors.compileErrors) == null ? void 0 : _a2.map((e) => /* @__PURE__ */ React5__namespace.default.createElement("pre", { key: e.message }, e.message)),
786
801
  (_b = errors.transpileErrors) == null ? void 0 : _b.map((e) => /* @__PURE__ */ React5__namespace.default.createElement("pre", { key: e.message }, e.message))
787
802
  );
788
803
  };
789
- var DSLEditorPanel = () => {
790
- const darkMode = useDarkMode();
804
+ var DSLEditorPanel = (props) => {
805
+ const darkMode = useDarkMode(props.api);
791
806
  const jsonEditorValue = useJSONEditorValue();
792
807
  const dslEditorValue = useDSLEditorValue();
793
808
  const dispatch = reactRedux.useDispatch();
@@ -864,18 +879,13 @@ var EditorPanel = (props) => {
864
879
  return null;
865
880
  }
866
881
  if (contentType === "dsl") {
867
- return /* @__PURE__ */ React5__namespace.default.createElement(DSLEditorPanel, null);
882
+ return /* @__PURE__ */ React5__namespace.default.createElement(DSLEditorPanel, { ...props });
868
883
  }
869
884
  if (contentType === "json") {
870
- return /* @__PURE__ */ React5__namespace.default.createElement(JSONEditorPanel, null);
885
+ return /* @__PURE__ */ React5__namespace.default.createElement(JSONEditorPanel, { ...props });
871
886
  }
872
887
  return /* @__PURE__ */ React5__namespace.default.createElement(components.Placeholder, null, "This story is not configured to allow flow edits.");
873
888
  };
874
-
875
- // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/tools/storybook/src/addons/events/events.css
876
- var events_default = {};
877
-
878
- // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/tools/storybook/src/addons/events/index.tsx
879
889
  var ExtraCells = (event) => {
880
890
  if (event.type === "log") {
881
891
  return /* @__PURE__ */ React5__namespace.default.createElement(React5__namespace.default.Fragment, null, /* @__PURE__ */ React5__namespace.default.createElement("td", null, event.severity), /* @__PURE__ */ React5__namespace.default.createElement("td", null, event.message.map((a) => JSON.stringify(a)).join(" ")));
@@ -898,38 +908,616 @@ var ExtraCells = (event) => {
898
908
  var EventsPanel = (props) => {
899
909
  const events = reactRedux.useSelector((state) => state.events);
900
910
  const contentType = useContentKind();
901
- const darkMode = useDarkMode();
911
+ const darkMode = useDarkMode(props.api);
902
912
  if (!props.active) {
903
913
  return null;
904
914
  }
905
915
  if (contentType === void 0) {
906
916
  return /* @__PURE__ */ React5__namespace.default.createElement(components.Placeholder, null, "This story is not configured to receive Player events.");
907
917
  }
908
- return /* @__PURE__ */ React5__namespace.default.createElement(
909
- "div",
910
- {
911
- className: clsx.clsx(events_default.wrapper, {
912
- [events_default.dark]: darkMode
918
+ return /* @__PURE__ */ React5__namespace.default.createElement("div", null, /* @__PURE__ */ React5__namespace.default.createElement(table.Table, { colorScheme: darkMode ? "dark" : "light" }, /* @__PURE__ */ React5__namespace.default.createElement(table.Head, null, /* @__PURE__ */ React5__namespace.default.createElement(table.Row, null, /* @__PURE__ */ React5__namespace.default.createElement(table.HeadCell, null, "Time"), /* @__PURE__ */ React5__namespace.default.createElement(table.HeadCell, null, "Type"), /* @__PURE__ */ React5__namespace.default.createElement(table.HeadCell, null), /* @__PURE__ */ React5__namespace.default.createElement(table.HeadCell, null))), /* @__PURE__ */ React5__namespace.default.createElement(table.Body, null, events.map((evt) => /* @__PURE__ */ React5__namespace.default.createElement(table.Row, { key: evt.id }, /* @__PURE__ */ React5__namespace.default.createElement(table.Cell, null, evt.time), /* @__PURE__ */ React5__namespace.default.createElement(table.Cell, null, evt.type), /* @__PURE__ */ React5__namespace.default.createElement(ExtraCells, { ...evt }))))));
919
+ };
920
+ var templateTokenize = /(?=true\|false|\.\*|\[0-9]\*)/gm;
921
+ var tokenSplit = new RegExp("(?<=true\\|false|\\.\\*|\\[0-9]\\*)", "gm");
922
+ function isPrimitiveTypeNode(node) {
923
+ return node.type === "string" || node.type === "number" || node.type === "boolean" || node.type === "null" || node.type === "any" || node.type === "never" || node.type === "undefined" || node.type === "unknown" || node.type === "void";
924
+ }
925
+ function isGenericNamedType(nt) {
926
+ var _a2;
927
+ return ((_a2 = nt.genericTokens) == null ? void 0 : _a2.length) > 0;
928
+ }
929
+ var ConversionError = class _ConversionError extends Error {
930
+ constructor(msg) {
931
+ super(msg);
932
+ Object.setPrototypeOf(this, _ConversionError.prototype);
933
+ }
934
+ toString() {
935
+ return `Conversion Error: ${this.message}`;
936
+ }
937
+ };
938
+ var TSWriter = class {
939
+ constructor(factory) {
940
+ this.context = {
941
+ factory: factory ?? ts__default.default.factory,
942
+ throwError: (message) => {
943
+ throw new ConversionError(message);
944
+ }
945
+ };
946
+ this.importSet = /* @__PURE__ */ new Set();
947
+ this.additionalTypes = /* @__PURE__ */ new Map();
948
+ }
949
+ convertNamedType(type) {
950
+ this.importSet.clear();
951
+ this.additionalTypes.clear();
952
+ const finalNode = this.convertNamedTypeNode(type);
953
+ const referencedTypes = this.importSet.size > 0 ? this.importSet : void 0;
954
+ const additionalTypes = this.additionalTypes.size > 0 ? this.additionalTypes : void 0;
955
+ return {
956
+ type: this.makeAnnotations(finalNode, type),
957
+ referencedTypes,
958
+ additionalTypes
959
+ };
960
+ }
961
+ convertNamedTypeNode(type) {
962
+ const typeName = type.name;
963
+ const tsNode = this.convertTypeNode(type);
964
+ let customPrimitiveHeritageClass;
965
+ if (type.type === "object" && type.extends) {
966
+ const refName = type.extends.ref.split("<")[0];
967
+ customPrimitiveHeritageClass = [
968
+ this.context.factory.createHeritageClause(
969
+ ts__default.default.SyntaxKind.ExtendsKeyword,
970
+ [
971
+ this.context.factory.createExpressionWithTypeArguments(
972
+ this.context.factory.createIdentifier(refName),
973
+ type.extends.genericArguments ? type.extends.genericArguments.map(
974
+ (node) => this.convertTypeNode(node)
975
+ ) : void 0
976
+ )
977
+ ]
978
+ )
979
+ ];
980
+ }
981
+ let generics;
982
+ if (isGenericNamedType(type)) {
983
+ generics = this.createTypeParameters(type);
984
+ type.genericTokens.forEach((token) => {
985
+ if (this.importSet.has(token.symbol)) {
986
+ this.importSet.delete(token.symbol);
987
+ }
988
+ });
989
+ }
990
+ let finalNode;
991
+ if (ts__default.default.isTypeLiteralNode(tsNode)) {
992
+ finalNode = this.makeInterfaceDeclaration(
993
+ typeName,
994
+ tsNode.members,
995
+ generics,
996
+ customPrimitiveHeritageClass
997
+ );
998
+ } else {
999
+ finalNode = this.makeTypeDeclaration(typeName, tsNode, generics);
1000
+ }
1001
+ return finalNode;
1002
+ }
1003
+ convertTypeNode(type) {
1004
+ if (type.type === "object") {
1005
+ return this.createObjectNode(type);
1006
+ }
1007
+ if (type.type === "and") {
1008
+ return this.context.factory.createIntersectionTypeNode(
1009
+ type.and.map((element) => {
1010
+ return this.convertTypeNode(element);
1011
+ })
1012
+ );
1013
+ }
1014
+ if (type.type === "or") {
1015
+ return this.context.factory.createUnionTypeNode(
1016
+ type.or.map((element) => {
1017
+ return this.convertTypeNode(element);
1018
+ })
1019
+ );
1020
+ }
1021
+ if (type.type === "array") {
1022
+ if (type.const) {
1023
+ return this.context.factory.createTupleTypeNode(
1024
+ type.const.map(
1025
+ (element) => this.convertTypeNode(element)
1026
+ )
1027
+ );
1028
+ }
1029
+ return this.context.factory.createTypeReferenceNode(
1030
+ this.context.factory.createIdentifier("Array"),
1031
+ [this.convertTypeNode(type.elementType)]
1032
+ );
1033
+ }
1034
+ if (isPrimitiveTypeNode(type)) {
1035
+ return this.createPrimitiveNode(type);
1036
+ }
1037
+ if (type.type === "conditional") {
1038
+ return this.createConditionalTypeNode(type);
1039
+ }
1040
+ if (type.type === "function") {
1041
+ return this.createFunctionDeclarationNode(type);
1042
+ }
1043
+ if (type.type === "record") {
1044
+ return this.createRecordNode(type);
1045
+ }
1046
+ if (type.type === "ref") {
1047
+ return this.createRefNode(type);
1048
+ }
1049
+ if (type.type === "template") {
1050
+ return this.createTemplateLiteral(type);
1051
+ }
1052
+ if (type.type === "tuple") {
1053
+ return this.createTupleNode(type);
1054
+ }
1055
+ this.context.throwError(
1056
+ `Unable to convert node type: ${type.type}`
1057
+ );
1058
+ }
1059
+ createRefNode(xlrNode) {
1060
+ const typeArgs = [];
1061
+ if (xlrNode.genericArguments) {
1062
+ xlrNode.genericArguments.forEach((genericArg) => {
1063
+ if (genericArg.name) {
1064
+ const additionalType = this.convertNamedTypeNode(
1065
+ genericArg
1066
+ );
1067
+ this.additionalTypes.set(genericArg.name, additionalType);
1068
+ } else if (genericArg.type === "and") {
1069
+ genericArg.and.forEach((type) => {
1070
+ if (type.name) {
1071
+ const additionalType = this.convertNamedTypeNode(
1072
+ type
1073
+ );
1074
+ this.additionalTypes.set(type.name, additionalType);
1075
+ }
1076
+ });
1077
+ } else if (genericArg.type === "or") {
1078
+ genericArg.or.forEach((type) => {
1079
+ if (type.name) {
1080
+ const additionalType = this.convertNamedTypeNode(
1081
+ type
1082
+ );
1083
+ this.additionalTypes.set(type.name, additionalType);
1084
+ }
1085
+ });
1086
+ } else {
1087
+ typeArgs.push(this.convertTypeNode(genericArg));
1088
+ }
1089
+ });
1090
+ }
1091
+ const importName = xlrNode.ref.split("<")[0];
1092
+ this.importSet.add(importName);
1093
+ return this.context.factory.createTypeReferenceNode(importName, typeArgs);
1094
+ }
1095
+ createPrimitiveNode(xlrNode) {
1096
+ if ((xlrNode.type === "string" || xlrNode.type === "boolean" || xlrNode.type === "number") && xlrNode.const || xlrNode.type === "null") {
1097
+ return this.context.factory.createLiteralTypeNode(
1098
+ this.createLiteralTypeNode(xlrNode)
1099
+ );
1100
+ }
1101
+ switch (xlrNode.type) {
1102
+ case "string":
1103
+ return this.context.factory.createKeywordTypeNode(
1104
+ ts__default.default.SyntaxKind.StringKeyword
1105
+ );
1106
+ case "number":
1107
+ return this.context.factory.createKeywordTypeNode(
1108
+ ts__default.default.SyntaxKind.NumberKeyword
1109
+ );
1110
+ case "boolean":
1111
+ return this.context.factory.createKeywordTypeNode(
1112
+ ts__default.default.SyntaxKind.BooleanKeyword
1113
+ );
1114
+ case "any":
1115
+ return this.context.factory.createKeywordTypeNode(
1116
+ ts__default.default.SyntaxKind.AnyKeyword
1117
+ );
1118
+ case "unknown":
1119
+ return this.context.factory.createKeywordTypeNode(
1120
+ ts__default.default.SyntaxKind.UnknownKeyword
1121
+ );
1122
+ case "never":
1123
+ return this.context.factory.createKeywordTypeNode(
1124
+ ts__default.default.SyntaxKind.NeverKeyword
1125
+ );
1126
+ case "undefined":
1127
+ return this.context.factory.createKeywordTypeNode(
1128
+ ts__default.default.SyntaxKind.UndefinedKeyword
1129
+ );
1130
+ case "void":
1131
+ return this.context.factory.createKeywordTypeNode(
1132
+ ts__default.default.SyntaxKind.VoidKeyword
1133
+ );
1134
+ default:
1135
+ this.context.throwError(
1136
+ `Unknown primitive type ${xlrNode.type}`
1137
+ );
1138
+ }
1139
+ }
1140
+ createLiteralTypeNode(xlrNode) {
1141
+ if (xlrNode.type === "boolean") {
1142
+ return xlrNode.const ? this.context.factory.createTrue() : this.context.factory.createFalse();
1143
+ }
1144
+ if (xlrNode.type === "number") {
1145
+ return xlrNode.const ? this.context.factory.createNumericLiteral(xlrNode.const) : this.context.throwError(
1146
+ "Can't make literal type out of non constant number"
1147
+ );
1148
+ }
1149
+ if (xlrNode.type === "string") {
1150
+ return xlrNode.const ? this.context.factory.createStringLiteral(xlrNode.const, true) : this.context.throwError(
1151
+ "Can't make literal type out of non constant string"
1152
+ );
1153
+ }
1154
+ if (xlrNode.type === "null") {
1155
+ return this.context.factory.createNull();
1156
+ }
1157
+ this.context.throwError(`Can't make literal out of type ${xlrNode.type}`);
1158
+ }
1159
+ createTupleNode(xlrNode) {
1160
+ return this.context.factory.createTupleTypeNode(
1161
+ xlrNode.elementTypes.map((e) => {
1162
+ if (e.name) {
1163
+ return this.context.factory.createNamedTupleMember(
1164
+ void 0,
1165
+ this.context.factory.createIdentifier(e.name),
1166
+ e.optional ? this.context.factory.createToken(ts__default.default.SyntaxKind.QuestionToken) : void 0,
1167
+ this.convertTypeNode(e.type)
1168
+ );
1169
+ }
1170
+ return this.convertTypeNode(e.type);
913
1171
  })
914
- },
915
- /* @__PURE__ */ React5__namespace.default.createElement(table.Table, { colorScheme: darkMode ? "dark" : "light" }, /* @__PURE__ */ React5__namespace.default.createElement(table.Head, { className: events_default.header }, /* @__PURE__ */ React5__namespace.default.createElement(table.Row, null, /* @__PURE__ */ React5__namespace.default.createElement(table.HeadCell, null, "Time"), /* @__PURE__ */ React5__namespace.default.createElement(table.HeadCell, null, "Type"), /* @__PURE__ */ React5__namespace.default.createElement(table.HeadCell, null), /* @__PURE__ */ React5__namespace.default.createElement(table.HeadCell, null))), /* @__PURE__ */ React5__namespace.default.createElement(table.Body, { className: events_default.body }, events.map((evt) => /* @__PURE__ */ React5__namespace.default.createElement(table.Row, { key: evt.id }, /* @__PURE__ */ React5__namespace.default.createElement(table.Cell, null, evt.time), /* @__PURE__ */ React5__namespace.default.createElement(table.Cell, null, evt.type), /* @__PURE__ */ React5__namespace.default.createElement(ExtraCells, { ...evt })))))
1172
+ );
1173
+ }
1174
+ createFunctionDeclarationNode(xlrNode) {
1175
+ return this.context.factory.createFunctionTypeNode(
1176
+ void 0,
1177
+ xlrNode.parameters.map((e) => {
1178
+ return this.context.factory.createParameterDeclaration(
1179
+ void 0,
1180
+ void 0,
1181
+ e.name,
1182
+ e.optional ? this.context.factory.createToken(ts__default.default.SyntaxKind.QuestionToken) : void 0,
1183
+ this.convertTypeNode(e.type),
1184
+ e.default ? this.createLiteralTypeNode(e.default) : void 0
1185
+ );
1186
+ }),
1187
+ xlrNode.returnType ? this.convertTypeNode(xlrNode.returnType) : this.context.factory.createToken(ts__default.default.SyntaxKind.VoidKeyword)
1188
+ );
1189
+ }
1190
+ createRecordNode(xlrNode) {
1191
+ const keyType = this.convertTypeNode(xlrNode.keyType);
1192
+ const valueType = this.convertTypeNode(xlrNode.valueType);
1193
+ return this.context.factory.createTypeReferenceNode(
1194
+ this.context.factory.createIdentifier("Record"),
1195
+ [keyType, valueType]
1196
+ );
1197
+ }
1198
+ createConditionalTypeNode(xlrNode) {
1199
+ const leftCheck = this.convertTypeNode(xlrNode.check.left);
1200
+ const rightCheck = this.convertTypeNode(xlrNode.check.right);
1201
+ const trueValue = this.convertTypeNode(xlrNode.value.true);
1202
+ const falseValue = this.convertTypeNode(xlrNode.value.false);
1203
+ return this.context.factory.createConditionalTypeNode(
1204
+ leftCheck,
1205
+ rightCheck,
1206
+ trueValue,
1207
+ falseValue
1208
+ );
1209
+ }
1210
+ createObjectNode(xlrNode) {
1211
+ const { properties, additionalProperties = false } = xlrNode;
1212
+ const propertyNodes = [
1213
+ ...Object.keys(properties).map((name) => ({ name, ...properties[name] })).map(
1214
+ ({ name, node, required }) => this.makeAnnotations(
1215
+ this.context.factory.createPropertySignature(
1216
+ void 0,
1217
+ // modifiers
1218
+ name,
1219
+ required ? void 0 : this.context.factory.createToken(ts__default.default.SyntaxKind.QuestionToken),
1220
+ this.convertTypeNode(node)
1221
+ ),
1222
+ node
1223
+ )
1224
+ )
1225
+ ];
1226
+ if (additionalProperties) {
1227
+ propertyNodes.push(
1228
+ this.context.factory.createIndexSignature(
1229
+ void 0,
1230
+ // modifiers
1231
+ [
1232
+ this.context.factory.createParameterDeclaration(
1233
+ void 0,
1234
+ // modifiers
1235
+ void 0,
1236
+ // dotdotdot token
1237
+ "key",
1238
+ void 0,
1239
+ // question token
1240
+ this.context.factory.createKeywordTypeNode(
1241
+ ts__default.default.SyntaxKind.StringKeyword
1242
+ )
1243
+ )
1244
+ ],
1245
+ this.convertTypeNode(additionalProperties)
1246
+ )
1247
+ );
1248
+ }
1249
+ return this.context.factory.createTypeLiteralNode(propertyNodes);
1250
+ }
1251
+ createTemplateLiteral(xlrNode) {
1252
+ const templateSegments = xlrNode.format.split(templateTokenize);
1253
+ let templateHead;
1254
+ if (templateSegments.length % 2 === 0) {
1255
+ templateHead = this.context.factory.createTemplateHead(
1256
+ templateSegments[0]
1257
+ );
1258
+ templateSegments.splice(0, 1);
1259
+ } else {
1260
+ templateHead = this.context.factory.createTemplateHead("");
1261
+ }
1262
+ return this.context.factory.createTemplateLiteralType(
1263
+ templateHead,
1264
+ templateSegments.map((segments, i) => {
1265
+ const [regexSegment, stringSegment = ""] = segments.split(tokenSplit);
1266
+ let regexTemplateType;
1267
+ if (regexSegment === ".*") {
1268
+ regexTemplateType = ts__default.default.SyntaxKind.StringKeyword;
1269
+ } else if (regexSegment === "[0-9]*") {
1270
+ regexTemplateType = ts__default.default.SyntaxKind.NumberKeyword;
1271
+ } else if (regexSegment === "true|false") {
1272
+ regexTemplateType = ts__default.default.SyntaxKind.BooleanKeyword;
1273
+ } else {
1274
+ this.context.throwError(
1275
+ `Can't make template literal type from regex ${regexSegment}`
1276
+ );
1277
+ }
1278
+ let stringTemplateType;
1279
+ if (i === templateSegments.length - 1) {
1280
+ stringTemplateType = this.context.factory.createTemplateTail(stringSegment);
1281
+ } else {
1282
+ stringTemplateType = this.context.factory.createTemplateMiddle(stringSegment);
1283
+ }
1284
+ return this.context.factory.createTemplateLiteralTypeSpan(
1285
+ this.context.factory.createKeywordTypeNode(regexTemplateType),
1286
+ stringTemplateType
1287
+ );
1288
+ })
1289
+ );
1290
+ }
1291
+ createGenericArgumentNode(node) {
1292
+ if (node) {
1293
+ if (node.type === "object" && node.name) {
1294
+ const additionalType = this.convertNamedTypeNode(
1295
+ node
1296
+ );
1297
+ this.additionalTypes.set(node.name, additionalType);
1298
+ return this.context.factory.createTypeReferenceNode(node.name);
1299
+ }
1300
+ return this.convertTypeNode(node);
1301
+ }
1302
+ return void 0;
1303
+ }
1304
+ makeAnnotations(tsNode, xlrAnnotations) {
1305
+ let comment = xlrAnnotations.description;
1306
+ if (!comment) {
1307
+ return tsNode;
1308
+ }
1309
+ if (comment.includes("\n")) {
1310
+ comment = `*
1311
+ ${comment.split("\n").map((s) => ` * ${s}`).join("\n")}
1312
+ `;
1313
+ } else {
1314
+ comment = `* ${comment} `;
1315
+ }
1316
+ return ts__default.default.addSyntheticLeadingComment(
1317
+ tsNode,
1318
+ ts__default.default.SyntaxKind.MultiLineCommentTrivia,
1319
+ comment,
1320
+ true
1321
+ );
1322
+ }
1323
+ createTypeParameters(genericXLRNode) {
1324
+ return genericXLRNode.genericTokens.map((generic) => {
1325
+ return this.context.factory.createTypeParameterDeclaration(
1326
+ void 0,
1327
+ generic.symbol,
1328
+ this.createGenericArgumentNode(generic.constraints),
1329
+ this.createGenericArgumentNode(generic.default)
1330
+ );
1331
+ });
1332
+ }
1333
+ makeInterfaceDeclaration(name, node, generics, heritageClass) {
1334
+ return this.context.factory.createInterfaceDeclaration(
1335
+ this.context.factory.createModifiersFromModifierFlags(
1336
+ ts__default.default.ModifierFlags.Export
1337
+ ),
1338
+ this.context.factory.createIdentifier(name),
1339
+ generics,
1340
+ // type parameters
1341
+ heritageClass,
1342
+ // heritage
1343
+ node
1344
+ );
1345
+ }
1346
+ makeTypeDeclaration(name, node, generics) {
1347
+ return this.context.factory.createTypeAliasDeclaration(
1348
+ this.context.factory.createModifiersFromModifierFlags(
1349
+ ts__default.default.ModifierFlags.Export
1350
+ ),
1351
+ this.context.factory.createIdentifier(name),
1352
+ generics,
1353
+ // type parameters
1354
+ node
1355
+ );
1356
+ }
1357
+ };
1358
+
1359
+ // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/tools/storybook/src/addons/docs/index.tsx
1360
+ function getKeyName(node) {
1361
+ if (node.type === "ref") {
1362
+ return node.ref;
1363
+ }
1364
+ if (node.type === "or") {
1365
+ return node.or.map((subnode) => getKeyName(subnode)).join(" | ");
1366
+ }
1367
+ if (node.type === "and") {
1368
+ return node.and.map((subnode) => getKeyName(subnode)).join(" & ");
1369
+ }
1370
+ if (node.type === "array") {
1371
+ return `Array<${getKeyName(node.elementType)}>`;
1372
+ }
1373
+ if (node.type === "record") {
1374
+ return `Record<${getKeyName(node.keyType)}, ${getKeyName(node.valueType)}>`;
1375
+ }
1376
+ if (isPrimitiveTypeNode(node) && node.type !== "null") {
1377
+ return node.type;
1378
+ }
1379
+ if (node.type === "object" && node.name) {
1380
+ return node.name;
1381
+ }
1382
+ return node.type;
1383
+ }
1384
+ function XLRObjectDocs(props) {
1385
+ const tsWriter = new TSWriter();
1386
+ const printer = ts__default.default.createPrinter();
1387
+ const resultFile = ts__default.default.createSourceFile(
1388
+ "output.d.ts",
1389
+ "",
1390
+ ts__default.default.ScriptTarget.ES2017,
1391
+ false,
1392
+ // setParentNodes
1393
+ ts__default.default.ScriptKind.TS
916
1394
  );
1395
+ return /* @__PURE__ */ React5__namespace.default.createElement("div", { style: { padding: "8px" } }, /* @__PURE__ */ React5__namespace.default.createElement("h2", null, props.xlr.title ?? props.xlr.name), /* @__PURE__ */ React5__namespace.default.createElement("p", { style: { whiteSpace: "pre-line" } }, props.xlr.description), /* @__PURE__ */ React5__namespace.default.createElement("table", null, /* @__PURE__ */ React5__namespace.default.createElement("thead", null, /* @__PURE__ */ React5__namespace.default.createElement("tr", null, /* @__PURE__ */ React5__namespace.default.createElement("th", null, "Name"), /* @__PURE__ */ React5__namespace.default.createElement("th", null, "Required"), /* @__PURE__ */ React5__namespace.default.createElement("th", null, "Type"), /* @__PURE__ */ React5__namespace.default.createElement("th", null, "Description"))), /* @__PURE__ */ React5__namespace.default.createElement("tbody", null, Object.entries(props.xlr.properties).sort(
1396
+ (a, b) => (
1397
+ // bubble up the required props first
1398
+ a[1].required === b[1].required ? 0 : a[1].required ? -1 : 1
1399
+ )
1400
+ ).map(([propKey, propType]) => {
1401
+ let nodeText = getKeyName(
1402
+ propType.node
1403
+ );
1404
+ if (nodeText === "object") {
1405
+ nodeText = propKey;
1406
+ }
1407
+ if (!isPrimitiveTypeNode(propType.node) && propType.node.type !== "ref" && !(propType.node.type === "array" && propType.node.elementType.type === "ref")) {
1408
+ const tsType = tsWriter.convertNamedType({
1409
+ source: props.xlr.source,
1410
+ name: propType.node.name ?? propKey,
1411
+ ...propType.node
1412
+ });
1413
+ const tsText = printer.printNode(
1414
+ ts__default.default.EmitHint.Unspecified,
1415
+ tsType.type,
1416
+ resultFile
1417
+ );
1418
+ nodeText = /* @__PURE__ */ React5__namespace.default.createElement(
1419
+ components.WithTooltip,
1420
+ {
1421
+ trigger: "hover",
1422
+ withArrows: true,
1423
+ tooltip: /* @__PURE__ */ React5__namespace.default.createElement(components.SyntaxHighlighter, { language: "typescript", bordered: true }, tsText)
1424
+ },
1425
+ /* @__PURE__ */ React5__namespace.default.createElement(components.Link, null, nodeText)
1426
+ );
1427
+ }
1428
+ return /* @__PURE__ */ React5__namespace.default.createElement("tr", { key: propKey }, /* @__PURE__ */ React5__namespace.default.createElement("td", null, propKey), /* @__PURE__ */ React5__namespace.default.createElement("td", null, propType.required ? /* @__PURE__ */ React5__namespace.default.createElement("b", null, "yes") : "no"), /* @__PURE__ */ React5__namespace.default.createElement("td", null, nodeText), /* @__PURE__ */ React5__namespace.default.createElement("td", null, propType.node.description));
1429
+ }))));
1430
+ }
1431
+ function DocsPanel(props) {
1432
+ const assetDocsToRender = managerApi.useParameter(
1433
+ "assetDocs"
1434
+ );
1435
+ const defaultXLRSources = managerApi.useParameter(
1436
+ "assetXLRSources"
1437
+ );
1438
+ const darkMode = useDarkMode(props.api);
1439
+ if (!props.active) {
1440
+ return null;
1441
+ }
1442
+ if (assetDocsToRender === void 0 && defaultXLRSources === void 0) {
1443
+ return /* @__PURE__ */ React5__namespace.default.createElement("div", null, "Loading...");
1444
+ }
1445
+ if (defaultXLRSources === void 0) {
1446
+ return /* @__PURE__ */ React5__namespace.default.createElement("div", null, "No assetXLRSources configured. Unable to generate docs.");
1447
+ }
1448
+ if (assetDocsToRender === void 0) {
1449
+ return /* @__PURE__ */ React5__namespace.default.createElement("div", null, "Story is not configured to generate asset docs.");
1450
+ }
1451
+ const assetsToRender = assetDocsToRender.map((name) => {
1452
+ for (const xlrSource of defaultXLRSources) {
1453
+ for (const assetXLR of xlrSource.capabilities.Assets) {
1454
+ if (assetXLR.name === name) {
1455
+ return assetXLR;
1456
+ }
1457
+ }
1458
+ for (const viewXLR of xlrSource.capabilities.Views) {
1459
+ if (viewXLR.name === name) {
1460
+ return viewXLR;
1461
+ }
1462
+ }
1463
+ }
1464
+ });
1465
+ return /* @__PURE__ */ React5__namespace.default.createElement("div", null, assetsToRender.map(
1466
+ (assetXLR) => assetDocsToRender === void 0 ? null : /* @__PURE__ */ React5__namespace.default.createElement(
1467
+ XLRObjectDocs,
1468
+ {
1469
+ key: assetXLR.name,
1470
+ xlr: assetXLR,
1471
+ darkMode: Boolean(darkMode)
1472
+ }
1473
+ )
1474
+ ));
1475
+ }
1476
+ var FlowRefresh = () => {
1477
+ const dispatch = reactRedux.useDispatch();
1478
+ return /* @__PURE__ */ React5__namespace.default.createElement(React5__namespace.default.Fragment, null, /* @__PURE__ */ React5__namespace.default.createElement(components.Separator, null), /* @__PURE__ */ React5__namespace.default.createElement(
1479
+ components.IconButton,
1480
+ {
1481
+ placeholder: "Flow Reset",
1482
+ title: "Reset the current flow",
1483
+ onPointerEnterCapture: () => {
1484
+ },
1485
+ onPointerLeaveCapture: () => {
1486
+ },
1487
+ onClick: () => {
1488
+ dispatch(resetEditor());
1489
+ }
1490
+ },
1491
+ /* @__PURE__ */ React5__namespace.default.createElement(components.Icons, { icon: "sync" })
1492
+ ));
917
1493
  };
918
1494
 
919
1495
  // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/tools/storybook/src/manager.tsx
920
1496
  var register = () => {
921
- managerApi.addons.register(ADDON_ID, () => {
1497
+ managerApi.addons.register(ADDON_ID, (api) => {
1498
+ managerApi.addons.add(DOCS_PANEL_ID, {
1499
+ type: types.Addon_TypesEnum.PANEL,
1500
+ title: "Asset Docs",
1501
+ match: ({ viewMode }) => viewMode === "story",
1502
+ render: ({ active }) => /* @__PURE__ */ React5__namespace.default.createElement(StateProvider, null, /* @__PURE__ */ React5__namespace.default.createElement(DocsPanel, { api, active }))
1503
+ });
922
1504
  managerApi.addons.add(EVENT_PANEL_ID, {
923
1505
  type: types.Addon_TypesEnum.PANEL,
924
1506
  title: "Events",
925
1507
  match: ({ viewMode }) => viewMode === "story",
926
- render: ({ active }) => /* @__PURE__ */ React5__namespace.default.createElement(StateProvider, null, /* @__PURE__ */ React5__namespace.default.createElement(EventsPanel, { active: Boolean(active) }))
1508
+ render: ({ active }) => /* @__PURE__ */ React5__namespace.default.createElement(StateProvider, null, /* @__PURE__ */ React5__namespace.default.createElement(EventsPanel, { api, active: Boolean(active) }))
927
1509
  });
928
1510
  managerApi.addons.add(FLOW_PANEL_ID, {
929
1511
  type: types.Addon_TypesEnum.PANEL,
930
1512
  title: "Flow Editor",
931
1513
  match: ({ viewMode }) => viewMode === "story",
932
- render: ({ active }) => /* @__PURE__ */ React5__namespace.default.createElement(StateProvider, null, /* @__PURE__ */ React5__namespace.default.createElement(EditorPanel, { active: Boolean(active) }))
1514
+ render: ({ active }) => /* @__PURE__ */ React5__namespace.default.createElement(StateProvider, null, /* @__PURE__ */ React5__namespace.default.createElement(EditorPanel, { api, active: Boolean(active) }))
1515
+ });
1516
+ managerApi.addons.add(FLOW_REFRESH_TOOL_ID, {
1517
+ title: "Refresh Flow",
1518
+ type: types.Addon_TypesEnum.TOOL,
1519
+ match: ({ viewMode }) => viewMode === "story",
1520
+ render: () => /* @__PURE__ */ React5__namespace.default.createElement(StateProvider, null, /* @__PURE__ */ React5__namespace.default.createElement(FlowRefresh, null))
933
1521
  });
934
1522
  });
935
1523
  };