histoire 0.1.2 → 0.1.3

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.
@@ -1,5 +1,5 @@
1
1
  <script lang="ts" setup>
2
- import { computed, Ref, ref, toRaw, toRefs, watch } from 'vue'
2
+ import { computed, Ref, ref, toRaw, watch } from 'vue'
3
3
  import { useEventListener } from '@vueuse/core'
4
4
  import { Icon } from '@iconify/vue'
5
5
  import { STATE_SYNC, PREVIEW_SETTINGS_SYNC, SANDBOX_READY } from '../../util/const'
@@ -8,6 +8,7 @@ import type { Story, Variant } from '../../types'
8
8
  import HatchedPattern from '../misc/HatchedPattern.vue'
9
9
  import CheckerboardPattern from '../misc/CheckerboardPattern.vue'
10
10
  import { toRawDeep } from '../../util/reactivity'
11
+ import { Settings } from 'http2'
11
12
 
12
13
  const props = defineProps<{
13
14
  story: Story
@@ -15,6 +16,10 @@ const props = defineProps<{
15
16
  settings: PreviewSettings
16
17
  }>()
17
18
 
19
+ const emit = defineEmits({
20
+ 'update:settings': (settings: PreviewSettings) => true,
21
+ })
22
+
18
23
  // Iframe
19
24
 
20
25
  const iframe = ref<HTMLIFrameElement>()
@@ -120,7 +125,43 @@ function useDragger (el: Ref<HTMLDivElement>, value: Ref<number>, min: number, m
120
125
  useEventListener(el, 'mousedown', onMouseDown)
121
126
  }
122
127
 
123
- const { responsiveWidth, responsiveHeight } = toRefs(props.settings)
128
+ // Optimize by batching settings updates to the next frame
129
+ // Prevents sync issues with `useStorage`
130
+ let settingsUpdate: Partial<Settings> = {}
131
+ let settingsUpdateQueued = false
132
+
133
+ function updateSettings (settings: Partial<PreviewSettings>) {
134
+ Object.assign(settingsUpdate, settings)
135
+
136
+ if (!settingsUpdateQueued) {
137
+ settingsUpdateQueued = true
138
+ requestAnimationFrame(() => {
139
+ emit('update:settings', {
140
+ ...props.settings,
141
+ ...settingsUpdate,
142
+ })
143
+ settingsUpdate = {}
144
+ settingsUpdateQueued = false
145
+ })
146
+ }
147
+ }
148
+
149
+ const responsiveWidth = computed({
150
+ get: () => props.settings[props.settings.rotate ? 'responsiveHeight' : 'responsiveWidth'],
151
+ set: (value) => {
152
+ updateSettings({
153
+ [props.settings.rotate ? 'responsiveHeight' : 'responsiveWidth']: value,
154
+ })
155
+ },
156
+ })
157
+ const responsiveHeight = computed({
158
+ get: () => props.settings[props.settings.rotate ? 'responsiveWidth' : 'responsiveHeight'],
159
+ set: (value) => {
160
+ updateSettings({
161
+ [props.settings.rotate ? 'responsiveWidth' : 'responsiveHeight']: value,
162
+ })
163
+ },
164
+ })
124
165
 
125
166
  const horizontalDragger = ref<HTMLDivElement>()
126
167
  const verticalDragger = ref<HTMLDivElement>()
@@ -168,9 +168,9 @@ const settings = usePreviewSettings()
168
168
 
169
169
  <!-- Preview -->
170
170
  <StoryResponsivePreview
171
+ v-model:settings="settings"
171
172
  :story="story"
172
173
  :variant="variant"
173
- :settings="settings"
174
174
  />
175
175
  </div>
176
176
  </template>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "histoire",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "A fast story book powered by Vite",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -34,9 +34,9 @@
34
34
  },
35
35
  "dependencies": {
36
36
  "@iconify/vue": "^3.1.3",
37
- "@histoire/controls": "^0.1.2",
37
+ "@histoire/controls": "^0.1.3",
38
38
  "@vitejs/plugin-vue": "^2.2.0",
39
- "@vueuse/core": "^7.6.2",
39
+ "@vueuse/core": "^8.1.1",
40
40
  "case": "^1.6.3",
41
41
  "chokidar": "^3.5.3",
42
42
  "defu": "^5.0.1",
@@ -1,5 +1,5 @@
1
1
  <script lang="ts" setup>
2
- import { computed, Ref, ref, toRaw, toRefs, watch } from 'vue'
2
+ import { computed, Ref, ref, toRaw, watch } from 'vue'
3
3
  import { useEventListener } from '@vueuse/core'
4
4
  import { Icon } from '@iconify/vue'
5
5
  import { STATE_SYNC, PREVIEW_SETTINGS_SYNC, SANDBOX_READY } from '../../util/const'
@@ -8,6 +8,7 @@ import type { Story, Variant } from '../../types'
8
8
  import HatchedPattern from '../misc/HatchedPattern.vue'
9
9
  import CheckerboardPattern from '../misc/CheckerboardPattern.vue'
10
10
  import { toRawDeep } from '../../util/reactivity'
11
+ import { Settings } from 'http2'
11
12
 
12
13
  const props = defineProps<{
13
14
  story: Story
@@ -15,6 +16,10 @@ const props = defineProps<{
15
16
  settings: PreviewSettings
16
17
  }>()
17
18
 
19
+ const emit = defineEmits({
20
+ 'update:settings': (settings: PreviewSettings) => true,
21
+ })
22
+
18
23
  // Iframe
19
24
 
20
25
  const iframe = ref<HTMLIFrameElement>()
@@ -120,7 +125,43 @@ function useDragger (el: Ref<HTMLDivElement>, value: Ref<number>, min: number, m
120
125
  useEventListener(el, 'mousedown', onMouseDown)
121
126
  }
122
127
 
123
- const { responsiveWidth, responsiveHeight } = toRefs(props.settings)
128
+ // Optimize by batching settings updates to the next frame
129
+ // Prevents sync issues with `useStorage`
130
+ let settingsUpdate: Partial<Settings> = {}
131
+ let settingsUpdateQueued = false
132
+
133
+ function updateSettings (settings: Partial<PreviewSettings>) {
134
+ Object.assign(settingsUpdate, settings)
135
+
136
+ if (!settingsUpdateQueued) {
137
+ settingsUpdateQueued = true
138
+ requestAnimationFrame(() => {
139
+ emit('update:settings', {
140
+ ...props.settings,
141
+ ...settingsUpdate,
142
+ })
143
+ settingsUpdate = {}
144
+ settingsUpdateQueued = false
145
+ })
146
+ }
147
+ }
148
+
149
+ const responsiveWidth = computed({
150
+ get: () => props.settings[props.settings.rotate ? 'responsiveHeight' : 'responsiveWidth'],
151
+ set: (value) => {
152
+ updateSettings({
153
+ [props.settings.rotate ? 'responsiveHeight' : 'responsiveWidth']: value,
154
+ })
155
+ },
156
+ })
157
+ const responsiveHeight = computed({
158
+ get: () => props.settings[props.settings.rotate ? 'responsiveWidth' : 'responsiveHeight'],
159
+ set: (value) => {
160
+ updateSettings({
161
+ [props.settings.rotate ? 'responsiveWidth' : 'responsiveHeight']: value,
162
+ })
163
+ },
164
+ })
124
165
 
125
166
  const horizontalDragger = ref<HTMLDivElement>()
126
167
  const verticalDragger = ref<HTMLDivElement>()
@@ -168,9 +168,9 @@ const settings = usePreviewSettings()
168
168
 
169
169
  <!-- Preview -->
170
170
  <StoryResponsivePreview
171
+ v-model:settings="settings"
171
172
  :story="story"
172
173
  :variant="variant"
173
- :settings="settings"
174
174
  />
175
175
  </div>
176
176
  </template>