@ibiz-template-plugin/ibiz-file-previewer 0.0.25 → 0.0.26

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.es.js CHANGED
@@ -917,6 +917,8 @@ var ImageMode = /* @__PURE__ */ ((ImageMode2) => {
917
917
  var FileType = /* @__PURE__ */ ((FileType2) => {
918
918
  FileType2["HTML"] = "html";
919
919
  FileType2["MD"] = "md";
920
+ FileType2["YAML"] = "yaml";
921
+ FileType2["YML"] = "yml";
920
922
  FileType2["TXT"] = "txt";
921
923
  FileType2["JSON"] = "json";
922
924
  FileType2["XML"] = "xml";
@@ -984,24 +986,32 @@ const FileTypeEngineMap = /* @__PURE__ */ new Map([
984
986
  ]],
985
987
  // ET类型文件
986
988
  // ------TXT类型文件服务端暂未支持START------
987
- // [FileType.TXT, [EngineType.TXT]], // TXT类型文件
988
- // [FileType.JSON, [EngineType.TXT]], // JSON类型文件
989
- // [FileType.XML, [EngineType.TXT]], // XML类型文件
990
- ["txt", [
991
- "MD"
992
- /* MD */
989
+ ["yaml", [
990
+ "TXT"
991
+ /* TXT */
993
992
  ]],
994
- // TXT类型文件
993
+ // YAML类型文件
994
+ ["yml", [
995
+ "TXT"
996
+ /* TXT */
997
+ ]],
998
+ // YML类型文件
995
999
  ["json", [
996
- "MD"
997
- /* MD */
1000
+ "TXT"
1001
+ /* TXT */
998
1002
  ]],
999
1003
  // JSON类型文件
1000
1004
  ["xml", [
1005
+ "TXT"
1006
+ /* TXT */
1007
+ ]],
1008
+ // XML类型文件
1009
+ // [FileType.TXT, [EngineType.TXT]], // TXT类型文件
1010
+ ["txt", [
1001
1011
  "MD"
1002
1012
  /* MD */
1003
1013
  ]],
1004
- // XML类型文件
1014
+ // TXT类型文件
1005
1015
  // ------TXT类型文件服务端暂未支持END------
1006
1016
  ["pdf", [
1007
1017
  "PDF"
@@ -1178,6 +1188,12 @@ const fileNameToFileType = (fileName) => {
1178
1188
  case "csv":
1179
1189
  fileType = FileType.CSV;
1180
1190
  break;
1191
+ case "yaml":
1192
+ fileType = FileType.YAML;
1193
+ break;
1194
+ case "yml":
1195
+ fileType = FileType.YML;
1196
+ break;
1181
1197
  default:
1182
1198
  fileType = FileType.UNKNOWN;
1183
1199
  }
@@ -18789,14 +18805,223 @@ function xml(hljs) {
18789
18805
  ]
18790
18806
  };
18791
18807
  }
18808
+ function yaml(hljs) {
18809
+ const LITERALS = "true false yes no null";
18810
+ const URI_CHARACTERS = "[\\w#;/?:@&=+$,.~*'()[\\]]+";
18811
+ const KEY = {
18812
+ className: "attr",
18813
+ variants: [
18814
+ // added brackets support and special char support
18815
+ { begin: /[\w*@][\w*@ :()\./-]*:(?=[ \t]|$)/ },
18816
+ {
18817
+ // double quoted keys - with brackets and special char support
18818
+ begin: /"[\w*@][\w*@ :()\./-]*":(?=[ \t]|$)/
18819
+ },
18820
+ {
18821
+ // single quoted keys - with brackets and special char support
18822
+ begin: /'[\w*@][\w*@ :()\./-]*':(?=[ \t]|$)/
18823
+ }
18824
+ ]
18825
+ };
18826
+ const TEMPLATE_VARIABLES = {
18827
+ className: "template-variable",
18828
+ variants: [
18829
+ {
18830
+ // jinja templates Ansible
18831
+ begin: /\{\{/,
18832
+ end: /\}\}/
18833
+ },
18834
+ {
18835
+ // Ruby i18n
18836
+ begin: /%\{/,
18837
+ end: /\}/
18838
+ }
18839
+ ]
18840
+ };
18841
+ const SINGLE_QUOTE_STRING = {
18842
+ className: "string",
18843
+ relevance: 0,
18844
+ begin: /'/,
18845
+ end: /'/,
18846
+ contains: [
18847
+ {
18848
+ match: /''/,
18849
+ scope: "char.escape",
18850
+ relevance: 0
18851
+ }
18852
+ ]
18853
+ };
18854
+ const STRING = {
18855
+ className: "string",
18856
+ relevance: 0,
18857
+ variants: [
18858
+ {
18859
+ begin: /"/,
18860
+ end: /"/
18861
+ },
18862
+ { begin: /\S+/ }
18863
+ ],
18864
+ contains: [
18865
+ hljs.BACKSLASH_ESCAPE,
18866
+ TEMPLATE_VARIABLES
18867
+ ]
18868
+ };
18869
+ const CONTAINER_STRING = hljs.inherit(STRING, { variants: [
18870
+ {
18871
+ begin: /'/,
18872
+ end: /'/,
18873
+ contains: [
18874
+ {
18875
+ begin: /''/,
18876
+ relevance: 0
18877
+ }
18878
+ ]
18879
+ },
18880
+ {
18881
+ begin: /"/,
18882
+ end: /"/
18883
+ },
18884
+ { begin: /[^\s,{}[\]]+/ }
18885
+ ] });
18886
+ const DATE_RE = "[0-9]{4}(-[0-9][0-9]){0,2}";
18887
+ const TIME_RE = "([Tt \\t][0-9][0-9]?(:[0-9][0-9]){2})?";
18888
+ const FRACTION_RE = "(\\.[0-9]*)?";
18889
+ const ZONE_RE = "([ \\t])*(Z|[-+][0-9][0-9]?(:[0-9][0-9])?)?";
18890
+ const TIMESTAMP = {
18891
+ className: "number",
18892
+ begin: "\\b" + DATE_RE + TIME_RE + FRACTION_RE + ZONE_RE + "\\b"
18893
+ };
18894
+ const VALUE_CONTAINER = {
18895
+ end: ",",
18896
+ endsWithParent: true,
18897
+ excludeEnd: true,
18898
+ keywords: LITERALS,
18899
+ relevance: 0
18900
+ };
18901
+ const OBJECT = {
18902
+ begin: /\{/,
18903
+ end: /\}/,
18904
+ contains: [VALUE_CONTAINER],
18905
+ illegal: "\\n",
18906
+ relevance: 0
18907
+ };
18908
+ const ARRAY = {
18909
+ begin: "\\[",
18910
+ end: "\\]",
18911
+ contains: [VALUE_CONTAINER],
18912
+ illegal: "\\n",
18913
+ relevance: 0
18914
+ };
18915
+ const MODES2 = [
18916
+ KEY,
18917
+ {
18918
+ className: "meta",
18919
+ begin: "^---\\s*$",
18920
+ relevance: 10
18921
+ },
18922
+ {
18923
+ // multi line string
18924
+ // Blocks start with a | or > followed by a newline
18925
+ //
18926
+ // Indentation of subsequent lines must be the same to
18927
+ // be considered part of the block
18928
+ className: "string",
18929
+ begin: "[\\|>]([1-9]?[+-])?[ ]*\\n( +)[^ ][^\\n]*\\n(\\2[^\\n]+\\n?)*"
18930
+ },
18931
+ {
18932
+ // Ruby/Rails erb
18933
+ begin: "<%[%=-]?",
18934
+ end: "[%-]?%>",
18935
+ subLanguage: "ruby",
18936
+ excludeBegin: true,
18937
+ excludeEnd: true,
18938
+ relevance: 0
18939
+ },
18940
+ {
18941
+ // named tags
18942
+ className: "type",
18943
+ begin: "!\\w+!" + URI_CHARACTERS
18944
+ },
18945
+ // https://yaml.org/spec/1.2/spec.html#id2784064
18946
+ {
18947
+ // verbatim tags
18948
+ className: "type",
18949
+ begin: "!<" + URI_CHARACTERS + ">"
18950
+ },
18951
+ {
18952
+ // primary tags
18953
+ className: "type",
18954
+ begin: "!" + URI_CHARACTERS
18955
+ },
18956
+ {
18957
+ // secondary tags
18958
+ className: "type",
18959
+ begin: "!!" + URI_CHARACTERS
18960
+ },
18961
+ {
18962
+ // fragment id &ref
18963
+ className: "meta",
18964
+ begin: "&" + hljs.UNDERSCORE_IDENT_RE + "$"
18965
+ },
18966
+ {
18967
+ // fragment reference *ref
18968
+ className: "meta",
18969
+ begin: "\\*" + hljs.UNDERSCORE_IDENT_RE + "$"
18970
+ },
18971
+ {
18972
+ // array listing
18973
+ className: "bullet",
18974
+ // TODO: remove |$ hack when we have proper look-ahead support
18975
+ begin: "-(?=[ ]|$)",
18976
+ relevance: 0
18977
+ },
18978
+ hljs.HASH_COMMENT_MODE,
18979
+ {
18980
+ beginKeywords: LITERALS,
18981
+ keywords: { literal: LITERALS }
18982
+ },
18983
+ TIMESTAMP,
18984
+ // numbers are any valid C-style number that
18985
+ // sit isolated from other words
18986
+ {
18987
+ className: "number",
18988
+ begin: hljs.C_NUMBER_RE + "\\b",
18989
+ relevance: 0
18990
+ },
18991
+ OBJECT,
18992
+ ARRAY,
18993
+ SINGLE_QUOTE_STRING,
18994
+ STRING
18995
+ ];
18996
+ const VALUE_MODES = [...MODES2];
18997
+ VALUE_MODES.pop();
18998
+ VALUE_MODES.push(CONTAINER_STRING);
18999
+ VALUE_CONTAINER.contains = VALUE_MODES;
19000
+ return {
19001
+ name: "YAML",
19002
+ case_insensitive: true,
19003
+ aliases: ["yml"],
19004
+ contains: MODES2
19005
+ };
19006
+ }
18792
19007
  HighlightJS.registerLanguage("xml", xml);
18793
19008
  HighlightJS.registerLanguage("json", json);
19009
+ HighlightJS.registerLanguage("yaml", yaml);
18794
19010
  const FilePreviewText = (props) => {
18795
19011
  const c2 = props.controller;
18796
19012
  const previewRef = A(null);
18797
19013
  y$1(() => {
18798
19014
  try {
18799
- previewRef.current.textContent = c2.state.value.content;
19015
+ if (c2.state.value.fileType === FileType.JSON) {
19016
+ try {
19017
+ const jsonObject = JSON.parse(c2.state.value.content);
19018
+ previewRef.current.textContent = JSON.stringify(jsonObject, null, 2);
19019
+ } catch (error2) {
19020
+ previewRef.current.textContent = c2.state.value.content;
19021
+ }
19022
+ } else {
19023
+ previewRef.current.textContent = c2.state.value.content;
19024
+ }
18800
19025
  HighlightJS.highlightElement(previewRef.current);
18801
19026
  } catch (error2) {
18802
19027
  console.error(error2);