Skip to content

Commit 9a6c815

Browse files
vue-dd release 1.1.1
1 parent 76e230d commit 9a6c815

File tree

5 files changed

+74
-26
lines changed

5 files changed

+74
-26
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Use `:model-value` instead of `v-model`
4141
## Beautiful & Pixel Perfect
4242
- dark and light modes are built in
4343
- fully configurable & fully themeable via CSS
44-
- functions content are highlighted with highlight.js
44+
- functions code is highlighted with highlight.js
4545
- highlight.js is built in to retain 0 dependecy architecture
4646

4747
## Zero dependencies

docs/docs/index.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1+
<script setup>
2+
const a = 'a'
3+
</script>
14
# Hello World!!
5+
6+
{{ a }}

vue-dd/src/NodeComplex.vue

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -249,25 +249,15 @@
249249
</template>
250250

251251
<script>
252-
import { isReactive, isRef } from 'vue';
253252
import NodePrimitive from "./NodePrimitive.vue";
253+
import { isReactive, isRef } from 'vue';
254+
import { isPromise } from './helpers.js';
254255
255256
import hljs from './highlight.js/core.min.js';
256257
import javascript from './highlight.js/javascript.min.js';
257258
258259
hljs.registerLanguage('javascript', javascript);
259260
260-
export function isObject (item) {
261-
return (item && typeof item === 'object' && !Array.isArray(item));
262-
}
263-
264-
function isPromise (p) {
265-
return p !== null &&
266-
typeof p === 'object' &&
267-
typeof p.then === 'function' &&
268-
typeof p.catch === 'function';
269-
}
270-
271261
// this is needed for cache, does not need to be reactive
272262
let allPointerCache = {}
273263

vue-dd/src/VueDd.vue

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,12 @@
7575
</div>
7676
</template>
7777
<script>
78-
import NodeComplex, { isObject } from "./NodeComplex.vue";
78+
import NodeComplex from "./NodeComplex.vue";
7979
import NodePrimitive from "./NodePrimitive.vue";
8080
import { isRef } from "vue";
81+
import { isObject, makeId } from "./helpers.js";
8182
8283
// this is important
83-
let uniqueId = 1
8484
let unwrapCache = {}
8585
8686
export default {
@@ -124,7 +124,7 @@ export default {
124124
},
125125
data () {
126126
return {
127-
rootId: this.makeId(),
127+
rootId: makeId(this.id, this.name, window),
128128
openClass: false,
129129
css: this.class,
130130
useOpenSpecific: this.openSpecific,
@@ -137,7 +137,6 @@ export default {
137137
},
138138
139139
created () {
140-
141140
if (this.save || this.saveFocus) {
142141
// this is very important for save functionality
143142
this.initMemory();
@@ -261,14 +260,6 @@ export default {
261260
return [...this.openSpecific, ...(this.useFocus === null ? [] : [String(this.useFocus)])]
262261
},
263262
264-
makeId () {
265-
if (this.id !== '') {
266-
return this.id
267-
} else {
268-
return `dd_${uniqueId++}`
269-
}
270-
},
271-
272263
focusEmit (setup) {
273264
274265
let { pointer, focusElement } = setup
@@ -377,7 +368,7 @@ export default {
377368
},
378369
379370
store () {
380-
const key = 'dd.' + this.rootId
371+
const key = 'vue-dd.' + this.rootId
381372
return {
382373
get: () => {
383374
try {

vue-dd/src/helpers.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/**
2+
* Returns a hash code from a string
3+
* @param {String} str The string to hash.
4+
* @return {Number} A 32bit integer
5+
* @see http://werxltd.com/wp/2010/05/13/javascript-implementation-of-javas-string-hashcode-method/
6+
*/
7+
export function hashCode (str) {
8+
let hash = 0;
9+
for (let i = 0, len = str.length; i < len; i++) {
10+
let chr = str.charCodeAt(i);
11+
hash = (hash << 5) - hash + chr;
12+
hash |= 0; // Convert to 32bit integer
13+
}
14+
return hash;
15+
}
16+
17+
export function isObject (item) {
18+
return (item && typeof item === 'object' && !Array.isArray(item));
19+
}
20+
21+
export function isPromise (p) {
22+
return p !== null &&
23+
typeof p === 'object' &&
24+
typeof p.then === 'function' &&
25+
typeof p.catch === 'function';
26+
}
27+
28+
let uniqueId = 1
29+
30+
export function makeId (id, name, window) {
31+
if (id !== '') {
32+
return id
33+
} else {
34+
// auto-generate id
35+
const locationHash = getLocationHash(window)
36+
37+
return `${name}_${uniqueId++}_${locationHash}`
38+
}
39+
}
40+
41+
function getLocationHash (window) {
42+
43+
// determine router type without importing vue-router package
44+
// by analyzing the urls
45+
// hash router will have a forward slash after the # sign #/about
46+
const isHashRouter = window.location.hash
47+
&& typeof window.location.hash[1] !== 'undefined'
48+
&& window.location.hash[1] === '/'
49+
50+
let smartLocation = ''
51+
if (isHashRouter) {
52+
// use full route path
53+
smartLocation = window.location.href.toString()
54+
} else {
55+
// if hash is not a location hash
56+
const url = new URL(window.location.href)
57+
url.hash = "" // strip away hash
58+
smartLocation = url.toString()
59+
}
60+
61+
return hashCode(smartLocation).toString(16).replace('-', '_')
62+
}

0 commit comments

Comments
 (0)