architwin 1.0.95 → 1.0.97

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.
@@ -19,8 +19,15 @@ import { renderObjectCard } from "./components/toolbar/card";
19
19
  import { toggleModelControl, getCoordinateValues } from "./components/toolbar/modelControlsPane";
20
20
  import { attachTagMedia } from "../tag";
21
21
  import i18n from './components/toolbar/i18n';
22
+ import { isValidUrl } from "../utils";
22
23
  let activeToolbarItem, activeActionItem, activePane, activeActionPane;
23
- let notyf = new Notyf({ position: { x: 'left', y: 'bottom' }, duration: 4500 });
24
+ let notyf = new Notyf({ position: { x: 'left', y: 'bottom' }, duration: 4500, types: [
25
+ {
26
+ type: 'info',
27
+ background: 'blue',
28
+ icon: '<span class="mdi mdi-information-outline"></span>'
29
+ }
30
+ ] });
24
31
  let currentTag = undefined;
25
32
  let modelsView = 'card';
26
33
  function batchAddEventListenerByClassName(className, callback) {
@@ -269,7 +276,19 @@ function handlePlaceTag() {
269
276
  if (payload.tagEmbed && !tag.attachments) {
270
277
  tag.attachments = [];
271
278
  }
272
- tag.attachments.push(payload.tagEmbed);
279
+ if (payload.tagEmbed) {
280
+ notyf.open({
281
+ type: 'info',
282
+ message: 'Verifying embedded link URL format'
283
+ });
284
+ if (isValidUrl(payload.tagEmbed)) {
285
+ tag.attachments.push(payload.tagEmbed);
286
+ }
287
+ else {
288
+ notyf.error("Invalid URL format");
289
+ return;
290
+ }
291
+ }
273
292
  if (targetCategory) {
274
293
  console.log("targetCategory is", targetCategory);
275
294
  tag.color = targetCategory.json_data.color.rgb;
@@ -294,7 +313,9 @@ function handlePlaceTag() {
294
313
  const row = renderTagRow(iTag);
295
314
  tagContainer.appendChild(row);
296
315
  addClickEventToTagRow(iTag);
297
- yield attachTagMedia({ sdk: _atwin, tag: iTag, attachments: iTag.attachments });
316
+ if (iTag.attachments && iTag.attachments.length > 0) {
317
+ yield attachTagMedia({ sdk: _atwin, tag: iTag, attachments: iTag.attachments });
318
+ }
298
319
  // toggleDisplayPane('at-cancel-tag-form-btn')
299
320
  notyf.success(`${i18n.t('SuccessAddTagToSpace')}`);
300
321
  const tags = getMpTags();
@@ -344,6 +365,18 @@ function handlePlaceTag() {
344
365
  if (payload && payload.tagName && payload.tagCategoryId && payload.tagSubcategoryId) {
345
366
  tag.label = payload.tagName;
346
367
  tag.description = payload.tagDescription;
368
+ if (payload.tagEmbed && !tag.attachments) {
369
+ tag.attachments = [];
370
+ }
371
+ if (payload.tagEmbed) {
372
+ if (isValidUrl(payload.tagEmbed)) {
373
+ tag.attachments.push(payload.tagEmbed);
374
+ }
375
+ else {
376
+ notyf.error("Invalid URL format");
377
+ return;
378
+ }
379
+ }
347
380
  // const iTag = await renderTag({tag:tag},true)
348
381
  const iTag = selectedTag;
349
382
  console.log('iTag', iTag);
@@ -355,7 +388,9 @@ function handlePlaceTag() {
355
388
  const row = renderTagRow(iTag);
356
389
  tagContainer.appendChild(row);
357
390
  addClickEventToTagRow(iTag);
358
- yield attachTagMedia({ sdk: _atwin, tag: iTag, attachments: iTag.attachments });
391
+ if (iTag.attachments && iTag.attachments.length > 0) {
392
+ yield attachTagMedia({ sdk: _atwin, tag: iTag, attachments: iTag.attachments });
393
+ }
359
394
  // toggleDisplayPane('at-cancel-tag-form-btn')
360
395
  notyf.success(`${i18n.t('SuccessAddTagToSpace')}`);
361
396
  const tags = getMpTags();
package/lib/tag.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { MpSdk } from "../bundle/sdk";
2
- import { IAtwinFloor, IAtwinLabel, ITag } from "./types";
2
+ import { IAtwinFloor, IAtwinLabel, ITag, EmbedlyData } from "./types";
3
3
  import { AxiosInstance } from "axios";
4
4
  declare function renderTag({ tag, sdk }: {
5
5
  tag: MpSdk.Tag.Descriptor;
@@ -60,4 +60,8 @@ declare function deleteTag(payload: {
60
60
  tag: ITag;
61
61
  api: AxiosInstance;
62
62
  }): Promise<boolean>;
63
- export { renderTag, disposeTag, moveTag, attachTagMedia, detachTagMedia, setTagIcon, editBillboard, editStem, editColor, saveTagDb, deleteTag, getTagColorCodeID, };
63
+ declare function getEmbedlyData(src: string): Promise<{
64
+ success: boolean;
65
+ embedlyData?: EmbedlyData;
66
+ }>;
67
+ export { renderTag, disposeTag, moveTag, attachTagMedia, detachTagMedia, setTagIcon, editBillboard, editStem, editColor, saveTagDb, deleteTag, getTagColorCodeID, getEmbedlyData };
package/lib/tag.js CHANGED
@@ -356,7 +356,30 @@ function deleteTag(payload) {
356
356
  return false;
357
357
  });
358
358
  }
359
- export { renderTag, disposeTag, moveTag, attachTagMedia, detachTagMedia, setTagIcon, editBillboard, editStem, editColor, saveTagDb, deleteTag, getTagColorCodeID, };
359
+ function getEmbedlyData(src) {
360
+ return __awaiter(this, void 0, void 0, function* () {
361
+ console.log('getEmbedlyData()');
362
+ console.log('src', src);
363
+ const res = yield axios.get("https://api.embedly.com/1/oembed", {
364
+ params: {
365
+ url: src,
366
+ //@ts-expect-error
367
+ key: import.meta.env.VITE_EMBEDLY_KEY,
368
+ },
369
+ }).catch(e => {
370
+ console.error(`Bad request from embedly. Error: ${e}`);
371
+ return { success: false };
372
+ });
373
+ // @ts-ignore
374
+ const data = JSON.parse(JSON.stringify(res.data));
375
+ console.log('Data from embedly', data);
376
+ if (!data) {
377
+ return { success: false };
378
+ }
379
+ return { success: true, embedlyData: data };
380
+ });
381
+ }
382
+ export { renderTag, disposeTag, moveTag, attachTagMedia, detachTagMedia, setTagIcon, editBillboard, editStem, editColor, saveTagDb, deleteTag, getTagColorCodeID, getEmbedlyData };
360
383
  // # -------------------------------------------------------------------------
361
384
  // # tag
362
385
  // # -------------------------------------------------------------------------
package/lib/utils.d.ts CHANGED
@@ -27,4 +27,10 @@ export declare function dateTimeFormat(d: any): string;
27
27
  export declare function stringContains(str: string, target: string, isCaseSensitive?: boolean): boolean;
28
28
  export declare function getURLParams(param: string): string;
29
29
  export declare function useCapitalizeFirstLetter(string: string): string;
30
+ /**
31
+ * Basic URL validation
32
+ * @param string
33
+ * @returns
34
+ */
35
+ export declare function isValidUrl(string: string): boolean;
30
36
  export declare function bytesToMegabytes(bytes: number): number;
package/lib/utils.js CHANGED
@@ -123,6 +123,20 @@ export function getURLParams(param) {
123
123
  export function useCapitalizeFirstLetter(string) {
124
124
  return string.charAt(0).toUpperCase() + string.slice(1);
125
125
  }
126
+ /**
127
+ * Basic URL validation
128
+ * @param string
129
+ * @returns
130
+ */
131
+ export function isValidUrl(string) {
132
+ try {
133
+ new URL(string);
134
+ return true;
135
+ }
136
+ catch (e) {
137
+ return false;
138
+ }
139
+ }
126
140
  export function bytesToMegabytes(bytes) {
127
141
  return bytes / (1024 * 1024);
128
142
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "architwin",
3
- "version": "1.0.95",
3
+ "version": "1.0.97",
4
4
  "description": "ArchiTwin Library for Matterport",
5
5
  "main": "./lib/architwin.js",
6
6
  "types": "./lib/architwin.d.ts",