@gem-sdk/core 1.23.0-staging.409 → 1.23.0-staging.415

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.
@@ -25,6 +25,10 @@ function Spacing(props) {
25
25
  const isDragging = react.useRef(false);
26
26
  const startY = react.useRef(0);
27
27
  const marginBottom = react.useRef(0);
28
+ const $visualNumberValue = react.useRef(null);
29
+ const [marginBottomValue, setMarginBottomValue] = react.useState(0);
30
+ const [isShowVisual, setIsShowVisual] = react.useState(false);
31
+ const hideVisualNumberValue = react.useRef(null);
28
32
  const getNewValueMargin = (event)=>{
29
33
  const top = event.clientY;
30
34
  const diffY = Math.ceil(top - startY.current);
@@ -43,6 +47,7 @@ function Spacing(props) {
43
47
  const $component = $bottomDrag.current.closest('[data-toolbar-wrap]');
44
48
  if ($component) {
45
49
  $component.style.marginBottom = newValue;
50
+ onShowMarginBottomNumber(newValue);
46
51
  }
47
52
  }
48
53
  };
@@ -135,6 +140,7 @@ function Spacing(props) {
135
140
  if ($marginBottom) {
136
141
  if ($bottomBg.current && $bottomDrag.current) {
137
142
  let value = style.marginBottom;
143
+ onShowMarginBottomNumber(value);
138
144
  if (parseFloat(value) < 0) {
139
145
  value = '0';
140
146
  }
@@ -153,17 +159,47 @@ function Spacing(props) {
153
159
  }
154
160
  }
155
161
  }, []);
162
+ const onShowMarginBottomNumber = (value)=>{
163
+ const parsedValue = parseFloat(value);
164
+ setMarginBottomValue(parsedValue);
165
+ setIsShowVisual(true);
166
+ if (hideVisualNumberValue.current) clearTimeout(hideVisualNumberValue.current);
167
+ hideVisualNumberValue.current = setTimeout(()=>{
168
+ setIsShowVisual(false);
169
+ }, 2000);
170
+ // break point 28px
171
+ const topPosition = parsedValue < 28 && parsedValue >= 0 ? parsedValue / 2 + 16 : parsedValue > 28 ? 0 : 16;
172
+ if ($visualNumberValue.current) {
173
+ $visualNumberValue.current.style.transform = `translateY(${topPosition}px)`;
174
+ }
175
+ };
176
+ const previousAdvanced = usePrevious(props.advanced?.['spacing-setting']);
156
177
  react.useEffect(()=>{
178
+ // validate spacing setting changed
179
+ if (JSON.stringify(previousAdvanced) !== JSON.stringify(props.advanced?.['spacing-setting'])) {
180
+ updateSpacing();
181
+ }
182
+ }, [
183
+ previousAdvanced,
184
+ props.advanced,
185
+ updateSpacing
186
+ ]);
187
+ const onWindowResize = react.useCallback(()=>{
157
188
  updateSpacing();
158
- });
189
+ }, [
190
+ updateSpacing
191
+ ]);
159
192
  react.useEffect(()=>{
160
193
  window.addEventListener('editor:toolbar:update-margin-bottom', updateSpacing);
161
194
  window.addEventListener('editor:toolbar:update-padding-left', updateSpacing);
195
+ window.addEventListener('resize', onWindowResize);
162
196
  return ()=>{
163
197
  window.removeEventListener('editor:toolbar:update-margin-bottom', updateSpacing);
164
198
  window.removeEventListener('editor:toolbar:update-padding-left', updateSpacing);
199
+ window.removeEventListener('resize', onWindowResize);
165
200
  };
166
201
  }, [
202
+ onWindowResize,
167
203
  updateSpacing
168
204
  ]);
169
205
  return /*#__PURE__*/ jsxRuntime.jsx(jsxRuntime.Fragment, {
@@ -174,12 +210,20 @@ function Spacing(props) {
174
210
  children: /*#__PURE__*/ jsxRuntime.jsxs("div", {
175
211
  "data-spacing-margin-bottom": true,
176
212
  children: [
177
- /*#__PURE__*/ jsxRuntime.jsx("div", {
213
+ /*#__PURE__*/ jsxRuntime.jsxs("div", {
178
214
  "data-spacing-margin-bottom-bg": true,
179
215
  ref: $bottomBg,
180
- children: /*#__PURE__*/ jsxRuntime.jsx("div", {
181
- "data-spacing-margin-bottom-value": true
182
- })
216
+ children: [
217
+ /*#__PURE__*/ jsxRuntime.jsx("div", {
218
+ "data-spacing-margin-bottom-value": true
219
+ }),
220
+ /*#__PURE__*/ jsxRuntime.jsx("div", {
221
+ "data-active": isShowVisual,
222
+ "data-value-number": true,
223
+ ref: $visualNumberValue,
224
+ children: marginBottomValue
225
+ })
226
+ ]
183
227
  }),
184
228
  /*#__PURE__*/ jsxRuntime.jsx("div", {
185
229
  ref: $bottomDrag,
@@ -193,5 +237,14 @@ function Spacing(props) {
193
237
  })
194
238
  });
195
239
  }
240
+ const usePrevious = (value)=>{
241
+ const ref = react.useRef();
242
+ react.useEffect(()=>{
243
+ ref.current = value;
244
+ }, [
245
+ value
246
+ ]);
247
+ return ref.current;
248
+ };
196
249
 
197
250
  exports.default = Spacing;
@@ -1,5 +1,5 @@
1
1
  import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
2
- import { useRef, useCallback, useEffect } from 'react';
2
+ import { useRef, useState, useCallback, useEffect } from 'react';
3
3
  import 'zustand';
4
4
  import { useBuilderPreviewStore } from '../../contexts/BuilderPreviewContext.js';
5
5
  import 'swr';
@@ -21,6 +21,10 @@ function Spacing(props) {
21
21
  const isDragging = useRef(false);
22
22
  const startY = useRef(0);
23
23
  const marginBottom = useRef(0);
24
+ const $visualNumberValue = useRef(null);
25
+ const [marginBottomValue, setMarginBottomValue] = useState(0);
26
+ const [isShowVisual, setIsShowVisual] = useState(false);
27
+ const hideVisualNumberValue = useRef(null);
24
28
  const getNewValueMargin = (event)=>{
25
29
  const top = event.clientY;
26
30
  const diffY = Math.ceil(top - startY.current);
@@ -39,6 +43,7 @@ function Spacing(props) {
39
43
  const $component = $bottomDrag.current.closest('[data-toolbar-wrap]');
40
44
  if ($component) {
41
45
  $component.style.marginBottom = newValue;
46
+ onShowMarginBottomNumber(newValue);
42
47
  }
43
48
  }
44
49
  };
@@ -131,6 +136,7 @@ function Spacing(props) {
131
136
  if ($marginBottom) {
132
137
  if ($bottomBg.current && $bottomDrag.current) {
133
138
  let value = style.marginBottom;
139
+ onShowMarginBottomNumber(value);
134
140
  if (parseFloat(value) < 0) {
135
141
  value = '0';
136
142
  }
@@ -149,17 +155,47 @@ function Spacing(props) {
149
155
  }
150
156
  }
151
157
  }, []);
158
+ const onShowMarginBottomNumber = (value)=>{
159
+ const parsedValue = parseFloat(value);
160
+ setMarginBottomValue(parsedValue);
161
+ setIsShowVisual(true);
162
+ if (hideVisualNumberValue.current) clearTimeout(hideVisualNumberValue.current);
163
+ hideVisualNumberValue.current = setTimeout(()=>{
164
+ setIsShowVisual(false);
165
+ }, 2000);
166
+ // break point 28px
167
+ const topPosition = parsedValue < 28 && parsedValue >= 0 ? parsedValue / 2 + 16 : parsedValue > 28 ? 0 : 16;
168
+ if ($visualNumberValue.current) {
169
+ $visualNumberValue.current.style.transform = `translateY(${topPosition}px)`;
170
+ }
171
+ };
172
+ const previousAdvanced = usePrevious(props.advanced?.['spacing-setting']);
152
173
  useEffect(()=>{
174
+ // validate spacing setting changed
175
+ if (JSON.stringify(previousAdvanced) !== JSON.stringify(props.advanced?.['spacing-setting'])) {
176
+ updateSpacing();
177
+ }
178
+ }, [
179
+ previousAdvanced,
180
+ props.advanced,
181
+ updateSpacing
182
+ ]);
183
+ const onWindowResize = useCallback(()=>{
153
184
  updateSpacing();
154
- });
185
+ }, [
186
+ updateSpacing
187
+ ]);
155
188
  useEffect(()=>{
156
189
  window.addEventListener('editor:toolbar:update-margin-bottom', updateSpacing);
157
190
  window.addEventListener('editor:toolbar:update-padding-left', updateSpacing);
191
+ window.addEventListener('resize', onWindowResize);
158
192
  return ()=>{
159
193
  window.removeEventListener('editor:toolbar:update-margin-bottom', updateSpacing);
160
194
  window.removeEventListener('editor:toolbar:update-padding-left', updateSpacing);
195
+ window.removeEventListener('resize', onWindowResize);
161
196
  };
162
197
  }, [
198
+ onWindowResize,
163
199
  updateSpacing
164
200
  ]);
165
201
  return /*#__PURE__*/ jsx(Fragment, {
@@ -170,12 +206,20 @@ function Spacing(props) {
170
206
  children: /*#__PURE__*/ jsxs("div", {
171
207
  "data-spacing-margin-bottom": true,
172
208
  children: [
173
- /*#__PURE__*/ jsx("div", {
209
+ /*#__PURE__*/ jsxs("div", {
174
210
  "data-spacing-margin-bottom-bg": true,
175
211
  ref: $bottomBg,
176
- children: /*#__PURE__*/ jsx("div", {
177
- "data-spacing-margin-bottom-value": true
178
- })
212
+ children: [
213
+ /*#__PURE__*/ jsx("div", {
214
+ "data-spacing-margin-bottom-value": true
215
+ }),
216
+ /*#__PURE__*/ jsx("div", {
217
+ "data-active": isShowVisual,
218
+ "data-value-number": true,
219
+ ref: $visualNumberValue,
220
+ children: marginBottomValue
221
+ })
222
+ ]
179
223
  }),
180
224
  /*#__PURE__*/ jsx("div", {
181
225
  ref: $bottomDrag,
@@ -189,5 +233,14 @@ function Spacing(props) {
189
233
  })
190
234
  });
191
235
  }
236
+ const usePrevious = (value)=>{
237
+ const ref = useRef();
238
+ useEffect(()=>{
239
+ ref.current = value;
240
+ }, [
241
+ value
242
+ ]);
243
+ return ref.current;
244
+ };
192
245
 
193
246
  export { Spacing as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gem-sdk/core",
3
- "version": "1.23.0-staging.409",
3
+ "version": "1.23.0-staging.415",
4
4
  "license": "MIT",
5
5
  "sideEffects": false,
6
6
  "main": "dist/cjs/index.js",
@@ -28,7 +28,7 @@
28
28
  },
29
29
  "devDependencies": {
30
30
  "@gem-sdk/adapter-shopify": "1.23.0-staging.383",
31
- "@gem-sdk/styles": "1.23.0-staging.407"
31
+ "@gem-sdk/styles": "1.23.0-staging.415"
32
32
  },
33
33
  "dependencies": {
34
34
  "react-error-boundary": "4.0.10",