@lvce-editor/renderer-process 30.51.0 → 30.52.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9655,7 +9655,101 @@ const setDragData = (viewletId, dragData) => {
9655
9655
  const getDragData = () => {
9656
9656
  return getCurrent();
9657
9657
  };
9658
+
9659
+ // Keep the actual patch baseline intact while a component DOM preview is displayed.
9660
+ const restoreComponentDom = viewletId => {
9661
+ const instance = get$a(viewletId);
9662
+ const $Original = instance?.componentDomOriginal;
9663
+ if (!$Original) {
9664
+ return;
9665
+ }
9666
+ const references = instance.componentDomReferences || [];
9667
+ for (const {
9668
+ placeholder,
9669
+ uid
9670
+ } of references) {
9671
+ const $Child = get$a(uid)?.state.$Viewlet;
9672
+ if ($Child) {
9673
+ placeholder.replaceWith($Child);
9674
+ } else {
9675
+ placeholder.remove();
9676
+ }
9677
+ }
9678
+ instance.state.$Viewlet.replaceWith($Original);
9679
+ set$a(viewletId, {
9680
+ ...instance,
9681
+ componentDom: undefined,
9682
+ componentDomOriginal: undefined,
9683
+ componentDomReferences: undefined,
9684
+ state: {
9685
+ ...instance.state,
9686
+ $Viewlet: $Original
9687
+ }
9688
+ });
9689
+ };
9690
+ const setComponentDom = (viewletId, dom) => {
9691
+ const instance = get$a(viewletId);
9692
+ if (!instance) {
9693
+ return;
9694
+ }
9695
+ const {
9696
+ $Viewlet
9697
+ } = instance.state;
9698
+ const $Original = instance.componentDomOriginal || $Viewlet;
9699
+ const references = [...(instance.componentDomReferences || [])];
9700
+ const newReferences = [];
9701
+ for (const node of dom) {
9702
+ if (node.type !== Reference || references.some(reference => reference.uid === node.uid)) {
9703
+ continue;
9704
+ }
9705
+ const $Child = get$a(node.uid)?.state.$Viewlet;
9706
+ if (!$Child || $Child === $Original || !$Original.contains($Child)) {
9707
+ throw new Error('Component DOM references must belong to the edited component');
9708
+ }
9709
+ newReferences.push({
9710
+ child: $Child,
9711
+ uid: node.uid
9712
+ });
9713
+ }
9714
+ for (const {
9715
+ child,
9716
+ uid
9717
+ } of newReferences) {
9718
+ const placeholder = document.createComment('component-dom-reference');
9719
+ child.before(placeholder);
9720
+ references.push({
9721
+ placeholder,
9722
+ uid
9723
+ });
9724
+ }
9725
+ set$a(viewletId, {
9726
+ ...instance,
9727
+ componentDomOriginal: $Original,
9728
+ componentDomReferences: references
9729
+ });
9730
+ // Render against a detached copy so focus preservation cannot move nodes out of the baseline.
9731
+ let $Preview;
9732
+ try {
9733
+ $Preview = rememberFocus($Viewlet.cloneNode(true), dom, instance.factory.Events, viewletId);
9734
+ } catch (error) {
9735
+ restoreComponentDom(viewletId);
9736
+ throw error;
9737
+ }
9738
+ $Viewlet.replaceWith($Preview);
9739
+ set$a(viewletId, {
9740
+ ...instance,
9741
+ componentDom: dom,
9742
+ componentDomOriginal: $Original,
9743
+ componentDomReferences: references,
9744
+ state: {
9745
+ ...instance.state,
9746
+ $Viewlet: $Preview
9747
+ }
9748
+ });
9749
+ };
9750
+ const getComponentDom = viewletId => get$a(viewletId)?.componentDom;
9658
9751
  const setDom = (viewletId, dom) => {
9752
+ restoreComponentDom(viewletId);
9659
9753
  const instance = get$a(viewletId);
9660
9754
  if (!instance) {
9661
9755
  return;
@@ -9669,6 +9763,7 @@ const setDom = (viewletId, dom) => {
9669
9763
  renderInto($Viewlet, dom, Events);
9670
9764
  };
9671
9765
  const setDom2 = (viewletId, dom) => {
9766
+ restoreComponentDom(viewletId);
9672
9767
  const instance = get$a(viewletId);
9673
9768
  if (!instance) {
9674
9769
  return;
@@ -9700,6 +9795,10 @@ const setDom2 = (viewletId, dom) => {
9700
9795
  });
9701
9796
  };
9702
9797
  const setPatches = (uid, patches) => {
9798
+ if (patches.length === 0) {
9799
+ return;
9800
+ }
9801
+ restoreComponentDom(uid);
9703
9802
  const instance = get$a(uid);
9704
9803
  if (!instance) {
9705
9804
  return;
@@ -9771,6 +9870,7 @@ const commitPending = (uid, transactionId) => {
9771
9870
  const dispose$3 = id => {
9772
9871
  try {
9773
9872
  number(id);
9873
+ restoreComponentDom(id);
9774
9874
  unregisterView(id);
9775
9875
  const instance = get$a(id);
9776
9876
  if (!instance) {
@@ -10053,6 +10153,7 @@ const commandHandlers = {
10053
10153
  'Viewlet.focusElementByName': focusElementByName,
10054
10154
  'Viewlet.focusSelector': focusSelector,
10055
10155
  'Viewlet.focusSelectorAfterRender': focusSelectorAfterRender,
10156
+ 'Viewlet.getComponentDom': getComponentDom,
10056
10157
  'Viewlet.handleError': handleError$1,
10057
10158
  'Viewlet.move': move,
10058
10159
  'Viewlet.patchCss': patchCssStyleSheet,
@@ -10065,6 +10166,7 @@ const commandHandlers = {
10065
10166
  'Viewlet.send': invoke,
10066
10167
  'Viewlet.setBounds': setBounds$1,
10067
10168
  'Viewlet.setCheckBoxValue': setCheckboxValue,
10169
+ 'Viewlet.setComponentDom': setComponentDom,
10068
10170
  'Viewlet.setCss': addCssStyleSheet,
10069
10171
  'Viewlet.setDom': setDom,
10070
10172
  'Viewlet.setDom2': setDom2,
@@ -10593,6 +10695,7 @@ const commandMap = {
10593
10695
  'Viewlet.focusElementByName': focusElementByName,
10594
10696
  'Viewlet.focusSelector': focusSelector,
10595
10697
  'Viewlet.focusSelectorAfterRender': focusSelectorAfterRender,
10698
+ 'Viewlet.getComponentDom': getComponentDom,
10596
10699
  'Viewlet.getDragData': getDragData,
10597
10700
  'Viewlet.handleError': handleError$1,
10598
10701
  'Viewlet.invoke': invoke,
@@ -10606,6 +10709,7 @@ const commandMap = {
10606
10709
  'Viewlet.send': invoke,
10607
10710
  'Viewlet.sendMultiple': sendMultiple,
10608
10711
  'Viewlet.setBounds': setBounds$1,
10712
+ 'Viewlet.setComponentDom': setComponentDom,
10609
10713
  'Viewlet.show': show,
10610
10714
  'WebRtc.readMicLevels': readMicLevels,
10611
10715
  'WebRtc.setRemoteDescription': setRemoteDescription,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/renderer-process",
3
- "version": "30.51.0",
3
+ "version": "30.52.0",
4
4
  "keywords": [
5
5
  "lvce-editor",
6
6
  "renderer-process"
@@ -1,191 +0,0 @@
1
- :root {
2
- --EditorCursorBackground: #aeafad;
3
- --EditorFontFamily: monospace;
4
- --EditorFontFeatureSettings: normal;
5
- --EditorFontSize: 15px;
6
- --EditorFontWeight: 400;
7
- --EditorLetterSpacing: 0;
8
- --EditorLineHeight: 20px;
9
- --EditorSelectionBackground: #264f78;
10
- --EditorTabSize: 2;
11
- --MainBackground: #1e1e1e;
12
- }
13
-
14
- html,
15
- body {
16
- width: 100%;
17
- height: 100%;
18
- margin: 0;
19
- overflow: hidden;
20
- background: var(--MainBackground);
21
- }
22
-
23
- .Viewlet {
24
- contain: strict;
25
- }
26
-
27
- .Editor {
28
- width: 100%;
29
- height: 100%;
30
- background: var(--MainBackground);
31
- color: #d4d4d4;
32
- outline: none;
33
- border: none;
34
- font-family: var(--EditorFontFamily);
35
- white-space: pre;
36
- font-size: var(--EditorFontSize);
37
- letter-spacing: var(--EditorLetterSpacing);
38
- font-feature-settings: var(--EditorFontFeatureSettings);
39
- tab-size: var(--EditorTabSize);
40
- cursor: text;
41
- font-weight: var(--EditorFontWeight);
42
- display: flex;
43
- }
44
-
45
- .EditorContent,
46
- .EditorLayers,
47
- .EditorRows {
48
- contain: strict;
49
- width: 100%;
50
- height: 100%;
51
- }
52
-
53
- .EditorRows {
54
- white-space: pre;
55
- }
56
-
57
- .EditorRow {
58
- display: block;
59
- height: var(--EditorLineHeight);
60
- line-height: var(--EditorLineHeight);
61
- contain: strict;
62
- }
63
-
64
- .Editors {
65
- flex: 1;
66
- }
67
-
68
- .EditorCursor {
69
- width: 2px;
70
- height: var(--EditorLineHeight);
71
- position: absolute;
72
- top: 0;
73
- left: 0;
74
- background: var(--EditorCursorBackground);
75
- pointer-events: none;
76
- contain: strict;
77
- }
78
-
79
- .EditorInput {
80
- position: absolute;
81
- width: 0;
82
- height: 0;
83
- opacity: 0;
84
- padding: 0;
85
- border: 0;
86
- font-size: 1px;
87
- top: -9999px;
88
- left: -9999px;
89
- }
90
-
91
- .EditorSelection {
92
- position: absolute;
93
- top: 0;
94
- left: 0;
95
- pointer-events: none;
96
- background: var(--EditorSelectionBackground);
97
- }
98
-
99
- .Token {
100
- contain: content;
101
- }
102
-
103
- .TokenComment {
104
- color: #6a9955;
105
- }
106
-
107
- .TokenString,
108
- .TokenStringValue {
109
- color: #ce9178;
110
- }
111
-
112
- .TokenNumeric,
113
- .TokenNumber {
114
- color: #b5cea8;
115
- }
116
-
117
- .TokenKeyword,
118
- .TokenTag,
119
- .TokenTagName {
120
- color: #569cd6;
121
- }
122
-
123
- .TokenAttribute,
124
- .TokenAttributeName,
125
- .TokenProperty,
126
- .TokenPropertyName {
127
- color: #9cdcfe;
128
- }
129
-
130
- .TokenPunctuation,
131
- .TokenPunctuationTag {
132
- color: #808080;
133
- }
134
-
135
- .LayerCursor,
136
- .LayerDiagnostics {
137
- position: absolute;
138
- inset: 0;
139
- pointer-events: none;
140
- }
141
-
142
- .Gutter {
143
- contain: strict;
144
- width: 30px;
145
- height: 100%;
146
- display: flex;
147
- flex-direction: column;
148
- }
149
-
150
- .Gutter:empty {
151
- display: none;
152
- }
153
-
154
- .LineNumber {
155
- color: rgba(155, 162, 160, 0.6);
156
- contain: strict;
157
- margin-right: 1px;
158
- height: var(--EditorLineHeight);
159
- text-align: right;
160
- }
161
-
162
- .ScrollBar {
163
- position: absolute;
164
- right: 0;
165
- top: 0;
166
- width: 14px;
167
- bottom: 0;
168
- contain: strict;
169
- cursor: default;
170
- }
171
-
172
- .ScrollBarHorizontal {
173
- left: 0;
174
- top: auto;
175
- height: 14px;
176
- width: auto;
177
- }
178
-
179
- .ScrollBarThumb {
180
- width: 100%;
181
- position: absolute;
182
- contain: strict;
183
- background: rgba(57, 71, 71, 0.6);
184
- height: var(--ScrollBarThumbHeight);
185
- top: var(--ScrollBarThumbTop);
186
- }
187
-
188
- .ScrollBarThumbHorizontal {
189
- height: 100%;
190
- width: auto;
191
- }