@nordcraft/runtime 1.0.76 → 1.0.77

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
@@ -4,8 +4,8 @@
4
4
  "type": "module",
5
5
  "homepage": "https://github.com/nordcraftengine/nordcraft",
6
6
  "dependencies": {
7
- "@nordcraft/core": "1.0.76",
8
- "@nordcraft/std-lib": "1.0.76",
7
+ "@nordcraft/core": "1.0.77",
8
+ "@nordcraft/std-lib": "1.0.77",
9
9
  "fast-deep-equal": "3.1.3",
10
10
  "path-to-regexp": "6.3.0"
11
11
  },
@@ -21,5 +21,5 @@
21
21
  "files": ["dist", "src"],
22
22
  "main": "dist/page.main.js",
23
23
  "types": "dist/page.main.d.ts",
24
- "version": "1.0.76"
24
+ "version": "1.0.77"
25
25
  }
@@ -225,7 +225,7 @@ export function createElement({
225
225
  })
226
226
 
227
227
  eventHandlers.forEach(([eventName, handler]) => {
228
- elem.addEventListener(eventName, handler)
228
+ elem.addEventListener(eventName, handler, { signal: ctx.abortSignal })
229
229
  })
230
230
 
231
231
  // for script, style & SVG<text> tags we only render text child.
@@ -102,7 +102,10 @@ export type NordcraftPreviewEvent =
102
102
  key: string
103
103
  value: Theme
104
104
  }
105
- resources?: ReadonlyArray<{
105
+ }
106
+ | {
107
+ type: 'preview_resources'
108
+ resources: ReadonlyArray<{
106
109
  type: 'link'
107
110
  href: string
108
111
  }>
@@ -913,38 +913,9 @@ export const createRoot = (
913
913
  })
914
914
  break
915
915
  case 'preview_style':
916
- const { styles: previewStyleStyles, theme, resources } = message.data
916
+ const { styles: previewStyleStyles, theme } = message.data
917
917
  cancelAnimationFrame(previewStyleAnimationFrame)
918
918
  previewStyleAnimationFrame = requestAnimationFrame(() => {
919
- // Allow for temporarily adding preview resources (e.g. fonts).
920
- const resourceElements = Array.from(
921
- document.head.querySelectorAll('[data-id="preview-resource"]'),
922
- )
923
- // Remove any resources that are no longer needed
924
- resourceElements.forEach((el) => {
925
- if (
926
- !resources ||
927
- resources.length === 0 ||
928
- !resources.some((res) => res.href === el.getAttribute('href'))
929
- ) {
930
- el.remove()
931
- }
932
- })
933
- resources
934
- ?.filter(
935
- (resource) =>
936
- !resourceElements.some(
937
- (el) => el.getAttribute('href') === resource.href,
938
- ),
939
- )
940
- .forEach((resource) => {
941
- const resourceElement = document.createElement('link')
942
- resourceElement.setAttribute('data-id', 'preview-resource')
943
- resourceElement.rel = 'stylesheet'
944
- resourceElement.href = resource.href
945
- document.head.appendChild(resourceElement)
946
- })
947
-
948
919
  // Update or create a new style tag and set the given styles with important priority
949
920
  let styleElement = document.head.querySelector(
950
921
  '[data-id="selected-node-styles"]',
@@ -1047,6 +1018,37 @@ export const createRoot = (
1047
1018
  }
1048
1019
  })
1049
1020
  break
1021
+ case 'preview_resources': {
1022
+ const { resources } = message.data
1023
+ // Allow for temporarily adding preview resources (e.g. fonts).
1024
+ const resourceElements = Array.from(
1025
+ document.head.querySelectorAll('[data-id="preview-resource"]'),
1026
+ )
1027
+ // Remove any resources that are no longer needed
1028
+ resourceElements.forEach((el) => {
1029
+ if (
1030
+ resources.length === 0 ||
1031
+ !resources.some((res) => res.href === el.getAttribute('href'))
1032
+ ) {
1033
+ el.remove()
1034
+ }
1035
+ })
1036
+ resources
1037
+ .filter(
1038
+ (resource) =>
1039
+ !resourceElements.some(
1040
+ (el) => el.getAttribute('href') === resource.href,
1041
+ ),
1042
+ )
1043
+ .forEach((resource) => {
1044
+ const resourceElement = document.createElement('link')
1045
+ resourceElement.setAttribute('data-id', 'preview-resource')
1046
+ resourceElement.rel = 'stylesheet'
1047
+ resourceElement.href = resource.href
1048
+ document.head.appendChild(resourceElement)
1049
+ })
1050
+ break
1051
+ }
1050
1052
  case 'preview_theme': {
1051
1053
  const { theme } = message.data
1052
1054
  if (theme) {