@m3ui-vue/m3ui-vue 1.3.1 → 1.3.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@m3ui-vue/m3ui-vue",
3
- "version": "1.3.1",
3
+ "version": "1.3.2",
4
4
  "description": "Material 3 component library for Vue 3 + Tailwind CSS v4",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -297,3 +297,33 @@ describe('MFloorPlan merges across the room', () => {
297
297
  expect(w.findAll('.m3-floor-merge-label')).toHaveLength(1)
298
298
  })
299
299
  })
300
+
301
+ describe('MFloorPlan dragMerged', () => {
302
+ it('a merged table drags its merge along', async () => {
303
+ const w: any = mount(MFloorPlan, {
304
+ props: { editable: true, grid: 10, dragMerged: true, tables: base(), merges: [{ id: 'm', tables: [1, 2] }], 'onUpdate:tables': (v: FloorTable[]) => w.setProps({ tables: v }) },
305
+ attachTo: document.body,
306
+ })
307
+ table(w, 'T1').element.dispatchEvent(new PointerEvent('pointerdown', { bubbles: true, button: 0, clientX: 0, clientY: 0, pointerId: 4 }))
308
+ window.dispatchEvent(new PointerEvent('pointermove', { clientX: 20, clientY: 30, pointerId: 4 }))
309
+ window.dispatchEvent(new PointerEvent('pointerup', { clientX: 20, clientY: 30, pointerId: 4 }))
310
+ await nextTick()
311
+ expect(w.props('tables').map((t: FloorTable) => [t.x, t.y])).toEqual([[120, 130], [320, 130]])
312
+ })
313
+ })
314
+
315
+ describe('MFloorPlan rotatable', () => {
316
+ it('has no rotate handle when rotatable is off', () => {
317
+ const on = mount(MFloorPlan, { props: { editable: true, tables: base(), selection: [1] } })
318
+ const off = mount(MFloorPlan, { props: { editable: true, tables: base(), selection: [1], rotatable: false } })
319
+ expect(on.findAll('[data-rotate]')).toHaveLength(1)
320
+ expect(off.findAll('[data-rotate]')).toHaveLength(0)
321
+ })
322
+ })
323
+
324
+ describe('MFloorPlanToolbar without table presets', () => {
325
+ it('hides Add a table when tables is empty', () => {
326
+ const w = mount(MFloorPlanToolbar, { props: { plan: { context: { kinds: { value: {} }, picked: { value: null }, selection: { value: [] }, tool: { value: 'select' }, drawingWall: { value: false }, canUndo: { value: false }, canRedo: { value: false } } } as any, tables: [] } })
327
+ expect(w.find('[aria-label="Add a table"]').exists()).toBe(false)
328
+ })
329
+ })
@@ -115,6 +115,10 @@ const props = withDefaults(defineProps<{
115
115
  chairs?: boolean
116
116
  /** Decor kinds of yours, or the built-in ones restyled (merged over them by name) */
117
117
  decorKinds?: Record<string, FloorDecorKind>
118
+ /** The handle that turns the picked table or decor (off when your app doesn't keep angles) */
119
+ rotatable?: boolean
120
+ /** Dragging (or nudging) a merged table moves its whole merge with it */
121
+ dragMerged?: boolean
118
122
  /** Outside editing, what a click on a table selects: nothing, one, or several (toggling; to merge them) */
119
123
  selectable?: 'none' | 'single' | 'multiple'
120
124
  /** Whether these tables may be merged: `true`, or `false` / a reason to refuse (shown by `merge-refused`) */
@@ -135,6 +139,8 @@ const props = withDefaults(defineProps<{
135
139
  showGrid: true,
136
140
  chairs: true,
137
141
  selectable: 'none',
142
+ dragMerged: false,
143
+ rotatable: true,
138
144
  })
139
145
  const tables = defineModel<FloorTable[]>('tables', { default: () => [] })
140
146
  const merges = defineModel<FloorMerge[]>('merges', { default: () => [] })
@@ -323,7 +329,7 @@ function onDown(e: PointerEvent, t: FloorTable) {
323
329
  }, LONG_PRESS)
324
330
  } else if (!selection.value.includes(t.id)) selection.value = e.shiftKey || e.ctrlKey || e.metaKey ? [...selection.value, t.id] : [t.id]
325
331
  // A touch picks the table once it moves (or on release), so a long press can add to what's picked
326
- const ids = selection.value.includes(t.id) ? selection.value : [t.id]
332
+ const ids = withMerged(selection.value.includes(t.id) ? selection.value : [t.id])
327
333
  drag = { id: e.pointerId, sx: e.clientX, sy: e.clientY, start: new Map(tables.value.filter((x) => ids.includes(x.id)).map((x) => [x.id, { x: x.x, y: x.y }])), moved: false, pick: touch && !selection.value.includes(t.id) ? t.id : undefined }
328
334
  window.addEventListener('pointermove', onMove)
329
335
  window.addEventListener('pointerup', onUp)
@@ -375,6 +381,13 @@ function onClick(e: MouseEvent, t: FloorTable) {
375
381
  selection.value = selection.value.includes(t.id) ? selection.value.filter((x) => x !== t.id) : [...selection.value, t.id]
376
382
  emit('table-click', t, e)
377
383
  }
384
+ /** With `dragMerged`, the tables merged with these come along */
385
+ function withMerged(ids: (string | number)[]) {
386
+ if (!props.dragMerged) return ids
387
+ const all = new Set(ids)
388
+ for (const id of ids) for (const m of merges.value) if (m.tables.includes(id)) m.tables.forEach((x) => all.add(x))
389
+ return [...all]
390
+ }
378
391
  function onKey(e: KeyboardEvent, t: FloorTable) {
379
392
  if (e.key === 'Enter' || e.key === ' ') {
380
393
  e.preventDefault()
@@ -385,7 +398,7 @@ function onKey(e: KeyboardEvent, t: FloorTable) {
385
398
  if (!dir || !props.editable) return
386
399
  e.preventDefault()
387
400
  const step = (props.grid || 1) * (e.shiftKey ? 5 : 1)
388
- const ids = selection.value.includes(t.id) ? selection.value : [t.id]
401
+ const ids = withMerged(selection.value.includes(t.id) ? selection.value : [t.id])
389
402
  commitMoves(new Map(tables.value.filter((x) => ids.includes(x.id)).map((x) => [x.id, clamp(x, x.x + dir[0]! * step, x.y + dir[1]! * step)])))
390
403
  }
391
404
  onBeforeUnmount(() => {
@@ -928,7 +941,7 @@ const gridStyle = computed(() => {
928
941
  @pointerdown="onDecorDown($event, d, true)"
929
942
  />
930
943
  <span
931
- v-if="editable && isPicked('decor', d.id)"
944
+ v-if="editable && rotatable && isPicked('decor', d.id)"
932
945
  class="m3-floor-handle absolute -top-6 left-1/2 size-3.5 -translate-x-1/2 cursor-grab rounded-full border-2 border-primary bg-surface"
933
946
  :aria-label="locale.floorRotate"
934
947
  data-rotate
@@ -975,7 +988,7 @@ const gridStyle = computed(() => {
975
988
  >
976
989
  <!-- Rotation handle of the one table picked while editing -->
977
990
  <span
978
- v-if="editable && selection.length === 1 && selection[0] === p.t.id && tool === 'select'"
991
+ v-if="editable && rotatable && selection.length === 1 && selection[0] === p.t.id && tool === 'select'"
979
992
  class="m3-floor-handle absolute z-10 size-3.5 -translate-x-1/2 -translate-y-1/2 cursor-grab rounded-full border-2 border-primary bg-surface"
980
993
  :style="{ left: '0px', top: `${-(p.size.h / 2 + CHAIR + 18) * scale}px` }"
981
994
  :aria-label="locale.floorRotate"
@@ -26,7 +26,7 @@ import MTooltip from './MTooltip.vue'
26
26
  const props = withDefaults(defineProps<{
27
27
  /** The plan: its template ref (or its `context`). Not needed inside the plan's slots */
28
28
  plan?: { context: FloorPlanContext } | FloorPlanContext | null
29
- /** Tables offered by Add a table (name, shape, seats, size…) */
29
+ /** Tables offered by Add a table (name, shape, seats, size…); `[]` hides it, when your app creates tables elsewhere */
30
30
  tables?: FloorTablePreset[]
31
31
  /** Decor kinds offered (default: every kind the plan knows, yours included) */
32
32
  decor?: string[]
@@ -90,7 +90,7 @@ function add(p: FloorTablePreset) {
90
90
  <MTooltip :text="locale.floorFinishWall" placement="top"><MIconButton icon="check" variant="filled" :label="locale.floorFinishWall" @click="ctx.finishWall()" /></MTooltip>
91
91
  <MTooltip :text="locale.floorCancel" placement="top"><MIconButton icon="close" :label="locale.floorCancel" @click="ctx.cancelWall()" /></MTooltip>
92
92
  </template>
93
- <MMenu>
93
+ <MMenu v-if="tables.length">
94
94
  <template #trigger>
95
95
  <MTooltip :text="locale.floorAddTable" placement="top"><MIconButton icon="table_restaurant" :label="locale.floorAddTable" /></MTooltip>
96
96
  </template>