@omicronenergy/oscd-scl-dialogs 0.0.8 → 0.0.10
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/CHANGELOG.md +20 -0
- package/custom-elements.json +427 -1
- package/dist/OscdTextEditor.d.ts +4 -2
- package/dist/OscdTextEditor.js +32 -11
- package/dist/OscdTextEditor.js.map +1 -1
- package/dist/ace-editor/AceEditor.d.ts +62 -0
- package/dist/ace-editor/AceEditor.js +202 -0
- package/dist/ace-editor/AceEditor.js.map +1 -0
- package/dist/ace-editor/debounce.d.ts +24 -0
- package/dist/ace-editor/debounce.js +41 -0
- package/dist/ace-editor/debounce.js.map +1 -0
- package/dist/ace-editor/property-decorators.d.ts +66 -0
- package/dist/ace-editor/property-decorators.js +171 -0
- package/dist/ace-editor/property-decorators.js.map +1 -0
- package/dist/wizards/ldevice.js +7 -5
- package/dist/wizards/ldevice.js.map +1 -1
- package/package.json +6 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.0.10](https://github.com/OMICRONEnergyOSS/oscd-scl-dialogs/compare/oscd-scl-dialogs-v0.0.9...oscd-scl-dialogs-v0.0.10) (2026-02-16)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* copy in ace-custom-element to avoid scoping torture ([5b9b757](https://github.com/OMICRONEnergyOSS/oscd-scl-dialogs/commit/5b9b7575f7b0db00175f52ce8f5b53adc4691329))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* bundling ace-editor should not cause component scope issues ([769def5](https://github.com/OMICRONEnergyOSS/oscd-scl-dialogs/commit/769def5eac0c75956e3f20bcb4fb06a379349db9))
|
|
14
|
+
* ldevice updates should only update ldName when correctly set ([042ef2f](https://github.com/OMICRONEnergyOSS/oscd-scl-dialogs/commit/042ef2f3f1da41f5464e0f1ab26da34faf7550bf))
|
|
15
|
+
|
|
16
|
+
## [0.0.9](https://github.com/OMICRONEnergyOSS/oscd-scl-dialogs/compare/oscd-scl-dialogs-v0.0.8...oscd-scl-dialogs-v0.0.9) (2026-02-16)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
### Bug Fixes
|
|
20
|
+
|
|
21
|
+
* ace-editor should not end up on the global customElement reg ([f8680ff](https://github.com/OMICRONEnergyOSS/oscd-scl-dialogs/commit/f8680ffb6414c1a3501029712effb7a412ca60c9))
|
|
22
|
+
|
|
3
23
|
## [0.0.8](https://github.com/OMICRONEnergyOSS/oscd-scl-dialogs/compare/oscd-scl-dialogs-v0.0.7...oscd-scl-dialogs-v0.0.8) (2026-02-15)
|
|
4
24
|
|
|
5
25
|
|
package/custom-elements.json
CHANGED
|
@@ -328,7 +328,7 @@
|
|
|
328
328
|
"text": "object"
|
|
329
329
|
},
|
|
330
330
|
"static": true,
|
|
331
|
-
"default": "{ 'ace-editor': AceEditor, }"
|
|
331
|
+
"default": "{ // Left here for clarity sake. We need to dyn-import this so we have a chance of overriding the customElements.define to prevent // ace-editor from being registered globally and causing issues with other instances of ace-editor in the same document. 'ace-editor': AceEditor, }"
|
|
332
332
|
},
|
|
333
333
|
{
|
|
334
334
|
"kind": "field",
|
|
@@ -367,6 +367,29 @@
|
|
|
367
367
|
}
|
|
368
368
|
]
|
|
369
369
|
},
|
|
370
|
+
{
|
|
371
|
+
"kind": "method",
|
|
372
|
+
"name": "firstUpdated",
|
|
373
|
+
"privacy": "protected",
|
|
374
|
+
"return": {
|
|
375
|
+
"type": {
|
|
376
|
+
"text": "void"
|
|
377
|
+
}
|
|
378
|
+
},
|
|
379
|
+
"parameters": [
|
|
380
|
+
{
|
|
381
|
+
"name": "_changedProperties",
|
|
382
|
+
"type": {
|
|
383
|
+
"text": "PropertyValues"
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
]
|
|
387
|
+
},
|
|
388
|
+
{
|
|
389
|
+
"kind": "method",
|
|
390
|
+
"name": "clearSelection",
|
|
391
|
+
"privacy": "private"
|
|
392
|
+
},
|
|
370
393
|
{
|
|
371
394
|
"kind": "method",
|
|
372
395
|
"name": "updated",
|
|
@@ -899,6 +922,403 @@
|
|
|
899
922
|
}
|
|
900
923
|
]
|
|
901
924
|
},
|
|
925
|
+
{
|
|
926
|
+
"kind": "javascript-module",
|
|
927
|
+
"path": "ace-editor/AceEditor.ts",
|
|
928
|
+
"declarations": [
|
|
929
|
+
{
|
|
930
|
+
"kind": "class",
|
|
931
|
+
"description": "Custom element Ace code editor",
|
|
932
|
+
"name": "AceEditor",
|
|
933
|
+
"members": [
|
|
934
|
+
{
|
|
935
|
+
"kind": "field",
|
|
936
|
+
"name": "_observedAttributes",
|
|
937
|
+
"type": {
|
|
938
|
+
"text": "string[]"
|
|
939
|
+
},
|
|
940
|
+
"privacy": "private",
|
|
941
|
+
"static": true,
|
|
942
|
+
"default": "[]"
|
|
943
|
+
},
|
|
944
|
+
{
|
|
945
|
+
"kind": "field",
|
|
946
|
+
"name": "_editor",
|
|
947
|
+
"type": {
|
|
948
|
+
"text": "Ace.Editor | undefined"
|
|
949
|
+
},
|
|
950
|
+
"privacy": "private"
|
|
951
|
+
},
|
|
952
|
+
{
|
|
953
|
+
"kind": "field",
|
|
954
|
+
"name": "editor",
|
|
955
|
+
"type": {
|
|
956
|
+
"text": "Ace.Editor | undefined"
|
|
957
|
+
},
|
|
958
|
+
"readonly": true
|
|
959
|
+
},
|
|
960
|
+
{
|
|
961
|
+
"kind": "field",
|
|
962
|
+
"name": "version",
|
|
963
|
+
"type": {
|
|
964
|
+
"text": "{ [key: string]: string }"
|
|
965
|
+
},
|
|
966
|
+
"readonly": true
|
|
967
|
+
},
|
|
968
|
+
{
|
|
969
|
+
"kind": "field",
|
|
970
|
+
"name": "value",
|
|
971
|
+
"type": {
|
|
972
|
+
"text": "string | undefined"
|
|
973
|
+
}
|
|
974
|
+
},
|
|
975
|
+
{
|
|
976
|
+
"kind": "field",
|
|
977
|
+
"name": "mode",
|
|
978
|
+
"type": {
|
|
979
|
+
"text": "string | undefined"
|
|
980
|
+
}
|
|
981
|
+
},
|
|
982
|
+
{
|
|
983
|
+
"kind": "field",
|
|
984
|
+
"name": "theme",
|
|
985
|
+
"type": {
|
|
986
|
+
"text": "string | undefined"
|
|
987
|
+
}
|
|
988
|
+
},
|
|
989
|
+
{
|
|
990
|
+
"kind": "field",
|
|
991
|
+
"name": "tabSize",
|
|
992
|
+
"type": {
|
|
993
|
+
"text": "number | undefined"
|
|
994
|
+
}
|
|
995
|
+
},
|
|
996
|
+
{
|
|
997
|
+
"kind": "field",
|
|
998
|
+
"name": "readonly",
|
|
999
|
+
"type": {
|
|
1000
|
+
"text": "boolean | undefined"
|
|
1001
|
+
}
|
|
1002
|
+
},
|
|
1003
|
+
{
|
|
1004
|
+
"kind": "field",
|
|
1005
|
+
"name": "softTabs",
|
|
1006
|
+
"type": {
|
|
1007
|
+
"text": "boolean | undefined"
|
|
1008
|
+
}
|
|
1009
|
+
},
|
|
1010
|
+
{
|
|
1011
|
+
"kind": "field",
|
|
1012
|
+
"name": "wrap",
|
|
1013
|
+
"type": {
|
|
1014
|
+
"text": "boolean | undefined"
|
|
1015
|
+
}
|
|
1016
|
+
},
|
|
1017
|
+
{
|
|
1018
|
+
"kind": "field",
|
|
1019
|
+
"name": "valueUpdateMode",
|
|
1020
|
+
"type": {
|
|
1021
|
+
"text": "ValueUpdateMode | undefined"
|
|
1022
|
+
}
|
|
1023
|
+
},
|
|
1024
|
+
{
|
|
1025
|
+
"kind": "field",
|
|
1026
|
+
"name": "hideActiveLineHighlight",
|
|
1027
|
+
"type": {
|
|
1028
|
+
"text": "boolean | undefined"
|
|
1029
|
+
}
|
|
1030
|
+
},
|
|
1031
|
+
{
|
|
1032
|
+
"kind": "field",
|
|
1033
|
+
"name": "hideGutter",
|
|
1034
|
+
"type": {
|
|
1035
|
+
"text": "boolean | undefined"
|
|
1036
|
+
}
|
|
1037
|
+
},
|
|
1038
|
+
{
|
|
1039
|
+
"kind": "field",
|
|
1040
|
+
"name": "hideGutterLineHighlight",
|
|
1041
|
+
"type": {
|
|
1042
|
+
"text": "boolean | undefined"
|
|
1043
|
+
}
|
|
1044
|
+
},
|
|
1045
|
+
{
|
|
1046
|
+
"kind": "field",
|
|
1047
|
+
"name": "hidePrintMargin",
|
|
1048
|
+
"type": {
|
|
1049
|
+
"text": "boolean | undefined"
|
|
1050
|
+
}
|
|
1051
|
+
},
|
|
1052
|
+
{
|
|
1053
|
+
"kind": "field",
|
|
1054
|
+
"name": "basePath",
|
|
1055
|
+
"type": {
|
|
1056
|
+
"text": "string | undefined"
|
|
1057
|
+
}
|
|
1058
|
+
},
|
|
1059
|
+
{
|
|
1060
|
+
"kind": "method",
|
|
1061
|
+
"name": "dispatch",
|
|
1062
|
+
"privacy": "private",
|
|
1063
|
+
"return": {
|
|
1064
|
+
"type": {
|
|
1065
|
+
"text": "void"
|
|
1066
|
+
}
|
|
1067
|
+
},
|
|
1068
|
+
"parameters": [
|
|
1069
|
+
{
|
|
1070
|
+
"name": "type",
|
|
1071
|
+
"type": {
|
|
1072
|
+
"text": "string"
|
|
1073
|
+
}
|
|
1074
|
+
},
|
|
1075
|
+
{
|
|
1076
|
+
"name": "detail",
|
|
1077
|
+
"type": {
|
|
1078
|
+
"text": "T"
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
]
|
|
1082
|
+
},
|
|
1083
|
+
{
|
|
1084
|
+
"kind": "field",
|
|
1085
|
+
"name": "initializeEditor",
|
|
1086
|
+
"privacy": "private"
|
|
1087
|
+
},
|
|
1088
|
+
{
|
|
1089
|
+
"kind": "method",
|
|
1090
|
+
"name": "appendStyles",
|
|
1091
|
+
"privacy": "private"
|
|
1092
|
+
},
|
|
1093
|
+
{
|
|
1094
|
+
"kind": "method",
|
|
1095
|
+
"name": "notifyPropertyChanged",
|
|
1096
|
+
"return": {
|
|
1097
|
+
"type": {
|
|
1098
|
+
"text": "void"
|
|
1099
|
+
}
|
|
1100
|
+
},
|
|
1101
|
+
"parameters": [
|
|
1102
|
+
{
|
|
1103
|
+
"name": "name",
|
|
1104
|
+
"type": {
|
|
1105
|
+
"text": "string"
|
|
1106
|
+
}
|
|
1107
|
+
}
|
|
1108
|
+
]
|
|
1109
|
+
},
|
|
1110
|
+
{
|
|
1111
|
+
"kind": "method",
|
|
1112
|
+
"name": "resize",
|
|
1113
|
+
"return": {
|
|
1114
|
+
"type": {
|
|
1115
|
+
"text": "void"
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1118
|
+
},
|
|
1119
|
+
{
|
|
1120
|
+
"kind": "field",
|
|
1121
|
+
"name": "handleChange",
|
|
1122
|
+
"privacy": "private"
|
|
1123
|
+
},
|
|
1124
|
+
{
|
|
1125
|
+
"kind": "field",
|
|
1126
|
+
"name": "handleBlur",
|
|
1127
|
+
"privacy": "private"
|
|
1128
|
+
}
|
|
1129
|
+
],
|
|
1130
|
+
"events": [
|
|
1131
|
+
{
|
|
1132
|
+
"name": "type",
|
|
1133
|
+
"type": {
|
|
1134
|
+
"text": "CustomEvent"
|
|
1135
|
+
}
|
|
1136
|
+
}
|
|
1137
|
+
],
|
|
1138
|
+
"superclass": {
|
|
1139
|
+
"name": "HTMLElement"
|
|
1140
|
+
},
|
|
1141
|
+
"customElement": true
|
|
1142
|
+
}
|
|
1143
|
+
],
|
|
1144
|
+
"exports": [
|
|
1145
|
+
{
|
|
1146
|
+
"kind": "js",
|
|
1147
|
+
"name": "default",
|
|
1148
|
+
"declaration": {
|
|
1149
|
+
"name": "AceEditor",
|
|
1150
|
+
"module": "ace-editor/AceEditor.ts"
|
|
1151
|
+
}
|
|
1152
|
+
}
|
|
1153
|
+
]
|
|
1154
|
+
},
|
|
1155
|
+
{
|
|
1156
|
+
"kind": "javascript-module",
|
|
1157
|
+
"path": "ace-editor/debounce.ts",
|
|
1158
|
+
"declarations": [
|
|
1159
|
+
{
|
|
1160
|
+
"kind": "function",
|
|
1161
|
+
"name": "debounce",
|
|
1162
|
+
"return": {
|
|
1163
|
+
"type": {
|
|
1164
|
+
"text": "() => Promise<T>"
|
|
1165
|
+
}
|
|
1166
|
+
},
|
|
1167
|
+
"parameters": [
|
|
1168
|
+
{
|
|
1169
|
+
"name": "func",
|
|
1170
|
+
"type": {
|
|
1171
|
+
"text": "(...params: any[]) => T"
|
|
1172
|
+
},
|
|
1173
|
+
"description": "The function to invoke."
|
|
1174
|
+
},
|
|
1175
|
+
{
|
|
1176
|
+
"name": "wait",
|
|
1177
|
+
"default": "0",
|
|
1178
|
+
"description": "The time in milliseconds to wait for idle invocations."
|
|
1179
|
+
}
|
|
1180
|
+
],
|
|
1181
|
+
"description": "Returns a new function that delays invocations to the original function\nwithin a specified wait period. The last invocation within this time period\ngets invoked. All earlier invocations are ignore."
|
|
1182
|
+
}
|
|
1183
|
+
],
|
|
1184
|
+
"exports": [
|
|
1185
|
+
{
|
|
1186
|
+
"kind": "js",
|
|
1187
|
+
"name": "debounce",
|
|
1188
|
+
"declaration": {
|
|
1189
|
+
"name": "debounce",
|
|
1190
|
+
"module": "ace-editor/debounce.ts"
|
|
1191
|
+
}
|
|
1192
|
+
}
|
|
1193
|
+
]
|
|
1194
|
+
},
|
|
1195
|
+
{
|
|
1196
|
+
"kind": "javascript-module",
|
|
1197
|
+
"path": "ace-editor/property-decorators.ts",
|
|
1198
|
+
"declarations": [
|
|
1199
|
+
{
|
|
1200
|
+
"kind": "function",
|
|
1201
|
+
"name": "NotifyAttribute",
|
|
1202
|
+
"parameters": [
|
|
1203
|
+
{
|
|
1204
|
+
"name": "attribute",
|
|
1205
|
+
"optional": true,
|
|
1206
|
+
"type": {
|
|
1207
|
+
"text": "string"
|
|
1208
|
+
},
|
|
1209
|
+
"description": "Override the attribute name to use. If ommitted, the\nproperty name is used (coverted from camelCase, to kebab-case)."
|
|
1210
|
+
}
|
|
1211
|
+
],
|
|
1212
|
+
"description": "Defines that the target property should be exposed as an attribute, and\nthat changes to the attribute should trigger a `notifyPropertyChanged`\ncallback."
|
|
1213
|
+
},
|
|
1214
|
+
{
|
|
1215
|
+
"kind": "function",
|
|
1216
|
+
"name": "NotifyBooleanAttribute",
|
|
1217
|
+
"parameters": [
|
|
1218
|
+
{
|
|
1219
|
+
"name": "attribute",
|
|
1220
|
+
"optional": true,
|
|
1221
|
+
"type": {
|
|
1222
|
+
"text": "string"
|
|
1223
|
+
},
|
|
1224
|
+
"description": "Override the attribute name to use. If ommitted, the\nproperty name is used (coverted from camelCase, to snake-case)."
|
|
1225
|
+
}
|
|
1226
|
+
],
|
|
1227
|
+
"description": "Defines that the target property should be exposed as boolean attribute, and\nthat changes to the attribute should trigger a `notifyPropertyChanged`\ncallback."
|
|
1228
|
+
},
|
|
1229
|
+
{
|
|
1230
|
+
"kind": "function",
|
|
1231
|
+
"name": "NotifyNumericAttribute",
|
|
1232
|
+
"parameters": [
|
|
1233
|
+
{
|
|
1234
|
+
"name": "attribute",
|
|
1235
|
+
"optional": true,
|
|
1236
|
+
"type": {
|
|
1237
|
+
"text": "string"
|
|
1238
|
+
},
|
|
1239
|
+
"description": "Override the attribute name to use. If ommitted, the\nproperty name is used (coverted from camelCase, to snake-case)."
|
|
1240
|
+
}
|
|
1241
|
+
],
|
|
1242
|
+
"description": "Defines that the target property should be exposed as numeric attribute, and\nthat changes to the attribute should trigger a `notifyPropertyChanged`\ncallback."
|
|
1243
|
+
},
|
|
1244
|
+
{
|
|
1245
|
+
"kind": "function",
|
|
1246
|
+
"name": "Notify",
|
|
1247
|
+
"return": {
|
|
1248
|
+
"type": {
|
|
1249
|
+
"text": "(target: NotifyTarget & HTMLElement, key: string) => void"
|
|
1250
|
+
}
|
|
1251
|
+
},
|
|
1252
|
+
"parameters": [
|
|
1253
|
+
{
|
|
1254
|
+
"name": "attribute",
|
|
1255
|
+
"optional": true,
|
|
1256
|
+
"type": {
|
|
1257
|
+
"text": "string"
|
|
1258
|
+
},
|
|
1259
|
+
"description": "Expose the property as an attribute. Note that when\nattribute is specified, this method has the same behavior as\n`NotifyAttribute`."
|
|
1260
|
+
}
|
|
1261
|
+
],
|
|
1262
|
+
"description": "Defines that the target property should trigger a `notifyPropertyChanged`\ncallback when the property changes."
|
|
1263
|
+
},
|
|
1264
|
+
{
|
|
1265
|
+
"kind": "function",
|
|
1266
|
+
"name": "Alias",
|
|
1267
|
+
"parameters": [
|
|
1268
|
+
{
|
|
1269
|
+
"name": "alias",
|
|
1270
|
+
"type": {
|
|
1271
|
+
"text": "string"
|
|
1272
|
+
},
|
|
1273
|
+
"description": "Name of the alias."
|
|
1274
|
+
}
|
|
1275
|
+
],
|
|
1276
|
+
"description": "Creates an alias for the given property with a getter and a setter."
|
|
1277
|
+
}
|
|
1278
|
+
],
|
|
1279
|
+
"exports": [
|
|
1280
|
+
{
|
|
1281
|
+
"kind": "js",
|
|
1282
|
+
"name": "NotifyAttribute",
|
|
1283
|
+
"declaration": {
|
|
1284
|
+
"name": "NotifyAttribute",
|
|
1285
|
+
"module": "ace-editor/property-decorators.ts"
|
|
1286
|
+
}
|
|
1287
|
+
},
|
|
1288
|
+
{
|
|
1289
|
+
"kind": "js",
|
|
1290
|
+
"name": "NotifyBooleanAttribute",
|
|
1291
|
+
"declaration": {
|
|
1292
|
+
"name": "NotifyBooleanAttribute",
|
|
1293
|
+
"module": "ace-editor/property-decorators.ts"
|
|
1294
|
+
}
|
|
1295
|
+
},
|
|
1296
|
+
{
|
|
1297
|
+
"kind": "js",
|
|
1298
|
+
"name": "NotifyNumericAttribute",
|
|
1299
|
+
"declaration": {
|
|
1300
|
+
"name": "NotifyNumericAttribute",
|
|
1301
|
+
"module": "ace-editor/property-decorators.ts"
|
|
1302
|
+
}
|
|
1303
|
+
},
|
|
1304
|
+
{
|
|
1305
|
+
"kind": "js",
|
|
1306
|
+
"name": "Notify",
|
|
1307
|
+
"declaration": {
|
|
1308
|
+
"name": "Notify",
|
|
1309
|
+
"module": "ace-editor/property-decorators.ts"
|
|
1310
|
+
}
|
|
1311
|
+
},
|
|
1312
|
+
{
|
|
1313
|
+
"kind": "js",
|
|
1314
|
+
"name": "Alias",
|
|
1315
|
+
"declaration": {
|
|
1316
|
+
"name": "Alias",
|
|
1317
|
+
"module": "ace-editor/property-decorators.ts"
|
|
1318
|
+
}
|
|
1319
|
+
}
|
|
1320
|
+
]
|
|
1321
|
+
},
|
|
902
1322
|
{
|
|
903
1323
|
"kind": "javascript-module",
|
|
904
1324
|
"path": "demo/demo-editor-plugin.js",
|
|
@@ -1055,6 +1475,12 @@
|
|
|
1055
1475
|
}
|
|
1056
1476
|
]
|
|
1057
1477
|
},
|
|
1478
|
+
{
|
|
1479
|
+
"kind": "javascript-module",
|
|
1480
|
+
"path": "demo/index.js",
|
|
1481
|
+
"declarations": [],
|
|
1482
|
+
"exports": []
|
|
1483
|
+
},
|
|
1058
1484
|
{
|
|
1059
1485
|
"kind": "javascript-module",
|
|
1060
1486
|
"path": "scripts/update-readme.ts",
|
package/dist/OscdTextEditor.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { LitElement, type PropertyValueMap } from 'lit';
|
|
1
|
+
import { LitElement, type PropertyValueMap, PropertyValues } from 'lit';
|
|
2
2
|
import type * as AceGlobal from 'ace-builds';
|
|
3
3
|
import 'ace-builds/src-noconflict/ace.js';
|
|
4
4
|
import 'ace-builds/src-noconflict/theme-sqlserver.js';
|
|
5
5
|
import 'ace-builds/src-noconflict/mode-xml.js';
|
|
6
6
|
import 'ace-builds/src-noconflict/ext-searchbox.js';
|
|
7
|
-
import AceEditor from 'ace-
|
|
7
|
+
import AceEditor from './ace-editor/AceEditor.js';
|
|
8
8
|
import { EditV2 } from '@openscd/oscd-api';
|
|
9
9
|
declare global {
|
|
10
10
|
interface Window {
|
|
@@ -34,6 +34,8 @@ export default class OscdTextEditor extends BaseElement {
|
|
|
34
34
|
connectedCallback(): void;
|
|
35
35
|
disconnectedCallback(): void;
|
|
36
36
|
private handleAceChange;
|
|
37
|
+
protected firstUpdated(_changedProperties: PropertyValues): void;
|
|
38
|
+
private clearSelection;
|
|
37
39
|
protected updated(changedProps: PropertyValueMap<OscdTextEditor>): void;
|
|
38
40
|
render(): import("lit-html").TemplateResult<1>;
|
|
39
41
|
static styles: import("lit").CSSResult;
|
package/dist/OscdTextEditor.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { __decorate } from "tslib";
|
|
2
|
-
import { LitElement, html, css } from 'lit';
|
|
2
|
+
import { LitElement, html, css, } from 'lit';
|
|
3
3
|
import { property, query } from 'lit/decorators.js';
|
|
4
4
|
import { ScopedElementsMixin } from '@open-wc/scoped-elements/lit-element.js';
|
|
5
5
|
import 'ace-builds/src-noconflict/ace.js';
|
|
6
6
|
import 'ace-builds/src-noconflict/theme-sqlserver.js';
|
|
7
7
|
import 'ace-builds/src-noconflict/mode-xml.js';
|
|
8
8
|
import 'ace-builds/src-noconflict/ext-searchbox.js';
|
|
9
|
-
import AceEditor from 'ace-
|
|
9
|
+
import AceEditor from './ace-editor/AceEditor.js';
|
|
10
10
|
const serializer = new XMLSerializer();
|
|
11
11
|
const parser = new DOMParser();
|
|
12
12
|
const ACE_DEFAULT_OPTIONS = {
|
|
@@ -134,7 +134,10 @@ class BaseElement extends ScopedElementsMixin(LitElement) {
|
|
|
134
134
|
*/
|
|
135
135
|
class OscdTextEditor extends BaseElement {
|
|
136
136
|
format() {
|
|
137
|
-
const rawXml = this.aceEditor?.editor?.getSelectedText() ||
|
|
137
|
+
const rawXml = this.aceEditor?.editor?.getSelectedText() ||
|
|
138
|
+
this.aceEditor.editor?.getValue() ||
|
|
139
|
+
this.value ||
|
|
140
|
+
'';
|
|
138
141
|
let initialIndent = '';
|
|
139
142
|
if (this.aceEditor?.editor?.getSelectedText()) {
|
|
140
143
|
const range = this.aceEditor.editor.getSelectionRange();
|
|
@@ -171,16 +174,32 @@ class OscdTextEditor extends BaseElement {
|
|
|
171
174
|
}));
|
|
172
175
|
}
|
|
173
176
|
}
|
|
177
|
+
firstUpdated(_changedProperties) {
|
|
178
|
+
this.clearSelection();
|
|
179
|
+
}
|
|
180
|
+
clearSelection() {
|
|
181
|
+
// Clear selection when content updates
|
|
182
|
+
setTimeout(() => {
|
|
183
|
+
/* For reasons unknown the ace editor initially selects all code, so we need to clear that*/
|
|
184
|
+
const editor = this.aceEditor.editor;
|
|
185
|
+
if (editor) {
|
|
186
|
+
editor.selection.clearSelection();
|
|
187
|
+
editor.moveCursorTo(0, 0);
|
|
188
|
+
}
|
|
189
|
+
}, 100);
|
|
190
|
+
}
|
|
174
191
|
updated(changedProps) {
|
|
175
192
|
if (changedProps.has('value')) {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
}
|
|
193
|
+
const editor = this.aceEditor.editor;
|
|
194
|
+
if (!editor) {
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
// Only update if content actually changed (prevents cursor jump)
|
|
198
|
+
// if (editor.getValue() !== this.value) {
|
|
199
|
+
// editor.setValue(this.value ?? '');
|
|
200
|
+
// }
|
|
201
|
+
editor.selection.clearSelection();
|
|
202
|
+
editor.moveCursorTo(0, 0);
|
|
184
203
|
}
|
|
185
204
|
}
|
|
186
205
|
render() {
|
|
@@ -198,6 +217,8 @@ class OscdTextEditor extends BaseElement {
|
|
|
198
217
|
}
|
|
199
218
|
}
|
|
200
219
|
OscdTextEditor.scopedElements = {
|
|
220
|
+
// Left here for clarity sake. We need to dyn-import this so we have a chance of overriding the customElements.define to prevent
|
|
221
|
+
// ace-editor from being registered globally and causing issues with other instances of ace-editor in the same document.
|
|
201
222
|
'ace-editor': AceEditor,
|
|
202
223
|
};
|
|
203
224
|
OscdTextEditor.styles = css `
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OscdTextEditor.js","sourceRoot":"","sources":["../OscdTextEditor.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,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IAAI,CAAC,KAAK,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC;YAC5B,IAAI,CAAC,aAAa,CAChB,IAAI,WAAW,CAAC,QAAQ,EAAE;gBACxB,MAAM,EAAE,CAAC,CAAC,MAAM;aACjB,CAAC,CACH,CAAC;QACJ,CAAC;IACH,CAAC;IAES,OAAO,CAAC,YAA8C;QAC9D,IAAI,YAAY,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC;YAC9B,uCAAuC;YACvC,UAAU,CAAC,GAAG,EAAE;gBACd,IAAI,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,CAAC;oBAC3B,4FAA4F;oBAC5F,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,SAAS,CAAC,cAAc,EAAE,CAAC;oBACjD,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;gBAC3C,CAAC;YACH,CAAC,EAAE,EAAE,CAAC,CAAC;QACT,CAAC;IACH,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAA;;iBAEE,IAAI,CAAC,KAAK;eACZ,UAAU,CAAC,IAAI;gBACd,UAAU,CAAC,KAAK;kBACd,CAAC,CAAsB,EAAE,EAAE;YACnC,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;QAC1B,CAAC;;;KAGJ,CAAC;IACJ,CAAC;;AArFM,6BAAc,GAAG;IACtB,YAAY,EAAE,SAAS;CACxB,CAAC;AAqFK,qBAAM,GAAG,GAAG,CAAA;;;;;;;;;;;GAWlB,CAAC;eAnGiB,cAAc;AAMjC;IADC,QAAQ,EAAE;6CACe;AAG1B;IADC,KAAK,CAAC,YAAY,CAAC;iDACE","sourcesContent":["import { LitElement, html, css, type PropertyValueMap } from 'lit';\nimport { property, query } from 'lit/decorators.js';\nimport { ScopedElementsMixin } from '@open-wc/scoped-elements/lit-element.js';\nimport type * as AceGlobal from 'ace-builds';\nimport 'ace-builds/src-noconflict/ace.js';\nimport 'ace-builds/src-noconflict/theme-sqlserver.js';\nimport 'ace-builds/src-noconflict/mode-xml.js';\nimport 'ace-builds/src-noconflict/ext-searchbox.js';\nimport AceEditor from 'ace-custom-element';\nimport { EditV2 } from '@openscd/oscd-api';\n\ndeclare global {\n interface Window {\n ace: typeof AceGlobal;\n }\n}\n\nconst serializer = new XMLSerializer();\nconst parser = new DOMParser();\n\nconst ACE_DEFAULT_OPTIONS = {\n fontSize: '14',\n theme: 'ace/theme/sqlserver',\n mode: 'ace/mode/xml',\n};\nconst storageKey = 'oscd:ace-options';\n\nconst getStoredAceOptions = (): Omit<\n Partial<AceGlobal.Ace.EditorOptions>,\n 'theme' | 'mode'\n> &\n Pick<AceGlobal.Ace.EditorOptions, 'theme' | 'mode'> => {\n try {\n const stored = localStorage.getItem(storageKey);\n if (stored) {\n return {\n ...ACE_DEFAULT_OPTIONS,\n ...JSON.parse(stored),\n };\n }\n } catch (error) {\n console.warn('Failed to retrieve Ace options from storage:', error);\n }\n return ACE_DEFAULT_OPTIONS;\n};\n\nlet aceOptions = getStoredAceOptions();\n\nfunction manageAceOptionChange(editor: AceGlobal.Ace.Editor) {\n editor.setOptions(aceOptions);\n\n const originalSetOption = editor.setOption.bind(editor);\n const originalSetOptions = editor.setOptions.bind(editor);\n const persistOptions = () => {\n try {\n aceOptions = {\n ...ACE_DEFAULT_OPTIONS,\n ...editor.getOptions(),\n };\n localStorage.setItem(storageKey, JSON.stringify(aceOptions));\n } catch (error) {\n console.warn('Failed to store Ace options:', error);\n }\n };\n\n editor.setOption = (name: string, value: unknown) => {\n originalSetOption(\n name as keyof AceGlobal.Ace.EditorOptions,\n value as never,\n );\n persistOptions();\n };\n\n editor.setOptions = (options: Partial<AceGlobal.Ace.EditorOptions>) => {\n originalSetOptions(options);\n persistOptions();\n };\n}\n\nexport function parseXml(xml: string): XMLDocument {\n const parsed = parser.parseFromString(xml, 'application/xml');\n const parseError = parsed.querySelector('parsererror');\n if (parseError) {\n const error = new Error(parseError.textContent ?? 'Invalid XML');\n console.error('XML Parsing Error:', error);\n }\n return parsed;\n}\n\nexport function serializeXml(xml: XMLDocument | Element): string {\n return serializer.serializeToString(xml);\n}\n\nexport function formatXml(\n rawXml: string | undefined,\n initialIndent: string = '',\n): string {\n if (!rawXml) {\n return '';\n }\n\n // Trim leading and trailing whitespace to avoid injecting extra < or >\n const xml = rawXml.trim();\n\n let formatted = '';\n let indent = '';\n\n const tab = '\\t';\n const nodes = xml.split(/>\\s*</);\n nodes.forEach(function (node, index) {\n // Remove leading < from first node and trailing > from last node. Allow for selection leading or trailing whitespace.\n if (index === 0) {\n node = node.replace(/^\\s*</, '');\n }\n if (index === nodes.length - 1) {\n node = node.replace(/>\\s*$/, '');\n }\n\n if (node.match(/^\\/\\w/)) {\n indent = indent.substring(tab!.length);\n }\n formatted += initialIndent + indent + '<' + node + '>\\r\\n';\n if (node.match(/^<?\\w[^>]*[^/]$/)) {\n indent += tab;\n }\n });\n\n return formatted.trim();\n}\n\nexport function newOscdTextEditV2({\n element,\n newText,\n}: {\n element: Element;\n newText: string;\n}): EditV2[] | null {\n let newDoc: XMLDocument | null = null;\n try {\n newDoc = newText ? parseXml(newText) : null;\n } catch (error) {\n console.error('Failed to parse XML:', error);\n return null;\n }\n if (element) {\n // get the parent and if we don't have a parent, use the documentElement\n const parent = element.parentElement ?? element.ownerDocument;\n const nextSibling = element.nextSibling ?? null;\n const newElement = newDoc\n ? element.ownerDocument.importNode(newDoc?.documentElement, true)\n : null;\n\n return [\n { node: element },\n ...(newElement\n ? [\n {\n node: newElement,\n parent,\n reference: nextSibling,\n },\n ]\n : []),\n ] as EditV2[];\n }\n return null;\n}\n\nclass BaseElement extends ScopedElementsMixin(LitElement) {}\n\n/**\n * Intent is to keep this generic so it can be migrated to oscd-ui.\n */\nexport default class OscdTextEditor extends BaseElement {\n static scopedElements = {\n 'ace-editor': AceEditor,\n };\n\n @property()\n value: string | undefined;\n\n @query('ace-editor')\n aceEditor!: AceEditor;\n\n public format() {\n const rawXml =\n this.aceEditor?.editor?.getSelectedText() || this.aceEditor.value;\n\n let initialIndent = '';\n if (this.aceEditor?.editor?.getSelectedText()) {\n const range = this.aceEditor.editor.getSelectionRange();\n // Get the starting line of the selection and detect its leading whitespace\n const startLine = range.start.row;\n const lineContent = this.aceEditor.editor.session.getLine(startLine);\n initialIndent = lineContent.match(/^(\\s*)/)?.[1] || '';\n }\n\n const formatted = formatXml(rawXml, initialIndent);\n if (this.aceEditor?.editor?.getSelectedText()) {\n const range = this.aceEditor.editor.getSelectionRange();\n // Remove the trailing \\r\\n\n this.aceEditor.editor.session.replace(\n range,\n formatted.substring(0, formatted.length - 2),\n );\n } else {\n this.value = formatted;\n }\n }\n\n connectedCallback(): void {\n super.connectedCallback();\n window.ace?.config?.addEventListener?.('editor', manageAceOptionChange);\n }\n\n disconnectedCallback(): void {\n super.disconnectedCallback();\n window.ace?.config?.removeEventListener?.('editor', manageAceOptionChange);\n }\n\n private handleAceChange(e: CustomEvent<string>): void {\n if (typeof e.detail !== 'string') {\n return;\n }\n\n if (this.value !== e.detail) {\n this.dispatchEvent(\n new CustomEvent('change', {\n detail: e.detail,\n }),\n );\n }\n }\n\n protected updated(changedProps: PropertyValueMap<OscdTextEditor>): void {\n if (changedProps.has('value')) {\n // Clear selection when content updates\n setTimeout(() => {\n if (this.aceEditor?.editor) {\n /* For reasons unknown the ace editor initially selects all code, so we need to clear that*/\n this.aceEditor.editor.selection.clearSelection();\n this.aceEditor.editor.moveCursorTo(0, 0);\n }\n }, 10);\n }\n }\n\n render() {\n return html`\n <ace-editor\n .value=${this.value}\n mode=${aceOptions.mode}\n theme=${aceOptions.theme}\n @change=${(e: CustomEvent<string>) => {\n this.handleAceChange(e);\n }}\n >\n </ace-editor>\n `;\n }\n\n static styles = css`\n :host {\n height: 100%;\n width: 100%;\n overflow: auto;\n }\n\n ace-editor {\n height: 100%;\n width: 100%;\n }\n `;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"OscdTextEditor.js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AAC,CAAsB,EAAE,EAAE;YACnC,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;QAC1B,CAAC;;;KAGJ,CAAC;IACJ,CAAC;;AAjIM,6BAAc,GAAG;IACtB,gIAAgI;IAChI,wHAAwH;IACxH,YAAY,EAAE,SAAS;CACxB,CAAC;AA+HK,qBAAM,GAAG,GAAG,CAAA;;;;;;;;;;;GAWlB,CAAC;eA/IiB,cAAc;AA0BjC;IADC,QAAQ,EAAE;6CACe;AAG1B;IADC,KAAK,CAAC,YAAY,CAAC;iDACE","sourcesContent":["import {\n LitElement,\n html,\n css,\n type PropertyValueMap,\n PropertyValues,\n} from 'lit';\nimport { property, query } from 'lit/decorators.js';\nimport { ScopedElementsMixin } from '@open-wc/scoped-elements/lit-element.js';\nimport type * as AceGlobal from 'ace-builds';\nimport 'ace-builds/src-noconflict/ace.js';\nimport 'ace-builds/src-noconflict/theme-sqlserver.js';\nimport 'ace-builds/src-noconflict/mode-xml.js';\nimport 'ace-builds/src-noconflict/ext-searchbox.js';\n\nimport AceEditor from './ace-editor/AceEditor.js';\n\nimport { EditV2 } from '@openscd/oscd-api';\n\ndeclare global {\n interface Window {\n ace: typeof AceGlobal;\n }\n}\n\nconst serializer = new XMLSerializer();\nconst parser = new DOMParser();\n\nconst ACE_DEFAULT_OPTIONS = {\n fontSize: '14',\n theme: 'ace/theme/sqlserver',\n mode: 'ace/mode/xml',\n};\nconst storageKey = 'oscd:ace-options';\n\nconst getStoredAceOptions = (): Omit<\n Partial<AceGlobal.Ace.EditorOptions>,\n 'theme' | 'mode'\n> &\n Pick<AceGlobal.Ace.EditorOptions, 'theme' | 'mode'> => {\n try {\n const stored = localStorage.getItem(storageKey);\n if (stored) {\n return {\n ...ACE_DEFAULT_OPTIONS,\n ...JSON.parse(stored),\n };\n }\n } catch (error) {\n console.warn('Failed to retrieve Ace options from storage:', error);\n }\n return ACE_DEFAULT_OPTIONS;\n};\n\nlet aceOptions = getStoredAceOptions();\n\nfunction manageAceOptionChange(editor: AceGlobal.Ace.Editor) {\n editor.setOptions(aceOptions);\n\n const originalSetOption = editor.setOption.bind(editor);\n const originalSetOptions = editor.setOptions.bind(editor);\n const persistOptions = () => {\n try {\n aceOptions = {\n ...ACE_DEFAULT_OPTIONS,\n ...editor.getOptions(),\n };\n localStorage.setItem(storageKey, JSON.stringify(aceOptions));\n } catch (error) {\n console.warn('Failed to store Ace options:', error);\n }\n };\n\n editor.setOption = (name: string, value: unknown) => {\n originalSetOption(\n name as keyof AceGlobal.Ace.EditorOptions,\n value as never,\n );\n persistOptions();\n };\n\n editor.setOptions = (options: Partial<AceGlobal.Ace.EditorOptions>) => {\n originalSetOptions(options);\n persistOptions();\n };\n}\n\nexport function parseXml(xml: string): XMLDocument {\n const parsed = parser.parseFromString(xml, 'application/xml');\n const parseError = parsed.querySelector('parsererror');\n if (parseError) {\n const error = new Error(parseError.textContent ?? 'Invalid XML');\n console.error('XML Parsing Error:', error);\n }\n return parsed;\n}\n\nexport function serializeXml(xml: XMLDocument | Element): string {\n return serializer.serializeToString(xml);\n}\n\nexport function formatXml(\n rawXml: string | undefined,\n initialIndent: string = '',\n): string {\n if (!rawXml) {\n return '';\n }\n\n // Trim leading and trailing whitespace to avoid injecting extra < or >\n const xml = rawXml.trim();\n\n let formatted = '';\n let indent = '';\n\n const tab = '\\t';\n const nodes = xml.split(/>\\s*</);\n nodes.forEach(function (node, index) {\n // Remove leading < from first node and trailing > from last node. Allow for selection leading or trailing whitespace.\n if (index === 0) {\n node = node.replace(/^\\s*</, '');\n }\n if (index === nodes.length - 1) {\n node = node.replace(/>\\s*$/, '');\n }\n\n if (node.match(/^\\/\\w/)) {\n indent = indent.substring(tab!.length);\n }\n formatted += initialIndent + indent + '<' + node + '>\\r\\n';\n if (node.match(/^<?\\w[^>]*[^/]$/)) {\n indent += tab;\n }\n });\n\n return formatted.trim();\n}\n\nexport function newOscdTextEditV2({\n element,\n newText,\n}: {\n element: Element;\n newText: string;\n}): EditV2[] | null {\n let newDoc: XMLDocument | null = null;\n try {\n newDoc = newText ? parseXml(newText) : null;\n } catch (error) {\n console.error('Failed to parse XML:', error);\n return null;\n }\n if (element) {\n // get the parent and if we don't have a parent, use the documentElement\n const parent = element.parentElement ?? element.ownerDocument;\n const nextSibling = element.nextSibling ?? null;\n const newElement = newDoc\n ? element.ownerDocument.importNode(newDoc?.documentElement, true)\n : null;\n\n return [\n { node: element },\n ...(newElement\n ? [\n {\n node: newElement,\n parent,\n reference: nextSibling,\n },\n ]\n : []),\n ] as EditV2[];\n }\n return null;\n}\n\nclass BaseElement extends ScopedElementsMixin(LitElement) {}\n\n/**\n * Intent is to keep this generic so it can be migrated to oscd-ui.\n */\nexport default class OscdTextEditor extends BaseElement {\n static scopedElements = {\n // Left here for clarity sake. We need to dyn-import this so we have a chance of overriding the customElements.define to prevent\n // ace-editor from being registered globally and causing issues with other instances of ace-editor in the same document.\n 'ace-editor': AceEditor,\n };\n\n // constructor() {\n // super();\n // // Special handling to prevent ace-editor from being registered globally, which would cause issues with multiple instances in the same document.\n // // This will all go away once the oscd-ui version is implemented and this project is migrated to oscd-ui\n // const customElementsDefineFn = window.customElements.define;\n // window.customElements.define = (name, constructor) => {\n // if (name !== 'ace-editor') {\n // return customElementsDefineFn(name, constructor);\n // }\n // };\n // import('ace-custom-element').then(AceEditor => {\n // if (!this.registry?.get('ace-editor')) {\n // this.registry?.define('ace-editor', AceEditor.default);\n // this.requestUpdate();\n // }\n // });\n // }\n\n @property()\n value: string | undefined;\n\n @query('ace-editor')\n aceEditor!: AceEditor;\n\n public format() {\n const rawXml =\n this.aceEditor?.editor?.getSelectedText() ||\n this.aceEditor.editor?.getValue() ||\n this.value ||\n '';\n\n let initialIndent = '';\n if (this.aceEditor?.editor?.getSelectedText()) {\n const range = this.aceEditor.editor.getSelectionRange();\n // Get the starting line of the selection and detect its leading whitespace\n const startLine = range.start.row;\n const lineContent = this.aceEditor.editor.session.getLine(startLine);\n initialIndent = lineContent.match(/^(\\s*)/)?.[1] || '';\n }\n\n const formatted = formatXml(rawXml, initialIndent);\n if (this.aceEditor?.editor?.getSelectedText()) {\n const range = this.aceEditor.editor.getSelectionRange();\n // Remove the trailing \\r\\n\n this.aceEditor.editor.session.replace(\n range,\n formatted.substring(0, formatted.length - 2),\n );\n } else {\n this.value = formatted;\n }\n }\n\n connectedCallback(): void {\n super.connectedCallback();\n window.ace?.config?.addEventListener?.('editor', manageAceOptionChange);\n }\n\n disconnectedCallback(): void {\n super.disconnectedCallback();\n window.ace?.config?.removeEventListener?.('editor', manageAceOptionChange);\n }\n\n private handleAceChange(e: CustomEvent<string>): void {\n if (typeof e.detail !== 'string') {\n return;\n }\n\n if (this.value !== e.detail) {\n this.dispatchEvent(\n new CustomEvent('change', {\n detail: e.detail,\n }),\n );\n }\n }\n\n protected firstUpdated(_changedProperties: PropertyValues): void {\n this.clearSelection();\n }\n\n private clearSelection() {\n // Clear selection when content updates\n setTimeout(() => {\n /* For reasons unknown the ace editor initially selects all code, so we need to clear that*/\n const editor = this.aceEditor.editor;\n if (editor) {\n editor.selection.clearSelection();\n editor.moveCursorTo(0, 0);\n }\n }, 100);\n }\n\n protected updated(changedProps: PropertyValueMap<OscdTextEditor>): void {\n if (changedProps.has('value')) {\n const editor = this.aceEditor.editor;\n\n if (!editor) {\n return;\n }\n\n // Only update if content actually changed (prevents cursor jump)\n // if (editor.getValue() !== this.value) {\n // editor.setValue(this.value ?? '');\n // }\n\n editor.selection.clearSelection();\n editor.moveCursorTo(0, 0);\n }\n }\n\n render() {\n return html`\n <ace-editor\n .value=${this.value}\n mode=${aceOptions.mode}\n theme=${aceOptions.theme}\n @change=${(e: CustomEvent<string>) => {\n this.handleAceChange(e);\n }}\n >\n </ace-editor>\n `;\n }\n\n static styles = css`\n :host {\n height: 100%;\n width: 100%;\n overflow: auto;\n }\n\n ace-editor {\n height: 100%;\n width: 100%;\n }\n `;\n}\n"]}
|