@lvce-editor/renderer-process 30.9.0 → 30.10.1

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.
@@ -119,7 +119,8 @@ const confirm$1 = message => {
119
119
  };
120
120
 
121
121
  const state$a = {
122
- styleSheets: Object.create(null)
122
+ styleSheets: Object.create(null),
123
+ texts: Object.create(null)
123
124
  };
124
125
  const set$a = (id, sheet) => {
125
126
  state$a.styleSheets[id] = sheet;
@@ -127,18 +128,57 @@ const set$a = (id, sheet) => {
127
128
  const get$b = id => {
128
129
  return state$a.styleSheets[id];
129
130
  };
131
+ const setText$2 = (id, text) => {
132
+ state$a.texts[id] = text;
133
+ };
134
+ const getText = id => {
135
+ return state$a.texts[id];
136
+ };
137
+ const remove$4 = id => {
138
+ delete state$a.styleSheets[id];
139
+ delete state$a.texts[id];
140
+ };
130
141
 
131
142
  const addCssStyleSheet = (id, text) => {
132
143
  const existing = get$b(id);
133
144
  if (existing) {
134
145
  existing.replaceSync(text);
146
+ setText$2(id, text);
135
147
  return;
136
148
  }
137
149
  const sheet = new CSSStyleSheet({});
138
150
  set$a(id, sheet);
151
+ setText$2(id, text);
139
152
  sheet.replaceSync(text);
140
153
  document.adoptedStyleSheets.push(sheet);
141
154
  };
155
+ const patchCssStyleSheet = (id, start, deleteCount, replacement) => {
156
+ const sheet = get$b(id);
157
+ const text = getText(id);
158
+ if (!sheet || typeof text !== 'string') {
159
+ throw new Error(`stylesheet ${id} must be initialized before it can be patched`);
160
+ }
161
+ if (!Number.isSafeInteger(start) || start < 0 || start > text.length) {
162
+ throw new TypeError('start must be an integer within the stylesheet');
163
+ }
164
+ if (!Number.isSafeInteger(deleteCount) || deleteCount < 0 || start + deleteCount > text.length) {
165
+ throw new TypeError('deleteCount must be an integer within the stylesheet');
166
+ }
167
+ if (typeof replacement !== 'string') {
168
+ throw new TypeError('replacement must be a string');
169
+ }
170
+ const newText = text.slice(0, start) + replacement + text.slice(start + deleteCount);
171
+ sheet.replaceSync(newText);
172
+ setText$2(id, newText);
173
+ };
174
+ const removeCssStyleSheet = id => {
175
+ const sheet = get$b(id);
176
+ if (!sheet) {
177
+ return;
178
+ }
179
+ document.adoptedStyleSheets = document.adoptedStyleSheets.filter(candidate => candidate !== sheet);
180
+ remove$4(id);
181
+ };
142
182
  const getSelectionText = () => {
143
183
  return document.getSelection()?.toString() || '';
144
184
  };
@@ -1359,9 +1399,7 @@ const setStyle = ($Element, styleString) => {
1359
1399
  }
1360
1400
  };
1361
1401
 
1362
- const optionalAttributeProps = new Map([['ariaActivedescendant', 'aria-activedescendant'], ['ariaOwns', 'aria-owns']]);
1363
- const mappedAttributeProps = new Map([['ariaControls', 'aria-controls'], ['ariaLabelledBy', 'aria-labelledby']]);
1364
- const removedAttributeProps = new Map([['ariaActivedescendant', 'aria-activedescendant'], ['ariaControls', 'aria-controls'], ['ariaLabelledBy', 'aria-labelledby'], ['ariaOwns', 'aria-owns'], ['className', 'class'], ['htmlFor', 'for'], ['inputType', 'type']]);
1402
+ const removedAttributeProps = new Map([['ariaActivedescendant', 'aria-activedescendant'], ['ariaControls', 'aria-controls'], ['ariaDescribedBy', 'aria-describedby'], ['ariaInvalid', 'aria-invalid'], ['ariaLabelledBy', 'aria-labelledby'], ['ariaOwns', 'aria-owns'], ['className', 'class'], ['htmlFor', 'for'], ['inputType', 'type']]);
1365
1403
  const pixelStyleProps = new Set(['height', 'left', 'marginTop', 'paddingLeft', 'paddingRight', 'top', 'width']);
1366
1404
  const eventProps = new Set(['onBlur', 'onChange', 'onClick', 'onContextMenu', 'onBeforeInput', 'onDblClick', 'onDragEnd', 'onDragEnter', 'onDragLeave', 'onDragOver', 'onDragStart', 'onDrop', 'onFocus', 'onFocusIn', 'onFocusOut', 'onInput', 'onKeydown', 'onKeyDown', 'onKeyUp', 'onMouseDown', 'onMouseMove', 'onMouseOut', 'onMouseOver', 'onMouseUp', 'onPointerDown', 'onPointerMove', 'onPointerOut', 'onPointerOver', 'onScroll', 'onSelectionChange', 'onSubmit', 'onWheel']);
1367
1405
  const setOptionalAttribute = ($Element, attributeName, value) => {
@@ -1406,18 +1444,25 @@ const removeProp = ($Element, key) => {
1406
1444
  $Element.removeAttribute(attributeName);
1407
1445
  };
1408
1446
  const setProp = ($Element, key, value, eventMap, newEventMap) => {
1409
- const optionalAttributeName = optionalAttributeProps.get(key);
1410
- if (optionalAttributeName) {
1411
- setOptionalAttribute($Element, optionalAttributeName, value);
1412
- return;
1413
- }
1414
- const mappedAttributeName = mappedAttributeProps.get(key);
1415
- if (mappedAttributeName) {
1416
- $Element.setAttribute(mappedAttributeName, value);
1417
- return;
1418
- }
1419
- if (key === 'childCount' || key === 'type') {
1420
- return;
1447
+ switch (key) {
1448
+ case 'ariaActivedescendant':
1449
+ setOptionalAttribute($Element, 'aria-activedescendant', value);
1450
+ return;
1451
+ case 'ariaControls':
1452
+ $Element.setAttribute('aria-controls', value);
1453
+ return;
1454
+ case 'ariaDescribedBy':
1455
+ $Element.setAttribute('aria-describedby', value);
1456
+ return;
1457
+ case 'ariaInvalid':
1458
+ $Element.setAttribute('aria-invalid', value);
1459
+ return;
1460
+ case 'ariaLabelledBy':
1461
+ $Element.setAttribute('aria-labelledby', value);
1462
+ return;
1463
+ case 'ariaOwns':
1464
+ setOptionalAttribute($Element, 'aria-owns', value);
1465
+ return;
1421
1466
  }
1422
1467
  if (key === 'height' || key === 'width') {
1423
1468
  setDimension($Element, key, value);
@@ -1466,6 +1511,9 @@ const setProp = ($Element, key, value, eventMap, newEventMap) => {
1466
1511
 
1467
1512
  const setProps = ($Element, props, eventMap, newEventMap) => {
1468
1513
  for (const key in props) {
1514
+ if (key === 'childCount' || key === 'type') {
1515
+ continue;
1516
+ }
1469
1517
  setProp($Element, key, props[key], eventMap, newEventMap);
1470
1518
  }
1471
1519
  };
@@ -1580,7 +1628,7 @@ const handleNavigateChild = (state, patches, patchIndex) => {
1580
1628
  return true;
1581
1629
  }
1582
1630
  const nextPatch = patches[patchIndex + 1];
1583
- if (nextPatch && nextPatch.type === Replace && patch.index === $Children.length) {
1631
+ if (nextPatch && (nextPatch.type === Replace || nextPatch.type === SetReferenceNodeUid) && patch.index === $Children.length) {
1584
1632
  const $Placeholder = document.createComment('virtual-dom-placeholder');
1585
1633
  state.current.append($Placeholder);
1586
1634
  state.current = $Placeholder;
@@ -8834,6 +8882,7 @@ const dispose$4 = id => {
8834
8882
  if (instance.state.$Viewlet?.isConnected) {
8835
8883
  instance.state.$Viewlet.remove();
8836
8884
  }
8885
+ removeCssStyleSheet(id);
8837
8886
  set$9(id, undefined);
8838
8887
  } catch {
8839
8888
  throw new Error(`Failed to dispose ${id}`);
@@ -9051,6 +9100,7 @@ const commandHandlers = {
9051
9100
  'Viewlet.focusSelector': focusSelector,
9052
9101
  'Viewlet.handleError': handleError$1,
9053
9102
  'Viewlet.move': move,
9103
+ 'Viewlet.patchCss': patchCssStyleSheet,
9054
9104
  'Viewlet.registerEventListeners': registerEventListeners,
9055
9105
  'Viewlet.removeKeyBindings': removeKeyBindings,
9056
9106
  'Viewlet.replaceChildren': replaceChildren,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/renderer-process",
3
- "version": "30.9.0",
3
+ "version": "30.10.1",
4
4
  "keywords": [
5
5
  "lvce-editor",
6
6
  "renderer-process"